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

Update Consumable adapter for Prebid.js 3.0 #4401

Merged
merged 4 commits into from
Nov 5, 2019
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
8 changes: 5 additions & 3 deletions modules/consumableBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const spec = {
const data = Object.assign({
placements: [],
time: Date.now(),
url: utils.getTopWindowUrl(),
url: bidderRequest.refererInfo.referer,
referrer: document.referrer,
source: [{
'name': 'prebidjs',
Expand All @@ -63,9 +63,10 @@ export const spec = {
}

validBidRequests.map(bid => {
const sizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes || [];
const placement = Object.assign({
divName: bid.bidId,
adTypes: bid.adTypes || getSize(bid.sizes)
adTypes: bid.adTypes || getSize(sizes)
}, bid.params);

if (placement.networkId && placement.siteId && placement.unitId && placement.unitName) {
Expand All @@ -75,6 +76,7 @@ export const spec = {

ret.data = JSON.stringify(data);
ret.bidRequest = validBidRequests;
ret.bidderRequest = bidderRequest;
ret.url = BASE_URI;

return ret;
Expand Down Expand Up @@ -117,7 +119,7 @@ export const spec = {
bid.creativeId = decision.adId;
bid.ttl = 30;
bid.netRevenue = true;
bid.referrer = utils.getTopWindowUrl();
bid.referrer = bidRequest.bidderRequest.refererInfo.referer;

bidResponses.push(bid);
}
Expand Down
218 changes: 140 additions & 78 deletions test/spec/modules/consumableBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,127 @@
import { expect } from 'chai';
import { spec } from 'modules/consumableBidAdapter';
import { createBid } from 'src/bidfactory';
import {expect} from 'chai';
import {spec} from 'modules/consumableBidAdapter';
import {createBid} from 'src/bidfactory';

const ENDPOINT = 'https://e.serverbid.com/api/v2';
const SMARTSYNC_CALLBACK = 'serverbidCallBids';

const REQUEST = {
'bidderCode': 'consumable',
'auctionId': 'a4713c32-3762-4798-b342-4ab810ca770d',
'bidderRequestId': '109f2a181342a9',
'bidRequest': [{
'bidder': 'consumable',
'params': {
'networkId': 9969,
'siteId': 730181,
'unitId': 123456,
'unitName': 'cnsmbl-unit'
},
'placementCode': 'div-gpt-ad-1487778092495-0',
'sizes': [
[728, 90],
[970, 90]
],
'bidId': '2b0f82502298c9',
'bidderRequestId': '109f2a181342a9',
'auctionId': 'a4713c32-3762-4798-b342-4ab810ca770d'
const BIDDER_REQUEST_1 = {
bidderCode: 'consumable',
auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
bidRequest: [
{
bidder: 'consumable',
params: {
networkId: '9969',
siteId: '730181',
unitId: '123456',
unitName: 'cnsmbl-unit'
},
placementCode: 'header-bid-tag-1',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
bidId: '23acc48ad47af5',
auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729'
}
],
gdprConsent: {
consentString: 'consent-test',
gdprApplies: false
},
{
'bidder': 'consumable',
'params': {
'networkId': 9969,
'siteId': 730181,
'unitId': 123456,
'unitName': 'cnsmbl-unit'
refererInfo: {
referer: 'http://example.com/page.html',
reachedTop: true,
numIframes: 2,
stack: [
'http://example.com/page.html',
'http://example.com/iframe1.html',
'http://example.com/iframe2.html'
]
}
};

const BIDDER_REQUEST_2 = {
bidderCode: 'consumable',
auctionId: 'a4713c32-3762-4798-b342-4ab810ca770d',
bidderRequestId: '109f2a181342a9',
bidRequest: [
{
bidder: 'consumable',
params: {
networkId: 9969,
siteId: 730181,
unitId: 123456,
unitName: 'cnsmbl-unit'
},
placementCode: 'div-gpt-ad-1487778092495-0',
mediaTypes: {
banner: {
sizes: [
[728, 90],
[970, 90]
]
}
},
bidId: '2b0f82502298c9',
bidderRequestId: '109f2a181342a9',
auctionId: 'a4713c32-3762-4798-b342-4ab810ca770d'
},
'placementCode': 'div-gpt-ad-1487778092495-0',
'sizes': [
[728, 90],
[970, 90]
],
'bidId': '123',
'bidderRequestId': '109f2a181342a9',
'auctionId': 'a4713c32-3762-4798-b342-4ab810ca770d'
}],
'gdprConsent': {
'consentString': 'consent-test',
'gdprApplies': true
{
bidder: 'consumable',
params: {
networkId: 9969,
siteId: 730181,
unitId: 123456,
unitName: 'cnsmbl-unit'
},
placementCode: 'div-gpt-ad-1487778092495-0',
mediaTypes: {
banner: {
sizes: [
[728, 90],
[970, 90]
]
}
},
bidId: '123',
bidderRequestId: '109f2a181342a9',
auctionId: 'a4713c32-3762-4798-b342-4ab810ca770d'
}
],
gdprConsent: {
consentString: 'consent-test',
gdprApplies: true
},
'start': 1487883186070,
'auctionStart': 1487883186069,
'timeout': 3000
refererInfo: {
referer: 'http://example.com/page.html',
reachedTop: true,
numIframes: 2,
stack: [
'http://example.com/page.html',
'http://example.com/iframe1.html',
'http://example.com/iframe2.html'
]
}
};

const RESPONSE = {
const BIDDER_REQUEST_EMPTY = {
bidderCode: 'consumable',
auctionId: 'b06458ef-4fe5-4a0b-a61b-bccbcedb7b11',
bidderRequestId: '8c8006750b10fd',
bidRequest: [],
gdprConsent: {
consentString: 'consent-test',
gdprApplies: false
}
};

const AD_SERVER_RESPONSE = {
'headers': null,
'body': {
'user': { 'key': 'ue1-2d33e91b71e74929b4aeecc23f4376f1' },
Expand Down Expand Up @@ -108,30 +177,17 @@ const RESPONSE = {
}
};

const BUILD_REQUESTS_OUTPUT = {
method: 'POST',
url: 'https://e.serverbid.com/api/v2',
data: '',
bidRequest: BIDDER_REQUEST_2.bidRequest,
bidderRequest: BIDDER_REQUEST_2
};

describe('Consumable BidAdapter', function () {
let bidRequests;
let adapter = spec;

beforeEach(function () {
bidRequests = [
{
bidder: 'consumable',
params: {
networkId: '9969',
siteId: '730181',
unitId: '123456',
unitName: 'cnsmbl-unit'
},
placementCode: 'header-bid-tag-1',
sizes: [[300, 250], [300, 600]],
bidId: '23acc48ad47af5',
auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729'
}
];
});

describe('bid request validation', function () {
it('should accept valid bid requests', function () {
let bid = {
Expand Down Expand Up @@ -187,43 +243,49 @@ describe('Consumable BidAdapter', function () {

describe('buildRequests validation', function () {
it('creates request data', function () {
let request = spec.buildRequests(bidRequests);
let request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1);

expect(request).to.exist.and.to.be.a('object');
});

it('request to consumable should contain a url', function () {
let request = spec.buildRequests(bidRequests);
let request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1);

expect(request.url).to.have.string('serverbid.com');
});

it('requires valid bids to make request', function () {
let request = spec.buildRequests([]);
let request = spec.buildRequests(BIDDER_REQUEST_EMPTY.bidRequest, BIDDER_REQUEST_EMPTY);
expect(request.bidRequest).to.be.empty;
});

it('sends bid request to ENDPOINT via POST', function () {
let request = spec.buildRequests(bidRequests);
let request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1);

expect(request.method).to.have.string('POST');
});

it('passes through bidderRequest', function () {
let request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1);

expect(request.bidderRequest).to.equal(BIDDER_REQUEST_1);
})
});
describe('interpretResponse validation', function () {
it('response should have valid bidderCode', function () {
let bidRequest = spec.buildRequests(REQUEST.bidRequest, REQUEST);
let bidRequest = spec.buildRequests(BIDDER_REQUEST_2.bidRequest, BIDDER_REQUEST_2);
let bid = createBid(1, bidRequest.bidRequest[0]);

expect(bid.bidderCode).to.equal('consumable');
});

it('response should include objects for all bids', function () {
let bids = spec.interpretResponse(RESPONSE, REQUEST);
let bids = spec.interpretResponse(AD_SERVER_RESPONSE, BUILD_REQUESTS_OUTPUT);
expect(bids.length).to.equal(2);
});

it('registers bids', function () {
let bids = spec.interpretResponse(RESPONSE, REQUEST);
let bids = spec.interpretResponse(AD_SERVER_RESPONSE, BUILD_REQUESTS_OUTPUT);
bids.forEach(b => {
expect(b).to.have.property('cpm');
expect(b.cpm).to.be.above(0);
Expand All @@ -243,14 +305,14 @@ describe('Consumable BidAdapter', function () {
});

it('handles nobid responses', function () {
let EMPTY_RESP = Object.assign({}, RESPONSE, {'body': {'decisions': null}})
let bids = spec.interpretResponse(EMPTY_RESP, REQUEST);
let EMPTY_RESP = Object.assign({}, AD_SERVER_RESPONSE, {'body': {'decisions': null}})
let bids = spec.interpretResponse(EMPTY_RESP, BUILD_REQUESTS_OUTPUT);

expect(bids).to.be.empty;
});

it('handles no server response', function () {
let bids = spec.interpretResponse(null, REQUEST);
let bids = spec.interpretResponse(null, BUILD_REQUESTS_OUTPUT);

expect(bids).to.be.empty;
});
Expand All @@ -272,7 +334,7 @@ describe('Consumable BidAdapter', function () {

it('should return a sync url if pixel syncs are enabled and some are returned from the server', function () {
let syncOptions = {'pixelEnabled': true};
let opts = spec.getUserSyncs(syncOptions, [RESPONSE]);
let opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE]);

expect(opts.length).to.equal(1);
});
Expand Down