Skip to content

Commit

Permalink
Criteo ID Module: Add error callback for pixel sync call
Browse files Browse the repository at this point in the history
  • Loading branch information
v.raybaud committed Apr 3, 2023
1 parent 0a665d7 commit ecec568
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/criteoIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ function callSyncPixel(domain, pixel) {
saveOnAllStorages(pixel.storageKeyName, jsonResponse[pixel.bundlePropertyName], domain);
}
}
},
error: error => {
logError(`criteoIdSystem: unable to sync user id`, error);
}
},
undefined,
Expand Down
38 changes: 38 additions & 0 deletions test/spec/modules/criteoIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,44 @@ describe('CriteoId module', function () {
expect(setLocalStorageStub.calledWith('cto_pixel_test', 'ok')).to.be.true;
});

it('should call sync pixels and use error handler', function () {
const expirationTs = new Date(nowTimestamp + cookiesMaxAge).toString();

const result = criteoIdSubmodule.getId();
result.callback((id) => {
});

const response = {
pixels: [
{
pixelUrl: 'pixelUrlWithBundle',
writeBundleInStorage: true,
bundlePropertyName: 'abc',
storageKeyName: 'cto_pixel_test'
}
]
};

server.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify(response)
);

server.requests[1].respond(
500,
{ 'Content-Type': 'application/json' },
JSON.stringify({
abc: 'ok'
})
);

expect(triggerPixelStub.called).to.be.false;
expect(setCookieStub.calledWith('cto_pixel_test', 'ok', expirationTs, null, '.com')).to.be.false;
expect(setCookieStub.calledWith('cto_pixel_test', 'ok', expirationTs, null, '.testdev.com')).to.be.false;
expect(setLocalStorageStub.calledWith('cto_pixel_test', 'ok')).to.be.false;
});

gdprConsentTestCases.forEach(testCase => it('should call user sync url with the gdprConsent', function () {
let callBackSpy = sinon.spy();
let result = criteoIdSubmodule.getId(undefined, testCase.consentData);
Expand Down

0 comments on commit ecec568

Please sign in to comment.