Skip to content

Commit

Permalink
A1media Bid Adpater: resolve AUCTION_PRICE macro (#10624)
Browse files Browse the repository at this point in the history
Co-authored-by: ChangsikChoi <>
  • Loading branch information
ChangsikChoi authored Oct 27, 2023
1 parent 0a18cdc commit fabbbf1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
17 changes: 16 additions & 1 deletion modules/a1MediaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
import { replaceAuctionPrice } from '../src/utils.js';

const BIDDER_CODE = 'a1media';
const END_POINT = 'https://d11.contentsfeed.com/dsp/breq/a1';
Expand Down Expand Up @@ -81,7 +82,21 @@ export const spec = {
},

interpretResponse: function (serverResponse, bidRequest) {
const bids = converter.fromORTB({response: serverResponse.body, request: bidRequest.data}).bids;
if (!serverResponse.body) return [];
const parsedSeatbid = serverResponse.body.seatbid.map(seatbidItem => {
const parsedBid = seatbidItem.bid.map((bidItem) => ({
...bidItem,
adm: replaceAuctionPrice(bidItem.adm, bidItem.price),
nurl: replaceAuctionPrice(bidItem.nurl, bidItem.price)
}));
return {...seatbidItem, bid: parsedBid};
});

const responseBody = {...serverResponse.body, seatbid: parsedSeatbid};
const bids = converter.fromORTB({
response: responseBody,
request: bidRequest.data,
}).bids;
return bids;
},

Expand Down
28 changes: 28 additions & 0 deletions test/spec/modules/a1MediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { config } from 'src/config.js';
import { BANNER, VIDEO, NATIVE } from 'src/mediaTypes.js';
import 'modules/currency.js';
import 'modules/priceFloors.js';
import { replaceAuctionPrice } from '../../../src/utils';

const ortbBlockParams = {
battr: [ 13 ],
Expand Down Expand Up @@ -102,6 +103,9 @@ const getBidderResponse = () => {
const bannerAdm = '<div><img src="test_src" /></div>';
const videoAdm = '<VAST version="3.0">testvast1</VAST>';
const nativeAdm = '{"ver":"1.2","link":{"url":"test_url"},"assets":[{"id":1,"required":1,"title":{"text":"native_title"}}]}';
const macroAdm = '<div><img src="http://d11.contentsfeed.com/pixel/${AUCTION_PRICE}" /></div>';
const macroNurl = 'https://d11.contentsfeed.com/dsp/win/example.com/SITE/a1/${AUCTION_PRICE}';
const interpretedNurl = `<div style="position:absolute;left:0px;top:0px;visibility:hidden;"><img src="${macroNurl}"></div>`;

describe('a1MediaBidAdapter', function() {
describe('isValidRequest', function() {
Expand Down Expand Up @@ -216,5 +220,29 @@ describe('a1MediaBidAdapter', function() {
expect(interpretedRes[0].mediaType).equal(BANNER);
});
});

describe('resolve the AUCTION_PRICE macro', function() {
let bidRequest;
beforeEach(function() {
const bidderRequest = getBidderRequest(true);
bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest);
});
it('should return empty array when bid response has not contents', function() {
const emptyResponse = { body: '' };
const interpretedRes = spec.interpretResponse(emptyResponse, bidRequest);
expect(interpretedRes.length).equal(0);
});
it('should replace macro keyword if is exist', function() {
const bidderResponse = getBidderResponse();
bidderResponse.body.seatbid[0].bid[0].adm = macroAdm;
bidderResponse.body.seatbid[0].bid[0].nurl = macroNurl;
const interpretedRes = spec.interpretResponse(bidderResponse, bidRequest);

const expectedResPrice = 9;
const expectedAd = replaceAuctionPrice(macroAdm, expectedResPrice) + replaceAuctionPrice(interpretedNurl, expectedResPrice);

expect(interpretedRes[0].ad).equal(expectedAd);
});
});
});
})

0 comments on commit fabbbf1

Please sign in to comment.