Skip to content

Commit 706d308

Browse files
authored
[CI-4285] Update tests (#371)
* Update tests * Remove beaconMode tests
1 parent f3e8081 commit 706d308

File tree

1 file changed

+3
-242
lines changed

1 file changed

+3
-242
lines changed

spec/src/modules/tracker.js

Lines changed: 3 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
693693
};
694694
const optionalParameters = {
695695
tr: 'click',
696-
groupId: 'All',
696+
groupId: 'all',
697697
displayName: 'display-name',
698698
itemId: '12345',
699699
};
@@ -756,7 +756,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
756756
original_query: 'original-query',
757757
section: 'Search Suggestions',
758758
tr: 'click',
759-
group_id: 'All',
759+
group_id: 'all',
760760
display_name: 'display-name',
761761
variation_id: '12345-A',
762762
item_id: '12345',
@@ -3550,7 +3550,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
35503550

35513551
// Response
35523552
expect(responseParams).to.have.property('method').to.equal('POST');
3553-
expect(responseParams).to.have.property('message').to.equal('conversion type must be one of add_to_wishlist, add_to_cart, like, message, make_offer, read. If you wish to use custom types, please set is_custom_type to true and specify a display_name.');
3553+
expect(responseParams).to.have.property('message').to.equal('Invalid parameters');
35543554

35553555
done();
35563556
});
@@ -4035,106 +4035,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
40354035
expect(tracker.trackPurchase()).to.be.an('error');
40364036
});
40374037

4038-
it('Should respond with a success if beacon=true and a non-existent item_id is provided', (done) => {
4039-
const { tracker } = new ConstructorIO({
4040-
apiKey: testApiKey,
4041-
fetch: fetchSpy,
4042-
...requestQueueOptions,
4043-
});
4044-
4045-
tracker.on('success', (responseParams) => {
4046-
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
4047-
4048-
// Request
4049-
expect(fetchSpy).to.have.been.called;
4050-
expect(requestParams).to.have.property('beacon').to.equal(true);
4051-
4052-
// Response
4053-
expect(responseParams).to.have.property('method').to.equal('POST');
4054-
expect(responseParams).to.have.property('message').to.equal('ok');
4055-
4056-
done();
4057-
});
4058-
4059-
expect(tracker.trackPurchase({
4060-
...requiredParameters,
4061-
items: [
4062-
{
4063-
itemId: 'bad-item-id-10',
4064-
variationId: '456',
4065-
},
4066-
{
4067-
itemId: 'bad-item-id-11',
4068-
},
4069-
],
4070-
})).to.equal(true);
4071-
});
4072-
4073-
it('Should respond with an error if beacon=true is not in the request and a non-existent item_id is provided', (done) => {
4074-
const { tracker } = new ConstructorIO({
4075-
apiKey: testApiKey,
4076-
fetch: fetchSpy,
4077-
...requestQueueOptions,
4078-
beaconMode: false,
4079-
});
4080-
4081-
tracker.on('error', (responseParams) => {
4082-
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
4083-
4084-
// Request
4085-
expect(fetchSpy).to.have.been.called;
4086-
expect(requestParams).to.not.have.property('beacon');
4087-
4088-
// Response
4089-
expect(responseParams).to.have.property('method').to.equal('POST');
4090-
expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="bad-item-id-10".');
4091-
4092-
done();
4093-
});
4094-
4095-
expect(tracker.trackPurchase({
4096-
...requiredParameters,
4097-
items: [
4098-
{
4099-
itemId: 'bad-item-id-10',
4100-
},
4101-
],
4102-
})).to.equal(true);
4103-
});
4104-
4105-
it('Should respond with an error if beacon=true is not in the request and a non-existent item_id/variation_id is provided', (done) => {
4106-
const { tracker } = new ConstructorIO({
4107-
apiKey: testApiKey,
4108-
fetch: fetchSpy,
4109-
...requestQueueOptions,
4110-
beaconMode: false,
4111-
});
4112-
4113-
tracker.on('error', (responseParams) => {
4114-
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
4115-
4116-
// Request
4117-
expect(fetchSpy).to.have.been.called;
4118-
expect(requestParams).to.not.have.property('beacon');
4119-
4120-
// Response
4121-
expect(responseParams).to.have.property('method').to.equal('POST');
4122-
expect(responseParams).to.have.property('message').to.contain('There is no variation item with variation_id="456".');
4123-
4124-
done();
4125-
});
4126-
4127-
expect(tracker.trackPurchase({
4128-
...requiredParameters,
4129-
items: [
4130-
{
4131-
itemId: 'bad-item-id-10',
4132-
variationId: '456',
4133-
},
4134-
],
4135-
})).to.equal(true);
4136-
});
4137-
41384038
it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => {
41394039
const { tracker } = new ConstructorIO({
41404040
apiKey: testApiKey,
@@ -5048,75 +4948,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
50484948
expect(tracker.trackRecommendationClick(Object.assign(requiredParameters, optionalParameters))).to.equal(true);
50494949
});
50504950

5051-
it('Should respond with a success if beacon=true and a non-existent item_id is provided', (done) => {
5052-
const { tracker } = new ConstructorIO({
5053-
apiKey: testApiKey,
5054-
fetch: fetchSpy,
5055-
...requestQueueOptions,
5056-
});
5057-
const parameters = {
5058-
...requiredParameters,
5059-
...optionalParameters,
5060-
itemId: 'non-existent-item-id',
5061-
};
5062-
5063-
tracker.on('success', (responseParams) => {
5064-
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
5065-
5066-
// Request
5067-
expect(fetchSpy).to.have.been.called;
5068-
expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage);
5069-
expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage);
5070-
expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount);
5071-
expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage);
5072-
expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId);
5073-
expect(requestParams).to.have.property('section').to.equal(parameters.section);
5074-
5075-
// Response
5076-
expect(responseParams).to.have.property('method').to.equal('POST');
5077-
expect(responseParams).to.have.property('message').to.equal('ok');
5078-
5079-
done();
5080-
});
5081-
5082-
expect(tracker.trackRecommendationClick(parameters)).to.equal(true);
5083-
});
5084-
5085-
it('Should respond with an error if beacon=true is not in the request and a non-existent item_id is provided', (done) => {
5086-
const { tracker } = new ConstructorIO({
5087-
apiKey: testApiKey,
5088-
fetch: fetchSpy,
5089-
...requestQueueOptions,
5090-
beaconMode: false,
5091-
});
5092-
const parameters = {
5093-
...requiredParameters,
5094-
...optionalParameters,
5095-
itemId: 'non-existent-item-id',
5096-
};
5097-
5098-
tracker.on('error', (responseParams) => {
5099-
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
5100-
5101-
// Request
5102-
expect(fetchSpy).to.have.been.called;
5103-
expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage);
5104-
expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage);
5105-
expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount);
5106-
expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage);
5107-
expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId);
5108-
expect(requestParams).to.have.property('section').to.equal(parameters.section);
5109-
5110-
// Response
5111-
expect(responseParams).to.have.property('method').to.equal('POST');
5112-
expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="non-existent-item-id"');
5113-
5114-
done();
5115-
});
5116-
5117-
expect(tracker.trackRecommendationClick(parameters)).to.equal(true);
5118-
});
5119-
51204951
it('Should throw an error when invalid parameters are provided', () => {
51214952
const { tracker } = new ConstructorIO({ apiKey: testApiKey });
51224953

@@ -6316,42 +6147,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
63166147
expect(tracker.trackBrowseResultClick(parameters)).to.equal(true);
63176148
});
63186149

