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

consumable Bid Adapter : add shared ID #8605

Merged
merged 1 commit into from
Jul 12, 2022
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
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);
});
});
});