forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LiveConnect, lighter-weight module (prebid#6016)
* NT. Trying out how webpack plays with env vars * NT. Test run before merge * NT. POC kinda ok for me now * NT. Updated the lc version to released one. * NT. Reverting test data. Ready for PR * NT. Fixing linting. * NT. Fixing the email hash scenario.
- Loading branch information
1 parent
e8ce9e2
commit d9b45cc
Showing
6 changed files
with
221 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
import * as utils from 'src/utils.js'; | ||
import { gdprDataHandler, uspDataHandler } from '../../../src/adapterManager.js'; | ||
import { server } from 'test/mocks/xhr.js'; | ||
import { liveIntentIdSubmodule, reset as resetLiveIntentIdSubmodule, storage } from 'modules/liveIntentIdSystem.js'; | ||
|
||
const PUBLISHER_ID = '89899'; | ||
const defaultConfigParams = { params: {publisherId: PUBLISHER_ID} }; | ||
const responseHeader = {'Content-Type': 'application/json'}; | ||
|
||
describe('LiveIntentMinimalId', function() { | ||
let logErrorStub; | ||
let uspConsentDataStub; | ||
let gdprConsentDataStub; | ||
let getCookieStub; | ||
let getDataFromLocalStorageStub; | ||
let imgStub; | ||
|
||
beforeEach(function() { | ||
liveIntentIdSubmodule.setModuleMode('minimal'); | ||
imgStub = sinon.stub(utils, 'triggerPixel'); | ||
getCookieStub = sinon.stub(storage, 'getCookie'); | ||
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); | ||
logErrorStub = sinon.stub(utils, 'logError'); | ||
uspConsentDataStub = sinon.stub(uspDataHandler, 'getConsentData'); | ||
gdprConsentDataStub = sinon.stub(gdprDataHandler, 'getConsentData'); | ||
}); | ||
|
||
afterEach(function() { | ||
imgStub.restore(); | ||
getCookieStub.restore(); | ||
getDataFromLocalStorageStub.restore(); | ||
logErrorStub.restore(); | ||
uspConsentDataStub.restore(); | ||
gdprConsentDataStub.restore(); | ||
liveIntentIdSubmodule.setModuleMode('minimal'); | ||
resetLiveIntentIdSubmodule(); | ||
}); | ||
it('should not fire an event when getId', function() { | ||
uspConsentDataStub.returns('1YNY'); | ||
gdprConsentDataStub.returns({ | ||
gdprApplies: true, | ||
consentString: 'consentDataString' | ||
}) | ||
liveIntentIdSubmodule.getId(defaultConfigParams); | ||
expect(server.requests[0]).to.eql(undefined) | ||
}); | ||
|
||
it('should not return a decoded identifier when the unifiedId is not present in the value', function() { | ||
const result = liveIntentIdSubmodule.decode({ additionalData: 'data' }); | ||
expect(result).to.be.undefined; | ||
}); | ||
|
||
it('should initialize LiveConnect and send no data', function() { | ||
liveIntentIdSubmodule.getId(defaultConfigParams); | ||
liveIntentIdSubmodule.decode({}, defaultConfigParams); | ||
liveIntentIdSubmodule.getId(defaultConfigParams); | ||
liveIntentIdSubmodule.decode({}, defaultConfigParams); | ||
expect(server.requests.length).to.be.eq(0); | ||
}); | ||
|
||
it('should call the Custom URL of the LiveIntent Identity Exchange endpoint', function() { | ||
getCookieStub.returns(null); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId({ params: {...defaultConfigParams.params, ...{'url': 'https://dummy.liveintent.com/idex'}} }).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/prebid/89899'); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should call the default url of the LiveIntent Identity Exchange endpoint, with a partner', function() { | ||
getCookieStub.returns(null); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId({ params: { | ||
...defaultConfigParams.params, | ||
...{ | ||
'url': 'https://dummy.liveintent.com/idex', | ||
'partner': 'rubicon' | ||
} | ||
} }).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/rubicon/89899'); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should call the LiveIntent Identity Exchange endpoint, with no additional query params', function() { | ||
getCookieStub.returns(null); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899'); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should log an error and continue to callback if ajax request errors', function() { | ||
getCookieStub.returns(null); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899'); | ||
request.respond( | ||
503, | ||
responseHeader, | ||
'Unavailable' | ||
); | ||
expect(logErrorStub.calledOnce).to.be.true; | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should include the LiveConnect identifier when calling the LiveIntent Identity Exchange endpoint', function() { | ||
const oldCookie = 'a-xxxx--123e4567-e89b-12d3-a456-426655440000' | ||
getDataFromLocalStorageStub.withArgs('_li_duid').returns(oldCookie); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq(`https://idx.liadm.com/idex/prebid/89899?duid=${oldCookie}`); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should include the LiveConnect identifier and additional Identifiers to resolve', function() { | ||
const oldCookie = 'a-xxxx--123e4567-e89b-12d3-a456-426655440000' | ||
getDataFromLocalStorageStub.withArgs('_li_duid').returns(oldCookie); | ||
getDataFromLocalStorageStub.withArgs('_thirdPC').returns('third-pc'); | ||
const configParams = { params: { | ||
...defaultConfigParams.params, | ||
...{ | ||
'identifiersToResolve': ['_thirdPC'] | ||
} | ||
}}; | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(configParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq(`https://idx.liadm.com/idex/prebid/89899?duid=${oldCookie}&_thirdPC=third-pc`); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should include an additional identifier value to resolve even if it is an object', function() { | ||
getCookieStub.returns(null); | ||
getDataFromLocalStorageStub.withArgs('_thirdPC').returns({'key': 'value'}); | ||
const configParams = { params: { | ||
...defaultConfigParams.params, | ||
...{ | ||
'identifiersToResolve': ['_thirdPC'] | ||
} | ||
}}; | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(configParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899?_thirdPC=%7B%22key%22%3A%22value%22%7D'); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters