Skip to content

Commit ef1df18

Browse files
committed
[CDX-384]: improved itemIds validation and test coverage
1 parent bb8d16d commit ef1df18

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ test
77
# OS X specific files
88
.DS_Store
99

10+
# Editor specific files
11+
.idea
12+
1013
# Logs
1114
logs
1215
*.log

spec/src/modules/recommendations.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ describe(`ConstructorIO - Recommendations${bundledDescriptionSuffix}`, () => {
124124
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
125125
expect(requestedUrlParams).to.have.property('item_id').to.equal(itemId);
126126
expect(requestedUrlParams).to.have.property('variation_id').to.equal(variationId);
127+
expect(res.request.variation_id).to.equal(variationId);
127128
done();
128129
});
129130
});
@@ -499,6 +500,15 @@ describe(`ConstructorIO - Recommendations${bundledDescriptionSuffix}`, () => {
499500
})).to.eventually.be.rejected;
500501
});
501502

503+
it('Should be rejected when variationId is provided with an empty itemIds array', () => {
504+
const { recommendations } = new ConstructorIO({ apiKey: testApiKey });
505+
506+
return expect(recommendations.getRecommendations(podId, {
507+
variationId,
508+
itemIds: [],
509+
})).to.eventually.be.rejected;
510+
});
511+
502512
it('Should be rejected when invalid pod id parameter is provided', () => {
503513
const { recommendations } = new ConstructorIO({ apiKey: testApiKey });
504514

src/modules/recommendations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function createRecommendationsUrl(podId, parameters, options) {
5252
}
5353

5454
if (variationId) {
55-
if (!itemIds) {
55+
if (!itemIds || (typeof itemIds === 'string' && !itemIds.trim())) {
5656
throw new Error('itemIds is a required parameter for variationId');
5757
}
5858

0 commit comments

Comments
 (0)