-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NextRoll ID System: add new ID module (#6396)
* Add Nextroll ID Module * Add nextroll to eids * Make configuration value names consistent with Adapter Module * Use parnerId instead of sellerId * Add nextroll to userId and eids md files * Remove storage configuration * Rename nextroll -> nextrollId * Add nextrollId to common ID specs
- Loading branch information
Showing
8 changed files
with
151 additions
and
10 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
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,50 @@ | ||
/** | ||
* This module adds Nextroll ID to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/nextrollIdSystem | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import { deepAccess } from '../src/utils.js'; | ||
import { submodule } from '../src/hook.js'; | ||
import { getStorageManager } from '../src/storageManager.js'; | ||
|
||
const NEXTROLL_ID_LS_KEY = 'dca0.com'; | ||
const KEY_PREFIX = 'AdID:' | ||
|
||
export const storage = getStorageManager(); | ||
|
||
/** @type {Submodule} */ | ||
export const nextrollIdSubmodule = { | ||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: 'nextrollId', | ||
|
||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @return {{nextrollId: string} | undefined} | ||
*/ | ||
decode(value) { | ||
return value; | ||
}, | ||
|
||
/** | ||
* performs action to obtain id and return a value. | ||
* @function | ||
* @param {SubmoduleConfig} [config] | ||
* @returns {{id: {nextrollId: string} | undefined}} | ||
*/ | ||
getId(config) { | ||
const key = KEY_PREFIX + deepAccess(config, 'params.partnerId', 'undefined'); | ||
const dataString = storage.getDataFromLocalStorage(NEXTROLL_ID_LS_KEY) || '{}'; | ||
const data = JSON.parse(dataString); | ||
const idValue = deepAccess(data, `${key}.value`); | ||
|
||
return { id: idValue ? {nextrollId: idValue} : undefined }; | ||
} | ||
}; | ||
|
||
submodule('userId', nextrollIdSubmodule); |
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
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
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,56 @@ | ||
import { nextrollIdSubmodule, storage } from 'modules/nextrollIdSystem.js'; | ||
|
||
const LS_VALUE = `{ | ||
"AdID":{"id":"adid","key":"AdID"}, | ||
"AdID:1002": {"id":"adid","key":"AdID:1002","value":"id_value"}}`; | ||
|
||
describe('NextrollId module', function () { | ||
let sandbox = sinon.sandbox.create(); | ||
let hasLocalStorageStub; | ||
let getLocalStorageStub; | ||
|
||
beforeEach(function() { | ||
hasLocalStorageStub = sandbox.stub(storage, 'hasLocalStorage'); | ||
getLocalStorageStub = sandbox.stub(storage, 'getDataFromLocalStorage'); | ||
}); | ||
|
||
afterEach(function () { | ||
sandbox.restore(); | ||
}) | ||
|
||
const testCases = [ | ||
{ | ||
expect: { | ||
id: {nextrollId: 'id_value'}, | ||
}, | ||
params: {partnerId: '1002'}, | ||
localStorage: LS_VALUE | ||
}, | ||
{ | ||
expect: {id: undefined}, | ||
params: {partnerId: '1003'}, | ||
localStorage: LS_VALUE | ||
}, | ||
{ | ||
expect: {id: undefined}, | ||
params: {partnerId: ''}, | ||
localStorage: LS_VALUE | ||
}, | ||
{ | ||
expect: {id: undefined}, | ||
params: {partnerId: '102'}, | ||
localStorage: undefined | ||
}, | ||
{ | ||
expect: {id: undefined}, | ||
params: undefined, | ||
localStorage: undefined | ||
} | ||
] | ||
testCases.forEach( | ||
(testCase, i) => it(`getId() (TC #${i}) should return the nextroll id if it exists`, function () { | ||
getLocalStorageStub.withArgs('dca0.com').returns(testCase.localStorage); | ||
const id = nextrollIdSubmodule.getId({params: testCase.params}); | ||
expect(id).to.be.deep.equal(testCase.expect); | ||
})) | ||
}); |
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