Conversation
Code Review Results✅ StrengthsExcellent comprehensive test coverage with thorough edge case handling and proper validation logic implementation across all affected modules. 🚨 Critical IssuesNone identified.
|
There was a problem hiding this comment.
Pull request overview
Adds validation/sanitization for testCells so only valid non-empty string entries are retained and sent as request params.
Changes:
- Added
helpers.toValidTestCellsto filter invalidtestCellsentries. - Applied filtering in
ConstructorIOconstructor andsetClientOptions. - Added unit/integration tests ensuring invalid
testCellsare excluded from request params.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/helpers.js | Adds toValidTestCells filtering helper. |
| src/constructorio.js | Uses toValidTestCells when setting options.testCells. |
| spec/src/utils/helpers.js | Adds unit tests for toValidTestCells. |
| spec/src/modules/tracker.js | Verifies only valid testCells are serialized into tracking requests. |
| spec/src/modules/search.js | Verifies only valid testCells are serialized into search requests. |
| spec/src/modules/browse.js | Verifies only valid testCells are serialized into browse requests. |
| spec/src/modules/autocomplete.js | Verifies only valid testCells are serialized into autocomplete requests. |
| spec/src/constructorio.js | Adds constructor/setClientOptions tests and updates assertions to deep equality. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| userId, | ||
| segments, | ||
| testCells, | ||
| testCells: helpers.toValidTestCells(testCells), |
There was a problem hiding this comment.
This changes the default options.testCells value from undefined (when testCells isn't provided) to {}. That can be a breaking behavior change for consumers who check presence vs emptiness. Consider only adding testCells to the options object when the caller actually provided it (e.g., conditionally set it, or have toValidTestCells return undefined when input is undefined).
| if (testCells) { | ||
| this.options.testCells = testCells; | ||
| this.options.testCells = helpers.toValidTestCells(testCells); | ||
| } |
There was a problem hiding this comment.
Using if (testCells) prevents callers from explicitly clearing testCells via null/undefined in setClientOptions (the assignment block won't run). If clearing is intended/expected, switch the conditional to check whether testCells was provided (e.g., property existence check) and then set this.options.testCells to the filtered result (which could be {}) accordingly.
|
|
||
| truncateString: (string, maxLength) => string.slice(0, maxLength), | ||
|
|
||
| // Filter testCells to only include entries with non-empty string values |
There was a problem hiding this comment.
The comment says 'non-empty string values' but the implementation allows whitespace-only strings (e.g. ' '). If whitespace-only values should be treated as empty, update the predicate accordingly (and add a test case); otherwise, consider clarifying the comment to indicate that whitespace-only strings are considered valid.
| const filtered = {}; | ||
|
|
||
| Object.keys(testCells).forEach((key) => { | ||
| if (typeof testCells[key] === 'string' && testCells[key] !== '') { |
There was a problem hiding this comment.
The comment says 'non-empty string values' but the implementation allows whitespace-only strings (e.g. ' '). If whitespace-only values should be treated as empty, update the predicate accordingly (and add a test case); otherwise, consider clarifying the comment to indicate that whitespace-only strings are considered valid.
| if (typeof testCells[key] === 'string' && testCells[key] !== '') { | |
| if (typeof testCells[key] === 'string' && testCells[key].trim() !== '') { |
No description provided.