Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intentiq id add validation #5797

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions modules/intentIqIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ import {submodule} from '../src/hook.js'

const MODULE_NAME = 'intentIqId';

const NOT_AVAILABLE = 'NA';

/**
* Verify the id is valid - Id value or Not Found (ignore not available response)
* @param id
* @returns {boolean|*|boolean}
*/
function isValidId(id) {
return id && id != '' && id != NOT_AVAILABLE && isValidResponse(id);
}

/**
* Ignore not available response JSON
* @param obj
* @returns {boolean}
*/
function isValidResponse(obj) {
try {
obj = JSON.parse(obj);
return obj && obj['RESULT'] != NOT_AVAILABLE;
} catch (error) {
utils.logError(error);
return true;
}
}

/** @type {Submodule} */
export const intentIqIdSubmodule = {
/**
Expand All @@ -22,10 +48,10 @@ export const intentIqIdSubmodule = {
* decode the stored id value for passing to bid requests
* @function
* @param {{string}} value
* @returns {{intentIqId:string}}
* @returns {{intentIqId: {string}}|undefined}
*/
decode(value) {
return (value && value != '') ? { 'intentIqId': value } : undefined;
return isValidId(value) ? { 'intentIqId': value } : undefined;
},
/**
* performs action to obtain id and return a value in the callback's response argument
Expand All @@ -47,7 +73,11 @@ export const intentIqIdSubmodule = {
const resp = function (callback) {
const callbacks = {
success: response => {
callback(response);
if (isValidId(response)) {
callback(response);
} else {
callback();
}
},
error: error => {
utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error);
Expand Down
8 changes: 8 additions & 0 deletions test/spec/modules/intentIqIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ describe('IntentIQ tests', function () {
expect(callBackSpy.calledOnce).to.be.true;
});

it('should ignore NA and invalid responses', function () {
let resp = JSON.stringify({'RESULT': 'NA'});
expect(intentIqIdSubmodule.decode(resp)).to.equal(undefined);
expect(intentIqIdSubmodule.decode('NA')).to.equal(undefined);
expect(intentIqIdSubmodule.decode('')).to.equal(undefined);
expect(intentIqIdSubmodule.decode(undefined)).to.equal(undefined);
});

it('should call the IntentIQ endpoint with only partner, pai', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = intentIqIdSubmodule.getId(paiConfigParams).callback;
Expand Down