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

[ParrableIdSystem] Accept list of partners as an array or string #6277

8 changes: 6 additions & 2 deletions modules/parrableIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function isValidConfig(configParams) {
utils.logError('User ID - parrableId submodule requires configParams');
return false;
}
if (!configParams.partner) {
if (!configParams.partners && !configParams.partner) {
utils.logError('User ID - parrableId submodule requires partner list');
return false;
}
Expand Down Expand Up @@ -183,10 +183,14 @@ function fetchId(configParams) {
const eid = (parrableId) ? parrableId.eid : null;
const refererInfo = getRefererInfo();
const uspString = uspDataHandler.getConsentData();
const partners = configParams.partners || configParams.partner
const trackers = typeof partners === 'string'
? partners.split(',')
: partners;

const data = {
eid,
trackers: configParams.partner.split(','),
trackers,
url: refererInfo.referer
};

Expand Down
89 changes: 66 additions & 23 deletions test/spec/modules/parrableIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const P_XHR_EID = '01.1588030911.test-new-eid'
const P_CONFIG_MOCK = {
name: 'parrableId',
params: {
partner: 'parrable_test_partner_123,parrable_test_partner_456'
partners: 'parrable_test_partner_123,parrable_test_partner_456'
}
};

Expand Down Expand Up @@ -74,21 +74,21 @@ function removeParrableCookie() {
storage.setCookie(P_COOKIE_NAME, '', EXPIRED_COOKIE_DATE);
}

function decodeBase64UrlSafe(encBase64) {
const DEC = {
'-': '+',
'_': '/',
'.': '='
};
return encBase64.replace(/[-_.]/g, (m) => DEC[m]);
}

describe('Parrable ID System', function() {
describe('parrableIdSystem.getId()', function() {
describe('response callback function', function() {
let logErrorStub;
let callbackSpy = sinon.spy();

let decodeBase64UrlSafe = function (encBase64) {
const DEC = {
'-': '+',
'_': '/',
'.': '='
};
return encBase64.replace(/[-_.]/g, (m) => DEC[m]);
}

beforeEach(function() {
logErrorStub = sinon.stub(utils, 'logError');
callbackSpy.resetHistory();
Expand All @@ -115,7 +115,7 @@ describe('Parrable ID System', function() {
expect(queryParams).to.not.have.property('us_privacy');
expect(data).to.deep.equal({
eid: P_COOKIE_EID,
trackers: P_CONFIG_MOCK.params.partner.split(','),
trackers: P_CONFIG_MOCK.params.partners.split(','),
url: getRefererInfo().referer
});

Expand Down Expand Up @@ -160,7 +160,7 @@ describe('Parrable ID System', function() {

it('should log an error and continue to callback if ajax request errors', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = parrableIdSubmodule.getId({ params: {partner: 'prebid'} }).callback;
let submoduleCallback = parrableIdSubmodule.getId({ params: {partners: 'prebid'} }).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.contain('h.parrable.com');
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('Parrable ID System', function() {

it('permits an impression when no timezoneFilter is configured', function() {
expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
} })).to.have.property('callback');
});

Expand All @@ -247,7 +247,7 @@ describe('Parrable ID System', function() {
writeParrableCookie({ eid: P_COOKIE_EID });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partnerss: 'prebid-test',
timezoneFilter: {
blockedZones: [ blockedZone ]
}
Expand All @@ -263,7 +263,7 @@ describe('Parrable ID System', function() {
Intl.DateTimeFormat.returns({ resolvedOptions });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
allowedZones: [ allowedZone ]
}
Expand All @@ -277,7 +277,7 @@ describe('Parrable ID System', function() {
Intl.DateTimeFormat.returns({ resolvedOptions });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
blockedZones: [ blockedZone ]
}
Expand All @@ -291,7 +291,7 @@ describe('Parrable ID System', function() {
Intl.DateTimeFormat.returns({ resolvedOptions });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
blockedZones: [ blockedZone ]
}
Expand All @@ -305,7 +305,7 @@ describe('Parrable ID System', function() {
Intl.DateTimeFormat.returns({ resolvedOptions });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
allowedZones: [ timezone ],
blockedZones: [ timezone ]
Expand Down Expand Up @@ -335,7 +335,7 @@ describe('Parrable ID System', function() {
writeParrableCookie({ eid: P_COOKIE_EID });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
blockedOffsets: [ blockedOffset ]
}
Expand All @@ -349,7 +349,7 @@ describe('Parrable ID System', function() {
Date.prototype.getTimezoneOffset.returns(allowedOffset * 60);

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
allowedOffsets: [ allowedOffset ]
}
Expand All @@ -363,7 +363,7 @@ describe('Parrable ID System', function() {
Date.prototype.getTimezoneOffset.returns(allowedOffset * 60);

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
blockedOffsets: [ blockedOffset ]
}
Expand All @@ -376,7 +376,7 @@ describe('Parrable ID System', function() {
Date.prototype.getTimezoneOffset.returns(blockedOffset * 60);

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
blockedOffsets: [ blockedOffset ]
}
Expand All @@ -389,7 +389,7 @@ describe('Parrable ID System', function() {
Date.prototype.getTimezoneOffset.returns(offset * 60);

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
allowedOffset: [ offset ],
blockedOffsets: [ offset ]
Expand Down Expand Up @@ -466,4 +466,47 @@ describe('Parrable ID System', function() {
}, { adUnits });
});
});

describe('partners parsing', () => {
let callbackSpy = sinon.spy();

const partnersTestCase = [
{
name: '"partners" as an array',
config: { params: { partners: ['parrable_test_partner_123', 'parrable_test_partner_456'] } },
expected: ['parrable_test_partner_123', 'parrable_test_partner_456']
},
{
name: '"partners" as a string list',
config: { params: { partners: 'parrable_test_partner_123,parrable_test_partner_456' } },
expected: ['parrable_test_partner_123', 'parrable_test_partner_456']
},
{
name: '"partners" as a string',
config: { params: { partners: 'parrable_test_partner_123' } },
expected: ['parrable_test_partner_123']
},
{
name: '"partner" as a string list',
config: { params: { partner: 'parrable_test_partner_123,parrable_test_partner_456' } },
expected: ['parrable_test_partner_123', 'parrable_test_partner_456']
},
{
name: '"partner" as string',
config: { params: { partner: 'parrable_test_partner_123' } },
expected: ['parrable_test_partner_123']
},
];
partnersTestCase.forEach(testCase => {
it(`accepts config property ${testCase.name}`, () => {
parrableIdSubmodule.getId(testCase.config).callback(callbackSpy);

let request = server.requests[0];
let queryParams = utils.parseQS(request.url.split('?')[1]);
let data = JSON.parse(atob(decodeBase64UrlSafe(queryParams.data)));

expect(data.trackers).to.deep.equal(testCase.expected);
});
});
});
});