Skip to content

Commit

Permalink
consumableBidAdapter - add shared ID (prebid#8605)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpiros authored and bwhisp committed Jul 13, 2022
1 parent 8c893d4 commit 0e7cf6b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
13 changes: 12 additions & 1 deletion modules/consumableBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logWarn, createTrackPixelHtml } from '../src/utils.js';
import { logWarn, createTrackPixelHtml, deepAccess, isArray, deepSetValue } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'consumable';
Expand Down Expand Up @@ -78,6 +78,8 @@ export const spec = {
}
});

handleEids(data, validBidRequests);

ret.data = JSON.stringify(data);
ret.bidRequest = validBidRequests;
ret.bidderRequest = bidderRequest;
Expand Down Expand Up @@ -234,4 +236,13 @@ function retrieveAd(decision, unitId, unitName) {
return ad;
}

function handleEids(data, validBidRequests) {
let bidUserIdAsEids = deepAccess(validBidRequests, '0.userIdAsEids');
if (isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) {
deepSetValue(data, 'user.eids', bidUserIdAsEids);
} else {
deepSetValue(data, 'user.eids', undefined);
}
}

registerBidder(spec);
75 changes: 75 additions & 0 deletions test/spec/modules/consumableBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {expect} from 'chai';
import {spec} from 'modules/consumableBidAdapter.js';
import {createBid} from 'src/bidfactory.js';
import {config} from 'src/config.js';
import {deepClone} from 'src/utils.js';
import { createEidsArray } from 'modules/userId/eids.js';

const ENDPOINT = 'https://e.serverbid.com/api/v2';
const SMARTSYNC_CALLBACK = 'serverbidCallBids';
Expand Down Expand Up @@ -425,4 +428,76 @@ describe('Consumable BidAdapter', function () {
expect(opts.length).to.equal(1);
});
});
describe('unifiedId from userId module', function() {
let sandbox, bidderRequest;
beforeEach(() => {
sandbox = sinon.sandbox.create();
bidderRequest = deepClone(BIDDER_REQUEST_1);
});

afterEach(() => {
sandbox.restore();
});

it('Request should have unifiedId config params', function() {
bidderRequest.bidRequest[0].userId = {};
bidderRequest.bidRequest[0].userId.tdid = 'TTD_ID';
bidderRequest.bidRequest[0].userIdAsEids = createEidsArray(bidderRequest.bidRequest[0].userId);
let request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1);
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal([{
'source': 'adserver.org',
'uids': [{
'id': 'TTD_ID',
'atype': 1,
'ext': {
'rtiPartner': 'TDID'
}
}]
}]);
});

it('Request should have adsrvrOrgId from UserId Module if config and userId module both have TTD ID', function() {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
adsrvrOrgId: {
'TDID': 'TTD_ID_FROM_CONFIG',
'TDID_LOOKUP': 'TRUE',
'TDID_CREATED_AT': '2022-06-21T09:47:00'
}
};
return config[key];
});
bidderRequest.bidRequest[0].userId = {};
bidderRequest.bidRequest[0].userId.tdid = 'TTD_ID';
bidderRequest.bidRequest[0].userIdAsEids = createEidsArray(bidderRequest.bidRequest[0].userId);
let request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1);
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal([{
'source': 'adserver.org',
'uids': [{
'id': 'TTD_ID',
'atype': 1,
'ext': {
'rtiPartner': 'TDID'
}
}]
}]);
});

it('Request should NOT have adsrvrOrgId params if userId is NOT object', function() {
let request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1);
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal(undefined);
});

it('Request should NOT have adsrvrOrgId params if userId.tdid is NOT string', function() {
bidderRequest.bidRequest[0].userId = {
tdid: 1234
};
let request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1);
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal(undefined);
});
});
});

0 comments on commit 0e7cf6b

Please sign in to comment.