Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 3 additions & 242 deletions spec/src/modules/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
};
const optionalParameters = {
tr: 'click',
groupId: 'All',
groupId: 'all',
displayName: 'display-name',
itemId: '12345',
};
Expand Down Expand Up @@ -756,7 +756,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
original_query: 'original-query',
section: 'Search Suggestions',
tr: 'click',
group_id: 'All',
group_id: 'all',
display_name: 'display-name',
variation_id: '12345-A',
item_id: '12345',
Expand Down Expand Up @@ -3550,7 +3550,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
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.');
expect(responseParams).to.have.property('message').to.equal('Invalid parameters');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message has been moved to response.errors[x].message but we don't emit that in our RequestQueue at the moment on errors. I didn't want to change the implementation just because of this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if this is how errors are going to be surfaced moving forward? If so, it shouldn't be too hard to add it as a part of the emitted event (and it should be backwards compatible since it's an addition). If it's something that's expected to continue changing, I wonder if we should just spread (...) the JSON body into the emitted event. For example:

instance.eventemitter.emit('error', {
    url: nextInQueue.url,
    method: nextInQueue.method,
    ...(json && {...json}) // bringing back of one of Stanley's signature existence-check and spread
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that. Should I create a story for it?


done();
});
Expand Down Expand Up @@ -4035,106 +4035,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
expect(tracker.trackPurchase()).to.be.an('error');
});

it('Should respond with a success if beacon=true and a non-existent item_id is provided', (done) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
...requestQueueOptions,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('beacon').to.equal(true);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.equal('ok');

done();
});

expect(tracker.trackPurchase({
...requiredParameters,
items: [
{
itemId: 'bad-item-id-10',
variationId: '456',
},
{
itemId: 'bad-item-id-11',
},
],
})).to.equal(true);
});

it('Should respond with an error if beacon=true is not in the request and a non-existent item_id is provided', (done) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
...requestQueueOptions,
beaconMode: false,
});

tracker.on('error', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.not.have.property('beacon');

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="bad-item-id-10".');

done();
});

expect(tracker.trackPurchase({
...requiredParameters,
items: [
{
itemId: 'bad-item-id-10',
},
],
})).to.equal(true);
});

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) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
...requestQueueOptions,
beaconMode: false,
});

tracker.on('error', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.not.have.property('beacon');

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.contain('There is no variation item with variation_id="456".');

done();
});

expect(tracker.trackPurchase({
...requiredParameters,
items: [
{
itemId: 'bad-item-id-10',
variationId: '456',
},
],
})).to.equal(true);
});

it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
Expand Down Expand Up @@ -5048,75 +4948,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
expect(tracker.trackRecommendationClick(Object.assign(requiredParameters, optionalParameters))).to.equal(true);
});

it('Should respond with a success if beacon=true and a non-existent item_id is provided', (done) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
...requestQueueOptions,
});
const parameters = {
...requiredParameters,
...optionalParameters,
itemId: 'non-existent-item-id',
};

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage);
expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage);
expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount);
expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage);
expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId);
expect(requestParams).to.have.property('section').to.equal(parameters.section);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.equal('ok');

done();
});

expect(tracker.trackRecommendationClick(parameters)).to.equal(true);
});

it('Should respond with an error if beacon=true is not in the request and a non-existent item_id is provided', (done) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
...requestQueueOptions,
beaconMode: false,
});
const parameters = {
...requiredParameters,
...optionalParameters,
itemId: 'non-existent-item-id',
};

tracker.on('error', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage);
expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage);
expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount);
expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage);
expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId);
expect(requestParams).to.have.property('section').to.equal(parameters.section);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="non-existent-item-id"');

done();
});

expect(tracker.trackRecommendationClick(parameters)).to.equal(true);
});

it('Should throw an error when invalid parameters are provided', () => {
const { tracker } = new ConstructorIO({ apiKey: testApiKey });

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

it('Should respond with a valid response when required parameters and non-existent item id are provided', (done) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
...requestQueueOptions,
beaconMode: false,
});
const parameters = {
...requiredParameters,
...optionalParameters,
itemId: 'non-existent-item-id',
};

tracker.on('error', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('section').to.equal(parameters.section);
expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount);
expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage);
expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId);
expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage);
expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage);
expect(requestParams).to.have.property('selected_filters').to.deep.equal(parameters.selectedFilters);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="non-existent-item-id"');

done();
});

expect(tracker.trackBrowseResultClick(parameters)).to.equal(true);
});

it('Should throw an error when invalid parameters are provided', () => {
const { tracker } = new ConstructorIO({ apiKey: testApiKey });

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

it('Should respond with a valid response when required parameters and non-existent item id are provided', (done) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
...requestQueueOptions,
beaconMode: false,
});
const parameters = {
...requiredParameters,
...optionalParameters,
itemId: 'non-existent-item-id',
};

tracker.on('error', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('section').to.equal(parameters.section);
expect(requestParams).to.have.property('item_id').to.equal(parameters.itemId);
expect(requestParams).to.have.property('item_name').to.equal(parameters.itemName);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams)
.to.have.property('message')
.to.contain('There is no item with item_id="non-existent-item-id"');

done();
});

expect(tracker.trackGenericResultClick(parameters)).to.equal(true);
});

it('Should throw an error when invalid parameters are provided', () => {
const { tracker } = new ConstructorIO({ apiKey: testApiKey });

Expand Down