Skip to content

Commit

Permalink
LiveIntent Id System: fix for parsing response twice (#6418)
Browse files Browse the repository at this point in the history
* Don't parse response twice in LiveIntent Id submodule

* Update the liveintent module test to have the 204 response
  • Loading branch information
Yevhenii Melnyk committed Mar 16, 2021
1 parent 670ab08 commit 20bea36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
10 changes: 1 addition & 9 deletions modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,7 @@ export const liveIntentIdSubmodule = {
const result = function(callback) {
liveConnect.resolve(
response => {
let responseObj = {};
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
callback(response);
},
error => {
utils.logError(`${MODULE_NAME}: ID fetch encountered an error: `, error);
Expand Down
17 changes: 10 additions & 7 deletions test/spec/modules/liveIntentIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('LiveIntentId', function() {
resetLiveIntentIdSubmodule();
});

it('should initialize LiveConnect with a privacy string when getId, and include it in the resolution request', function() {
it('should initialize LiveConnect with a privacy string when getId, and include it in the resolution request', function () {
uspConsentDataStub.returns('1YNY');
gdprConsentDataStub.returns({
gdprApplies: true,
Expand All @@ -47,12 +47,16 @@ describe('LiveIntentId', function() {
submoduleCallback(callBackSpy);
let request = server.requests[1];
expect(request.url).to.match(/.*us_privacy=1YNY.*&gdpr=1&gdpr_consent=consentDataString.*/);
const response = {
unifiedId: 'a_unified_id',
segments: [123, 234]
}
request.respond(
200,
responseHeader,
JSON.stringify({})
JSON.stringify(response)
);
expect(callBackSpy.calledOnce).to.be.true;
expect(callBackSpy.calledOnceWith(response)).to.be.true;
});

it('should fire an event when getId', function() {
Expand Down Expand Up @@ -131,11 +135,10 @@ describe('LiveIntentId', function() {
let request = server.requests[1];
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/prebid/89899');
request.respond(
200,
responseHeader,
JSON.stringify({})
204,
responseHeader
);
expect(callBackSpy.calledOnce).to.be.true;
expect(callBackSpy.calledOnceWith({})).to.be.true;
});

it('should call the default url of the LiveIntent Identity Exchange endpoint, with a partner', function() {
Expand Down

0 comments on commit 20bea36

Please sign in to comment.