Skip to content

Commit

Permalink
add PAF unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bwschmidt committed May 9, 2022
1 parent 1f9ab34 commit 825b08b
Show file tree
Hide file tree
Showing 9 changed files with 417 additions and 48 deletions.
2 changes: 2 additions & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"netIdSystem",
"nextrollIdSystem",
"novatiqIdSystem",
"pafIdSystem",
"parrableIdSystem",
"pubProvidedIdSystem",
"publinkIdSystem",
Expand Down Expand Up @@ -58,6 +59,7 @@
"jwplayerRtdProvider",
"medianetRtdProvider",
"optimeraRtdProvider",
"pafRtdProvider",
"permutiveRtdProvider",
"reconciliationRtdProvider",
"sirdataRtdProvider",
Expand Down
4 changes: 2 additions & 2 deletions modules/openxRtbBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import includes from 'core-js-pure/features/array/includes.js'
import {includes} from '../src/polyfill.js';

const bidderConfig = 'hb_pb_ortb';
const bidderVersion = '1.0';
Expand Down Expand Up @@ -363,4 +363,4 @@ function getUserSyncs(syncOptions, responses, gdprConsent, uspConsent) {
url: `${syncUrl}${queryParamStrings.length > 0 ? '?' + queryParamStrings.join('&') : ''}`
}];
}
}
}
42 changes: 21 additions & 21 deletions modules/pafIdSystem.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
/**
* This module adds pafId to the User ID module
* This module adds pafData to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/swanIdSystem
* @requires module:modules/userId
*/

import {submodule} from '../src/hook.js';
import {submodule} from '../src/hook.js';

/** @type {Submodule} */
export const pafIdSubmodule = {
/**
/** @type {Submodule} */
export const pafIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'pafData',
/**
name: 'pafData',
/**
* decode the stored data value for passing to bid requests
* @function decode
* @param {(Object|string)} value
* @returns {(Object|undefined)}
*/
decode(data) {
return { pafData: data };
},
/**
decode(data) {
return { pafData: data };
},
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleConfig} [config]
* @param {ConsentData} [consentData]
* @param {(Object|undefined)} cacheIdObj
* @returns {IdResponse|undefined}
*/
getId(config, consentData) {
if (window.PAF && window.PAF.getIdsAndPreferences()) {
return {id: window.PAF.getIdsAndPreferences()};
} else {
return undefined;
}
}
};
submodule('userId', pafIdSubmodule);
getId(config, consentData) {
if (window.PAF && window.PAF.getIdsAndPreferences()) {
return {id: window.PAF.getIdsAndPreferences()};
} else {
return undefined;
}
}
};

submodule('userId', pafIdSubmodule);
14 changes: 8 additions & 6 deletions modules/pafIdSystem.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Prebid Addressability Framework (OneKey)

Insert description here
https://github.com/prebid/addressability-framework
https://github.com/prebid/paf-mvp-implementation
The PAF real-time data module in Prebid has been built so that publishers
can quickly and easily setup the Prebid Addressability Framework and utilize OneKey.
This module is used along with the pafRtdProvider to pass PAF data to your partners.
Both modules are required. This module will pass paData to your partners
while the pafRtdProvider will pass the transmission requests.

## PAF Registration

