From 4e60945c85e47a5a7c52e4489efebbb16e8619ba Mon Sep 17 00:00:00 2001 From: EddieYu <32135564+eddieyu1998@users.noreply.github.com> Date: Wed, 9 Jun 2021 12:06:28 +0100 Subject: [PATCH] Add support for advertiserDomains (#6980) --- modules/glimpseBidAdapter.js | 15 +++++++-- test/spec/modules/glimpseBidAdapter_spec.js | 34 +++++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/modules/glimpseBidAdapter.js b/modules/glimpseBidAdapter.js index 969c04bb451..9ef46f62f1d 100644 --- a/modules/glimpseBidAdapter.js +++ b/modules/glimpseBidAdapter.js @@ -3,6 +3,17 @@ import { BANNER } from '../src/mediaTypes.js'; const BIDDER_CODE = 'glimpse'; +function transformEachBidResponse(glimpseBid) { + const bid = glimpseBid; + bid.meta = { advertiserDomains: [] }; + + if (glimpseBid.adomain) { + bid.meta.advertiserDomains = glimpseBid.adomain; + } + + return bid; +} + export const spec = { code: BIDDER_CODE, url: 'https://api.glimpseprotocol.io/cloud/v1/vault/prebid', @@ -45,10 +56,10 @@ export const spec = { }, interpretResponse: (serverResponse, _) => { - const bids = []; + let bids = []; try { const { body } = serverResponse; - bids.push(...body); + bids = body.map(transformEachBidResponse); } catch (error) {} return bids; diff --git a/test/spec/modules/glimpseBidAdapter_spec.js b/test/spec/modules/glimpseBidAdapter_spec.js index cc11efcb2af..336f606309e 100644 --- a/test/spec/modules/glimpseBidAdapter_spec.js +++ b/test/spec/modules/glimpseBidAdapter_spec.js @@ -61,7 +61,10 @@ const templateBidResponse = { }; const copyBidResponse = () => ({ ...templateBidResponse }); -const copyBidderRequest = () => ({ ...templateBidderRequest, bids: copyBidRequests() }); +const copyBidderRequest = () => ({ + ...templateBidderRequest, + bids: copyBidRequests(), +}); const copyBidRequest = () => ({ ...templateBidRequest }); const copyBidRequests = () => [copyBidRequest()]; @@ -139,7 +142,9 @@ describe('GlimpseProtocolAdapter', function () { expect(payload.gdprConsent).to.exist; const { gdprConsent } = payload; expect(gdprConsent.gdprApplies).to.be.true; - expect(gdprConsent.consentString).to.equal(bidderRequest.gdprConsent.consentString); + expect(gdprConsent.consentString).to.equal( + bidderRequest.gdprConsent.consentString + ); }); it('should add referer info', function () { @@ -147,7 +152,9 @@ describe('GlimpseProtocolAdapter', function () { const request = spec.buildRequests(bidRequests, bidderRequest); const payload = JSON.parse(request.data); - expect(payload.refererInfo.referer).to.equal(templateBidderRequest.refererInfo.referer); + expect(payload.refererInfo.referer).to.equal( + templateBidderRequest.refererInfo.referer + ); }); }); @@ -175,5 +182,26 @@ describe('GlimpseProtocolAdapter', function () { const bids = spec.interpretResponse(response); expect(bids).to.have.length(0); }); + + it('should include advertiserDomains field in the response', function () { + const response = copyBidResponses(); + + const bids = spec.interpretResponse(response); + expect(bids[0].meta.advertiserDomains).to.be.an('array').that.is.empty; + }); + + it('should reflect the value of the OpenRTB adomain field', function () { + const advertiserDomainsMock = ['http://example.com']; + let response = copyBidResponses(); + response.body = response.body.map((bid) => { + return { + ...bid, + adomain: advertiserDomainsMock, + }; + }); + + const bids = spec.interpretResponse(response); + expect(bids[0].meta.advertiserDomains).to.equal(advertiserDomainsMock); + }); }); });