Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
esezen committed Jul 26, 2024
1 parent 16452ec commit 7320601
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 11 deletions.
16 changes: 16 additions & 0 deletions spec/src/modules/catalog/catalog-facet-configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ describe('ConstructorIO - Catalog', () => {
catalog.addFacetConfiguration(mockFacetConfiguration).then(() => {
// Push mock facet configuration into saved list to be cleaned up afterwards
facetConfigurations.push(mockFacetConfiguration);

const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -182,6 +188,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('facets').to.be.an('array').length.gte(1);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -265,6 +272,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('name').to.be.a('string').to.equal(name);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -341,6 +349,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res[1]).to.have.property('position').to.be.a('number').to.equal(5);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -481,6 +490,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('position').to.be.a('number').to.equal(5);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -612,6 +622,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('position').to.be.a('number').to.equal(5);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -715,6 +726,11 @@ describe('ConstructorIO - Catalog', () => {

catalog.addFacetConfiguration(mockFacetConfiguration).then(() => {
catalog.removeFacetConfiguration(mockFacetConfiguration).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down
27 changes: 25 additions & 2 deletions spec/src/modules/catalog/catalog-facet-option-configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ describe('ConstructorIO - Catalog', () => {
fetch: fetchSpy,
});

catalog.addFacetOptionConfiguration(mockFacetOptionConfiguration).then(() => done());
catalog.addFacetOptionConfiguration(mockFacetOptionConfiguration).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});

it('Backwards Compatibility `display_name` - Should resolve when adding a facet option configuration', (done) => {
Expand Down Expand Up @@ -187,7 +194,14 @@ describe('ConstructorIO - Catalog', () => {
catalog.addOrModifyFacetOptionConfigurations({
facetGroupName,
facetOptionConfigurations: mockFacetOptionConfigurations,
}).then(() => done());
}).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});

it('Should return a response when modifying facet configurations', (done) => {
Expand Down Expand Up @@ -317,6 +331,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('facet_options').to.be.an('array').length.gte(1);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -411,6 +426,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('value').to.be.a('string').to.equal(value);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -484,6 +500,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('position').to.be.a('number').to.equal(5);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -614,6 +631,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('position').to.be.a('number').to.equal(5);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -723,6 +741,11 @@ describe('ConstructorIO - Catalog', () => {

catalog.addFacetOptionConfiguration(mockFacetOptionConfiguration).then(() => {
catalog.removeFacetOptionConfiguration(mockFacetOptionConfiguration).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down
23 changes: 21 additions & 2 deletions spec/src/modules/catalog/catalog-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ describe('ConstructorIO - Catalog', () => {
fetch: fetchSpy,
});

catalog.addItemGroup(group).then(done);
catalog.addItemGroup(group).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});

it('Should return error when adding an item group with an invalid API key', () => {
Expand Down Expand Up @@ -142,7 +149,14 @@ describe('ConstructorIO - Catalog', () => {
fetch: fetchSpy,
});

catalog.addItemGroups({ itemGroups: groups }).then(done);
catalog.addItemGroups({ itemGroups: groups }).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});

it('Should resolve when adding item groups with children', (done) => {
Expand Down Expand Up @@ -243,6 +257,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res.item_groups[0]).to.have.property('id').to.equal(mockItemGroup.id);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -327,6 +342,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('item_groups').to.be.an('array').to.have.length.gt(1);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -403,6 +419,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res.item_groups).to.have.property('deleted').to.be.an('number');
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -559,6 +576,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('name').to.be.a('string').to.equal(mockItemGroup.name);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -635,6 +653,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('message').to.be.a('string');
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down
4 changes: 4 additions & 0 deletions spec/src/modules/catalog/catalog-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('ConstructorIO - Catalog', () => {

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});

Expand Down Expand Up @@ -202,6 +203,7 @@ describe('ConstructorIO - Catalog', () => {

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -350,6 +352,7 @@ describe('ConstructorIO - Catalog', () => {

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -481,6 +484,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('items').to.be.an('array');
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down
38 changes: 34 additions & 4 deletions spec/src/modules/catalog/catalog-one-way-synonyms.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ describe('ConstructorIO - Catalog', () => {
catalog.addOneWaySynonym({
phrase: createMockOneWaySynonymPhrase(),
child_phrases: [{ phrase: createMockOneWaySynonymPhrase() }],
}).then(done);
}).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});

it('Should return error when adding a one way synonym that already exists', () => {
Expand Down Expand Up @@ -168,7 +175,14 @@ describe('ConstructorIO - Catalog', () => {
catalog.modifyOneWaySynonym({
phrase: mockOneWaySynonymPhrase,
childPhrases: [{ phrase: createMockOneWaySynonymPhrase() }],
}).then(done);
}).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});

it('Checking Backwards Compatibility `child_phrases` - Should resolve when modifying a one way synonym', (done) => {
Expand Down Expand Up @@ -279,6 +293,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res.one_way_synonym_relations[0]).to.have.property('parent_phrase').to.be.a('string').to.equal(mockOneWaySynonymPhrase);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -375,6 +390,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('one_way_synonym_relations').to.be.an('array').length.gte(1);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -476,7 +492,14 @@ describe('ConstructorIO - Catalog', () => {
fetch: fetchSpy,
});

catalog.removeOneWaySynonym({ phrase: mockOneWaySynonymPhrase }).then(done);
catalog.removeOneWaySynonym({ phrase: mockOneWaySynonymPhrase }).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});

it('Should return error when removing one way synonym with an invalid API key', () => {
Expand Down Expand Up @@ -549,7 +572,14 @@ describe('ConstructorIO - Catalog', () => {
fetch: fetchSpy,
});

catalog.removeOneWaySynonyms().then(done);
catalog.removeOneWaySynonyms().then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});

it('Should return error when removing one way synonyms with an invalid API key', () => {
Expand Down
6 changes: 6 additions & 0 deletions spec/src/modules/catalog/catalog-redirect-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res.matches[0]).to.have.property('match_type').to.eq(mockRedirectRule.matches[0].match_type);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -157,6 +158,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res.matches[0]).to.have.property('match_type').to.eq(mockRedirectRule.matches[0].match_type);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -267,6 +269,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res.matches[0]).to.have.property('match_type').to.eq(mockRedirectRule.matches[0].match_type);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -370,6 +373,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res.matches[0]).to.have.property('match_type').to.eq(mockRedirectRule.matches[0].match_type);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -453,6 +457,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('redirect_rules').an('array').of.length.gte(1);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -615,6 +620,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res.matches[0]).to.have.property('match_type').to.eq(mockRedirectRule.matches[0].match_type);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down
2 changes: 2 additions & 0 deletions spec/src/modules/catalog/catalog-searchabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('ConstructorIO - Catalog', () => {
expect(res).to.have.property('searchabilities').to.be.an('array').length.gte(1);
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down Expand Up @@ -173,6 +174,7 @@ describe('ConstructorIO - Catalog', () => {
expect(fetchSpy).to.have.been.called;
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('section');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
done();
});
});
Expand Down
Loading

0 comments on commit 7320601

Please sign in to comment.