insert info here
Background information:
- [prebid/addressability-framework](https://github.com/prebid/addressability-framework)
- [prebid/paf-mvp-implementation](https://github.com/prebid/paf-mvp-implementation)

## PAF Configuration

Expand Down
15 changes: 7 additions & 8 deletions modules/pafRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SUBMODULE_NAME = 'paf';
* @param {Object} rtdConfig
* @param {Object} userConsent
*/
function getBidRequestData(reqBidsConfigObj, onDone, rtdConfig, userConsent) {
export function getBidRequestData(reqBidsConfigObj, onDone, rtdConfig, userConsent) {
let idsAndPreferences;
const adUnits = (reqBidsConfigObj.adUnits || getGlobal().adUnits);

Expand All @@ -25,17 +25,16 @@ function getBidRequestData(reqBidsConfigObj, onDone, rtdConfig, userConsent) {
return;
}

let transaction_ids = [];
for (var i=0; i < adUnits.length; i++) {
let transactionIds = [];
for (var i = 0; i < adUnits.length; i++) {
const uuid = generateUUID();
transaction_ids.push(uuid)
transactionIds.push(uuid)
deepSetValue(adUnits[i], `ortb2Imp.ext.data.paf.transaction_id`, uuid)
}

window.PAF.generateSeed({proxyHostName: rtdConfig.params.proxyHostName, callback: function (seed) {setData(seed, rtdConfig, onDone);}}, transaction_ids)
window.PAF.generateSeed({proxyHostName: rtdConfig.params.proxyHostName, callback: function (seed) { setData(seed, rtdConfig, onDone); }}, transactionIds)
} else {
onDone();
return;
}
}

Expand All @@ -44,7 +43,7 @@ function getBidRequestData(reqBidsConfigObj, onDone, rtdConfig, userConsent) {
* @param {Object} target
* @param {Object} source
*/
function mergeLazy(target, source) {
function mergeLazy(target, source) {
if (!isPlainObject(target)) {
target = {};
}
Expand All @@ -56,7 +55,7 @@ function getBidRequestData(reqBidsConfigObj, onDone, rtdConfig, userConsent) {
return mergeDeep(target, source);
}

function setData(seed, rtdConfig, onDone) {
export function setData(seed, rtdConfig, onDone) {
if (!seed) {
logError(SUBMODULE_NAME, 'Could not createSeed');
onDone()
Expand Down
38 changes: 35 additions & 3 deletions modules/pafRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Background information:
- [prebid/addressability-framework](https://github.com/prebid/addressability-framework)
- [prebid/paf-mvp-implementation](https://github.com/prebid/paf-mvp-implementation)



### Publisher Usage

The paf RTD module depends on paf-lib.js existing in the page.
Expand Down Expand Up @@ -91,4 +89,38 @@ The following is an example of the format of the data:
}
}
}
```
```

### Bidder Responses

Bidders who are part of the Prebid Addressability Framework and receive PAF
transmissions are required to return transmission responses as outlined in
[prebid/addressability-framework](https://github.com/prebid/addressability-framework/blob/main/mvp-spec/ad-auction.md). Transmission responses should be appended to bids
along with the releveant content_id using the meta.paf field. The paf-lib will
be responsible for collecting all of the transmission responses.

Below is an example of setting a transmission response:
```javascript
bid.meta.paf = {
"content_id": "90141190-26fe-497c-acee-4d2b649c2112",
"transmission": {
"version": "0.1",
"contents": [
{
"transaction_id": "f55a401d-e8bb-4de1-a3d2-fa95619393e8",
"content_id": "90141190-26fe-497c-acee-4d2b649c2112"
}
],
"status": "success",
"details": "",
"receiver": "dsp1.com",
"source": {
"domain": "dsp1.com",
"timestamp": 1639589531,
"signature": "d01c6e83f14b4f057c2a2a86d320e2454fc0c60df4645518d993b5f40019d24c"
},
"children": []
}
}
```

23 changes: 15 additions & 8 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,29 @@ export const USER_IDS_CONFIG = {
}
},

// PAF Data
'pafData': {
getValue: function(data) {
return data.identifiers[0].value;
if (data && Array.isArray(data.identifiers) && data.identifiers[0]) {
return data.identifiers[0].value;
}
},
source: 'paf',
atype: 1,
getEidExt: function(data) {
return {preferences: data.preferences};
if (data && data.preferences) {
return {preferences: data.preferences};
}
},
getUidExt: function(data) {
const id = data.identifiers[0];
return {
version: id.version,
type: id.type,
source: id.source
};
if (data && Array.isArray(data.identifiers) && data.identifiers[0]) {
const id = data.identifiers[0];
return {
version: id.version,
type: id.type,
source: id.source
};
}
}
}
};
Expand Down
114 changes: 114 additions & 0 deletions test/spec/modules/pafIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { pafIdSubmodule } from 'modules/pafIdSystem'
import { config } from 'src/config.js';
import {find} from 'src/polyfill.js';
import { init, requestBidsHook, setSubmoduleRegistry } from 'modules/userId/index.js';

const idsAndPrefs = {
'identifiers': [
{
'version': '0.1',
'type': 'paf_browser_id',
'value': 'da135b3a-7d04-44bf-a0af-c4709f10420b',
'source': {
'domain': 'crto-poc-1.onekey.network',
'timestamp': 1648836556881,
'signature': '+NF27bBvPM54z103YPExXuS834+ggAQe6JV0jPeGo764vRYiiBl5OmEXlnB7UZgxNe3KBU7rN2jk0SkI4uL0bg=='
}
}
],
'preferences': {
'version': '0.1',
'data': {
'use_browsing_for_personalization': true
},
'source': {
'domain': 'cmp.pafdemopublisher.com',
'timestamp': 1648836566468,
'signature': 'ipbYhU8IbSFm2tCqAVYI2d5w4DnGF7Xa2AaiZScx2nmBPLfMmIT/FkBYGitR8Mi791DHtcy5MXr4+bs1aeZFqw=='
}
}
};

function getConfigMock() {
return {
userSync: {
syncDelay: 0,
userIds: [{
name: 'pafData'
}]
}
}
}

function getAdUnitMock(code = 'adUnit-code') {
return {
code,
mediaTypes: {banner: {}, native: {}},
sizes: [
[300, 200],
[300, 600]
],
bids: [{
bidder: 'sampleBidder',
params: { placementId: 'banner-only-bidder' }
}]
};
}

describe('pafData module', function () {
it('returns undefined if paf-lib is not found', function () {
const moduleIdResponse = pafIdSubmodule.getId();
expect(moduleIdResponse).to.be.undefined;
})
it('returns undefined if no Data', function () {
window.PAF = {
getIdsAndPreferences() {
return undefined;
}
}
const moduleIdResponse = pafIdSubmodule.getId();
expect(moduleIdResponse).to.be.undefined;
})
it('gets pafData from page context', function () {
window.PAF = {
getIdsAndPreferences() {
return idsAndPrefs;
}
}
const moduleIdResponse = pafIdSubmodule.getId();
expect(moduleIdResponse).to.deep.equal({id: idsAndPrefs});
})

// this test format was copied from other id module tests
// but it is failing on the hook and im not sure why, if someone
// knows why and can help i will fix, otherwise i will remove it
// describe('requestBids hook', function() {
// let adUnits;

// beforeEach(function() {
// adUnits = [getAdUnitMock()];
// window.PAF = {
// getIdsAndPreferences() {
// return idsAndPrefs;
// }
// }
// init(config);
// setSubmoduleRegistry([pafIdSubmodule]);
// config.setConfig(getConfigMock());
// });

// it('when pafData exists it is added to bids', function(done) {
// requestBidsHook(function() {
// adUnits.forEach(unit => {
// unit.bids.forEach(bid => {
// expect(bid).to.have.deep.nested.property('userId.pafData');
// expect(bid.userId.pafData).to.equal(idsAndPrefs);
// const pafDataAsEid = find(bid.userIdAsEids, e => e.source == 'paf');
// expect(pafDataAsEid.uids[0].id).to.equal('da135b3a-7d04-44bf-a0af-c4709f10420b');
// });
// });
// done();
// }, { adUnits });
// });
// });
})
Loading

0 comments on commit 825b08b

Please sign in to comment.