From 0e7cf6bf9e334a5ebec69b3c2da321cc582ffd2e Mon Sep 17 00:00:00 2001 From: Jason Piros Date: Tue, 12 Jul 2022 04:52:23 -0700 Subject: [PATCH] consumableBidAdapter - add shared ID (#8605) --- modules/consumableBidAdapter.js | 13 +++- .../spec/modules/consumableBidAdapter_spec.js | 75 +++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/modules/consumableBidAdapter.js b/modules/consumableBidAdapter.js index afdf34b72c1..5c34fbe8c64 100644 --- a/modules/consumableBidAdapter.js +++ b/modules/consumableBidAdapter.js @@ -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'; @@ -78,6 +78,8 @@ export const spec = { } }); + handleEids(data, validBidRequests); + ret.data = JSON.stringify(data); ret.bidRequest = validBidRequests; ret.bidderRequest = bidderRequest; @@ -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); diff --git a/test/spec/modules/consumableBidAdapter_spec.js b/test/spec/modules/consumableBidAdapter_spec.js index b70cd6fe631..23851c0da40 100644 --- a/test/spec/modules/consumableBidAdapter_spec.js +++ b/test/spec/modules/consumableBidAdapter_spec.js @@ -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'; @@ -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); + }); + }); });