Skip to content

Commit

Permalink
Loglylift Bid Adapter: add support for banners (#8270)
Browse files Browse the repository at this point in the history
* Support banner mediatype

* add bannerType test
  • Loading branch information
HashimotoLogly authored Apr 8, 2022
1 parent fdfa7a2 commit 7d42e11
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 47 deletions.
7 changes: 4 additions & 3 deletions modules/loglyliftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { NATIVE } from '../src/mediaTypes.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';

const BIDDER_CODE = 'loglylift';
const ENDPOINT_URL = 'https://bid.logly.co.jp/prebid/client/v1';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [NATIVE],
supportedMediaTypes: [BANNER, NATIVE],

isBidRequestValid: function (bid) {
return !!(bid.params && bid.params.adspotId);
Expand Down Expand Up @@ -43,7 +43,8 @@ export const spec = {
getUserSyncs: function (syncOptions, serverResponses) {
const syncs = [];

if (syncOptions.iframeEnabled && serverResponses.length > 0) {
// sync if mediaType is native because not native ad itself has a function for sync
if (syncOptions.iframeEnabled && serverResponses.length > 0 && serverResponses[0].body.bids[0].native) {
syncs.push({
type: 'iframe',
url: 'https://sync.logly.co.jp/sync/sync.html'
Expand Down
16 changes: 16 additions & 0 deletions modules/loglyliftBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ Currently module supports only native mediaType.
# Test Parameters
```
var adUnits = [
// Banner adUnit
{
code: 'test-banner-code',
sizes: [[300, 250], [300, 600]],
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
bids: [{
bidder: 'loglylift',
params: {
adspotId: 1302078
}
}]
},
// Native adUnit
{
code: 'test-native-code',
Expand Down
157 changes: 113 additions & 44 deletions test/spec/modules/loglyliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ import { spec } from '../../../modules/loglyliftBidAdapter';
import * as utils from 'src/utils.js';

describe('loglyliftBidAdapter', function () {
const bannerBidRequests = [{
bidder: 'loglylift',
bidId: '51ef8751f9aead',
params: {
adspotId: 16
},
adUnitCode: '/19968336/prebid_native_example_1',
transactionId: '10aee457-617c-4572-ab5b-99df1d73ccb4',
sizes: [[300, 250], [300, 600]],
bidderRequestId: '15da3afd9632d7',
auctionId: 'f890b7d9-e787-4237-ac21-6d8554abac9f',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
}
}];

const nativeBidRequests = [{
bidder: 'loglylift',
bidId: '254304ac29e265',
Expand Down Expand Up @@ -51,6 +69,25 @@ describe('loglyliftBidAdapter', function () {
timeout: 3000
};

const bannerServerResponse = {
body: {
bids: [{
requestId: '51ef8751f9aead',
cpm: 101.0234,
width: 300,
height: 250,
creativeId: '16',
currency: 'JPY',
netRevenue: true,
ttl: 60,
meta: {
advertiserDomains: ['advertiserexample.com']
},
ad: '<div>TEST</div>',
}]
}
};

const nativeServerResponse = {
body: {
bids: [{
Expand Down Expand Up @@ -83,39 +120,43 @@ describe('loglyliftBidAdapter', function () {
};

describe('isBidRequestValid', function () {
it('should return true if the adspotId parameter is present', function () {
expect(spec.isBidRequestValid(nativeBidRequests[0])).to.be.true;
});
[nativeBidRequests, bannerBidRequests].forEach(bidRequests => {
it('should return true if the adspotId parameter is present', function () {
expect(spec.isBidRequestValid(bidRequests[0])).to.be.true;
});

it('should return false if the adspotId parameter is not present', function () {
let bidRequest = utils.deepClone(nativeBidRequests[0]);
delete bidRequest.params.adspotId;
expect(spec.isBidRequestValid(bidRequest)).to.be.false;
it('should return false if the adspotId parameter is not present', function () {
let bidRequest = utils.deepClone(bidRequests[0]);
delete bidRequest.params.adspotId;
expect(spec.isBidRequestValid(bidRequest)).to.be.false;
});
});
});

describe('buildRequests', function () {
it('should generate a valid single POST request for multiple bid requests', function () {
const request = spec.buildRequests(nativeBidRequests, bidderRequest)[0];
expect(request.method).to.equal('POST');
expect(request.url).to.equal('https://bid.logly.co.jp/prebid/client/v1?adspot_id=16');
expect(request.data).to.exist;

const data = JSON.parse(request.data);
expect(data.auctionId).to.equal(nativeBidRequests[0].auctionId);
expect(data.bidderRequestId).to.equal(nativeBidRequests[0].bidderRequestId);
expect(data.transactionId).to.equal(nativeBidRequests[0].transactionId);
expect(data.adUnitCode).to.equal(nativeBidRequests[0].adUnitCode);
expect(data.bidId).to.equal(nativeBidRequests[0].bidId);
expect(data.mediaTypes).to.deep.equal(nativeBidRequests[0].mediaTypes);
expect(data.params).to.deep.equal(nativeBidRequests[0].params);
expect(data.prebidJsVersion).to.equal('$prebid.version$');
expect(data.url).to.exist;
expect(data.domain).to.exist;
expect(data.referer).to.equal(bidderRequest.refererInfo.referer);
expect(data.auctionStartTime).to.equal(bidderRequest.auctionStart);
expect(data.currency).to.exist;
expect(data.timeout).to.equal(bidderRequest.timeout);
[nativeBidRequests, bannerBidRequests].forEach(bidRequests => {
it('should generate a valid single POST request for multiple bid requests', function () {
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.method).to.equal('POST');
expect(request.url).to.equal('https://bid.logly.co.jp/prebid/client/v1?adspot_id=16');
expect(request.data).to.exist;

const data = JSON.parse(request.data);
expect(data.auctionId).to.equal(bidRequests[0].auctionId);
expect(data.bidderRequestId).to.equal(bidRequests[0].bidderRequestId);
expect(data.transactionId).to.equal(bidRequests[0].transactionId);
expect(data.adUnitCode).to.equal(bidRequests[0].adUnitCode);
expect(data.bidId).to.equal(bidRequests[0].bidId);
expect(data.mediaTypes).to.deep.equal(bidRequests[0].mediaTypes);
expect(data.params).to.deep.equal(bidRequests[0].params);
expect(data.prebidJsVersion).to.equal('$prebid.version$');
expect(data.url).to.exist;
expect(data.domain).to.exist;
expect(data.referer).to.equal(bidderRequest.refererInfo.referer);
expect(data.auctionStartTime).to.equal(bidderRequest.auctionStart);
expect(data.currency).to.exist;
expect(data.timeout).to.equal(bidderRequest.timeout);
});
});
});

Expand All @@ -125,20 +166,40 @@ describe('loglyliftBidAdapter', function () {
expect(interpretedResponse).to.be.an('array').that.is.empty;
});

it('should return valid response when passed valid server response', function () {
const request = spec.buildRequests(nativeBidRequests, bidderRequest)[0];
const interpretedResponse = spec.interpretResponse(nativeServerResponse, request);

expect(interpretedResponse).to.have.lengthOf(1);
expect(interpretedResponse[0].cpm).to.equal(nativeServerResponse.body.bids[0].cpm);
expect(interpretedResponse[0].width).to.equal(nativeServerResponse.body.bids[0].width);
expect(interpretedResponse[0].height).to.equal(nativeServerResponse.body.bids[0].height);
expect(interpretedResponse[0].creativeId).to.equal(nativeServerResponse.body.bids[0].creativeId);
expect(interpretedResponse[0].currency).to.equal(nativeServerResponse.body.bids[0].currency);
expect(interpretedResponse[0].netRevenue).to.equal(nativeServerResponse.body.bids[0].netRevenue);
expect(interpretedResponse[0].ttl).to.equal(nativeServerResponse.body.bids[0].ttl);
expect(interpretedResponse[0].native).to.deep.equal(nativeServerResponse.body.bids[0].native);
expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal(nativeServerResponse.body.bids[0].meta.advertiserDomains[0]);
describe('nativeServerResponse', function () {
it('should return valid response when passed valid server response', function () {
const request = spec.buildRequests(nativeBidRequests, bidderRequest)[0];
const interpretedResponse = spec.interpretResponse(nativeServerResponse, request);

expect(interpretedResponse).to.have.lengthOf(1);
expect(interpretedResponse[0].cpm).to.equal(nativeServerResponse.body.bids[0].cpm);
expect(interpretedResponse[0].width).to.equal(nativeServerResponse.body.bids[0].width);
expect(interpretedResponse[0].height).to.equal(nativeServerResponse.body.bids[0].height);
expect(interpretedResponse[0].creativeId).to.equal(nativeServerResponse.body.bids[0].creativeId);
expect(interpretedResponse[0].currency).to.equal(nativeServerResponse.body.bids[0].currency);
expect(interpretedResponse[0].netRevenue).to.equal(nativeServerResponse.body.bids[0].netRevenue);
expect(interpretedResponse[0].ttl).to.equal(nativeServerResponse.body.bids[0].ttl);
expect(interpretedResponse[0].native).to.deep.equal(nativeServerResponse.body.bids[0].native);
expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal(nativeServerResponse.body.bids[0].meta.advertiserDomains[0]);
});
});

describe('bannerServerResponse', function () {
it('should return valid response when passed valid server response', function () {
const request = spec.buildRequests(bannerBidRequests, bidderRequest)[0];
const interpretedResponse = spec.interpretResponse(bannerServerResponse, request);

expect(interpretedResponse).to.have.lengthOf(1);
expect(interpretedResponse[0].cpm).to.equal(bannerServerResponse.body.bids[0].cpm);
expect(interpretedResponse[0].width).to.equal(bannerServerResponse.body.bids[0].width);
expect(interpretedResponse[0].height).to.equal(bannerServerResponse.body.bids[0].height);
expect(interpretedResponse[0].creativeId).to.equal(bannerServerResponse.body.bids[0].creativeId);
expect(interpretedResponse[0].currency).to.equal(bannerServerResponse.body.bids[0].currency);
expect(interpretedResponse[0].netRevenue).to.equal(bannerServerResponse.body.bids[0].netRevenue);
expect(interpretedResponse[0].ttl).to.equal(bannerServerResponse.body.bids[0].ttl);
expect(interpretedResponse[0].ad).to.equal(bannerServerResponse.body.bids[0].ad);
expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal(bannerServerResponse.body.bids[0].meta.advertiserDomains[0]);
});
});
});

Expand All @@ -161,12 +222,20 @@ describe('loglyliftBidAdapter', function () {
expect(userSync).to.be.an('array').that.is.empty;
});

it('When nativeServerResponses empty, no userSync should be returned', function () {
it('When serverResponses empty, no userSync should be returned', function () {
const syncOptions = {
'iframeEnabled': false
'iframeEnabled': true
}
let userSync = spec.getUserSyncs(syncOptions, []);
expect(userSync).to.be.an('array').that.is.empty;
});

it('When mediaType is banner, no userSync should be returned', function () {
const syncOptions = {
'iframeEnabled': true
}
let userSync = spec.getUserSyncs(syncOptions, [bannerServerResponse]);
expect(userSync).to.be.an('array').that.is.empty;
});
});
});

0 comments on commit 7d42e11

Please sign in to comment.