Skip to content

Commit

Permalink
[ParrableIdSystem] Accept list of partners as an array or string (pre…
Browse files Browse the repository at this point in the history
…bid#6277)

* Accept partners as an array and fallthrough partner if no partners

* Ensure that Parrable data object decodes with urlsafe base64 in tests

* Fixed tests caused by typo in config property

* Fix failing test due to accessing unexisting property 'partner'

Co-authored-by: Victor <victorigualada@gmail.com>
  • Loading branch information
icflournoy and victorigualada authored Feb 5, 2021
1 parent ccd570b commit 86516ab
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 25 deletions.
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,
prebidVersion: '$prebid.version$',
isIframe: utils.inIframe()
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,
prebidVersion: '$prebid.version$',
isIframe: true
Expand Down Expand Up @@ -162,7 +162,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 @@ -237,7 +237,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 @@ -249,7 +249,7 @@ describe('Parrable ID System', function() {
writeParrableCookie({ eid: P_COOKIE_EID });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
partners: 'prebid-test',
timezoneFilter: {
blockedZones: [ blockedZone ]
}
Expand All @@ -265,7 +265,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 @@ -279,7 +279,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 @@ -293,7 +293,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 @@ -307,7 +307,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 @@ -337,7 +337,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 @@ -351,7 +351,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 @@ -365,7 +365,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 @@ -378,7 +378,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 @@ -391,7 +391,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 @@ -468,4 +468,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);
});
});
});
});

0 comments on commit 86516ab

Please sign in to comment.