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.
Add tapad id submodule (prebid#6167)
* Add tapad id submodule * clean and add specs
- Loading branch information
1 parent
264f75d
commit 766ccf8
Showing
7 changed files
with
195 additions
and
15 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,61 @@ | ||
import { uspDataHandler } from '../src/adapterManager.js'; | ||
import { submodule } from '../src/hook.js'; | ||
import * as ajax from '../src/ajax.js' | ||
import * as utils from '../src/utils.js'; | ||
|
||
export const graphUrl = 'https://realtime-graph-access-zxvhwknfeq-uc.a.run.app/v1/graph'; | ||
|
||
export const tapadIdSubmodule = { | ||
name: 'tapadId', | ||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @returns {{tapadId: string} | undefined} | ||
*/ | ||
decode(id) { | ||
return { tapadId: id }; | ||
}, | ||
/* | ||
* @function | ||
* @summary initiate Real Time Graph | ||
* @param {SubmoduleParams} [configParams] | ||
* @param {ConsentData} [consentData] | ||
* @returns {IdResponse }} | ||
*/ | ||
getId(config) { | ||
const uspData = uspDataHandler.getConsentData(); | ||
if (uspData && uspData !== '1---') { | ||
return { id: undefined }; | ||
} | ||
const configParams = config.params || {}; | ||
|
||
if (configParams.companyId == null || isNaN(Number(configParams.companyId))) { | ||
utils.logMessage('Please provide a valid Company Id. Contact [email protected] for assistance.'); | ||
} | ||
|
||
return { | ||
callback: (complete) => { | ||
ajax.ajaxBuilder(10000)( | ||
`${graphUrl}?company_id=${configParams.companyId}&tapad_id_type=TAPAD_ID`, | ||
{ | ||
success: (response) => { | ||
const responseJson = JSON.parse(response); | ||
if (responseJson.hasOwnProperty('tapadId')) { | ||
complete(responseJson.tapadId); | ||
} | ||
}, | ||
error: (_, e) => { | ||
if (e.status === 404) { | ||
complete(undefined); | ||
} | ||
if (e.status === 403) { | ||
utils.logMessage('Invalid Company Id. Contact [email protected] for assistance.'); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
} | ||
} | ||
} | ||
submodule('userId', tapadIdSubmodule); |
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,65 @@ | ||
import { tapadIdSubmodule, graphUrl } from 'modules/tapadIdSystem.js'; | ||
import * as utils from 'src/utils.js'; | ||
|
||
import { server } from 'test/mocks/xhr.js'; | ||
|
||
describe('TapadIdSystem', function () { | ||
describe('getId', function() { | ||
const config = { params: { companyId: 12345 } }; | ||
it('should call to real time graph endpoint and handle valid response', function() { | ||
const callbackSpy = sinon.spy(); | ||
const callback = tapadIdSubmodule.getId(config).callback; | ||
callback(callbackSpy); | ||
|
||
const request = server.requests[0]; | ||
expect(request.url).to.eq(`${graphUrl}?company_id=12345&tapad_id_type=TAPAD_ID`); | ||
|
||
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ tapadId: 'your-tapad-id' })); | ||
expect(callbackSpy.lastCall.lastArg).to.eq('your-tapad-id'); | ||
}); | ||
|
||
it('should remove stored tapadId if not found', function() { | ||
const callbackSpy = sinon.spy(); | ||
const callback = tapadIdSubmodule.getId(config).callback; | ||
callback(callbackSpy); | ||
|
||
const request = server.requests[0]; | ||
|
||
request.respond(404); | ||
expect(callbackSpy.lastCall.lastArg).to.be.undefined; | ||
}); | ||
|
||
it('should log message with invalid company id', function() { | ||
const logMessageSpy = sinon.spy(utils, 'logMessage'); | ||
const callbackSpy = sinon.spy(); | ||
const callback = tapadIdSubmodule.getId(config).callback; | ||
callback(callbackSpy); | ||
|
||
const request = server.requests[0]; | ||
|
||
request.respond(403); | ||
expect(logMessageSpy.lastCall.lastArg).to.eq('Invalid Company Id. Contact [email protected] for assistance.'); | ||
logMessageSpy.restore(); | ||
}); | ||
|
||
it('should log message if company id not given', function() { | ||
const logMessageSpy = sinon.spy(utils, 'logMessage'); | ||
const callbackSpy = sinon.spy(); | ||
const callback = tapadIdSubmodule.getId({}).callback; | ||
callback(callbackSpy); | ||
|
||
expect(logMessageSpy.lastCall.lastArg).to.eq('Please provide a valid Company Id. Contact [email protected] for assistance.'); | ||
logMessageSpy.restore(); | ||
}); | ||
|
||
it('should log message if company id is incorrect format', function() { | ||
const logMessageSpy = sinon.spy(utils, 'logMessage'); | ||
const callbackSpy = sinon.spy(); | ||
const callback = tapadIdSubmodule.getId({ params: { companyId: 'notANumber' } }).callback; | ||
callback(callbackSpy); | ||
|
||
expect(logMessageSpy.lastCall.lastArg).to.eq('Please provide a valid Company Id. Contact [email protected] for assistance.'); | ||
logMessageSpy.restore(); | ||
}); | ||
}); | ||
}) |
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