Skip to content

Commit

Permalink
Add support for advertiserDomains (prebid#6980)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyu0 authored Jun 9, 2021
1 parent 27e4541 commit 4e60945
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
15 changes: 13 additions & 2 deletions modules/glimpseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 31 additions & 3 deletions test/spec/modules/glimpseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down Expand Up @@ -139,15 +142,19 @@ 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 () {
const bidderRequest = copyBidderRequest();
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
);
});
});

Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 4e60945

Please sign in to comment.