6319-
it('Should respond with a valid response when required parameters and non-existent item id are provided', (done) => {
6320-
const { tracker } = new ConstructorIO({
6321-
apiKey: testApiKey,
6322-
fetch: fetchSpy,
6323-
...requestQueueOptions,
6324-
beaconMode: false,
6325-
});
6326-
const parameters = {
6327-
...requiredParameters,
6328-
...optionalParameters,
6329-
itemId: 'non-existent-item-id',
6330-
};
6331-
6332-
tracker.on('error', (responseParams) => {
6333-
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
6334-
6335-
// Request
6336-
expect(fetchSpy).to.have.been.called;
6337-
expect(requestParams).to.have.property('section').to.equal(parameters.section);
6338-
expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount);
6339-
expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage);
6340-
expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId);
6341-
expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage);
6342-
expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage);
6343-
expect(requestParams).to.have.property('selected_filters').to.deep.equal(parameters.selectedFilters);
6344-
6345-
// Response
6346-
expect(responseParams).to.have.property('method').to.equal('POST');
6347-
expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="non-existent-item-id"');
6348-
6349-
done();
6350-
});
6351-
6352-
expect(tracker.trackBrowseResultClick(parameters)).to.equal(true);
6353-
});
6354-
63556150
it('Should throw an error when invalid parameters are provided', () => {
63566151
const { tracker } = new ConstructorIO({ apiKey: testApiKey });
63576152

@@ -6769,40 +6564,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
67696564
expect(tracker.trackGenericResultClick(parameters)).to.equal(true);
67706565
});
67716566

6772-
it('Should respond with a valid response when required parameters and non-existent item id are provided', (done) => {
6773-
const { tracker } = new ConstructorIO({
6774-
apiKey: testApiKey,
6775-
fetch: fetchSpy,
6776-
...requestQueueOptions,
6777-
beaconMode: false,
6778-
});
6779-
const parameters = {
6780-
...requiredParameters,
6781-
...optionalParameters,
6782-
itemId: 'non-existent-item-id',
6783-
};
6784-
6785-
tracker.on('error', (responseParams) => {
6786-
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
6787-
6788-
// Request
6789-
expect(fetchSpy).to.have.been.called;
6790-
expect(requestParams).to.have.property('section').to.equal(parameters.section);
6791-
expect(requestParams).to.have.property('item_id').to.equal(parameters.itemId);
6792-
expect(requestParams).to.have.property('item_name').to.equal(parameters.itemName);
6793-
6794-
// Response
6795-
expect(responseParams).to.have.property('method').to.equal('POST');
6796-
expect(responseParams)
6797-
.to.have.property('message')
6798-
.to.contain('There is no item with item_id="non-existent-item-id"');
6799-
6800-
done();
6801-
});
6802-
6803-
expect(tracker.trackGenericResultClick(parameters)).to.equal(true);
6804-
});
6805-
68066567
it('Should throw an error when invalid parameters are provided', () => {
68076568
const { tracker } = new ConstructorIO({ apiKey: testApiKey });
68086569

0 commit comments

Comments
 (0)