From 24306f3c9d25058c7df0137829dfd85fa9dbe42d Mon Sep 17 00:00:00 2001 From: Solta Date: Tue, 22 Oct 2024 16:12:23 +0300 Subject: [PATCH] Kimberlite Bidder Adapter: expand auction price & currency macros (#12325) * Expand price & currency macro * lint fix --------- Co-authored-by: Oleg Stolonogov --- modules/kimberliteBidAdapter.js | 16 +- .../spec/modules/kimberliteBidAdapter_spec.js | 187 ++++++++++-------- 2 files changed, 117 insertions(+), 86 deletions(-) diff --git a/modules/kimberliteBidAdapter.js b/modules/kimberliteBidAdapter.js index 6ad8b9eda05..fbb9974d52d 100644 --- a/modules/kimberliteBidAdapter.js +++ b/modules/kimberliteBidAdapter.js @@ -1,7 +1,7 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { ortbConverter } from '../libraries/ortbConverter/converter.js' -import { deepSetValue } from '../src/utils.js'; +import { deepSetValue, replaceMacros } from '../src/utils.js'; import {ORTB_MTYPES} from '../libraries/ortbConverter/processors/mediaType.js'; const VERSION = '1.1.0'; @@ -45,6 +45,12 @@ const converter = ortbConverter({ context.mediaType = type; } + bid.adm = expandAuctionMacros(bid.adm, bid.price, context.ortbResponse.cur); + + if (bid.nurl && bid.nurl != '') { + bid.nurl = expandAuctionMacros(bid.nurl, bid.price, context.ortbResponse.cur); + } + const bidResponse = buildBidResponse(bid, context); return bidResponse; }, @@ -85,4 +91,12 @@ export const spec = { } }; +export function expandAuctionMacros(str, price, currency) { + if (!str) return; + + const defaultCurrency = 'RUB'; + + return replaceMacros(str, {AUCTION_PRICE: price, AUCTION_CURRENCY: currency || defaultCurrency}); +}; + registerBidder(spec); diff --git a/test/spec/modules/kimberliteBidAdapter_spec.js b/test/spec/modules/kimberliteBidAdapter_spec.js index c0394a2090b..739a970603c 100644 --- a/test/spec/modules/kimberliteBidAdapter_spec.js +++ b/test/spec/modules/kimberliteBidAdapter_spec.js @@ -1,4 +1,4 @@ -import { spec, ENDPOINT_URL } from 'modules/kimberliteBidAdapter.js'; +import { spec, ENDPOINT_URL, expandAuctionMacros } from 'modules/kimberliteBidAdapter.js'; import { assert } from 'chai'; import { BANNER, VIDEO } from '../../../src/mediaTypes.js'; @@ -144,100 +144,117 @@ describe('kimberliteBidAdapter', function () { let bidderResponse, bidderRequest, bidRequest, expectedBids; const requestId = '07fba8b0-8812-4dc6-b91e-4a525d81729c'; - const bannerAdm = 'landing'; - const videoAdm = 'test vast'; + const bannerAdm = 'landing'; + const videoAdm = 'http://video-test.landing.com?p=${AUCTION_PRICE}&c=${AUCTION_CURRENCY}test vast'; + const nurl = 'http://nurl.landing.com?p=${AUCTION_PRICE}&c=${AUCTION_CURRENCY}'; + const nurlPixel = `
`; + + const currencies = [ + undefined, + 'USD' + ]; + + currencies.forEach(function(currency) { + beforeEach(function () { + bidderResponse = { + body: { + id: requestId, + seatbid: [{ + bid: [ + { + crid: 1, + impid: 1, + price: 1, + adm: bannerAdm, + nurl: nurl + }, + { + crid: 2, + impid: 2, + price: 1, + adm: videoAdm + } + ] + }] + } + }; - beforeEach(function () { - bidderResponse = { - body: { - id: requestId, - seatbid: [{ - bid: [ - { - crid: 1, - impid: 1, - price: 1, - adm: bannerAdm + bidderRequest = { + refererInfo: { + domain: 'example.com', + page: 'https://www.example.com/test.html', + }, + bids: [ + { + bidId: 1, + mediaTypes: { + banner: {sizes: sizes} }, - { - crid: 2, - impid: 2, - price: 1, - adm: videoAdm + params: { + placementId: 'test-placement' } - ] - }] - } - }; - - bidderRequest = { - refererInfo: { - domain: 'example.com', - page: 'https://www.example.com/test.html', - }, - bids: [ - { - bidId: 1, - mediaTypes: { - banner: {sizes: sizes} }, - params: { - placementId: 'test-placement' - } - }, - { - bidId: 2, - mediaTypes: { - video: { - mimes: ['video/mp4'] + { + bidId: 2, + mediaTypes: { + video: { + mimes: ['video/mp4'] + } + }, + params: { + placementId: 'test-placement' } - }, - params: { - placementId: 'test-placement' } - } - ] - }; + ] + }; - expectedBids = [ - { - mediaType: 'banner', - requestId: 1, - cpm: 1, - creative_id: 1, - creativeId: 1, - ttl: 300, - netRevenue: true, - ad: bannerAdm, - meta: {} - }, - { - mediaType: 'video', - requestId: 2, - cpm: 1, - creative_id: 2, - creativeId: 2, - ttl: 300, - netRevenue: true, - vastXml: videoAdm, - meta: {} - }, - ]; + expectedBids = [ + { + mediaType: 'banner', + requestId: 1, + cpm: 1, + creative_id: 1, + creativeId: 1, + ttl: 300, + netRevenue: true, + ad: bannerAdm + nurlPixel, + meta: {} + }, + { + mediaType: 'video', + requestId: 2, + cpm: 1, + creative_id: 2, + creativeId: 2, + ttl: 300, + netRevenue: true, + vastXml: videoAdm, + meta: {} + }, + ]; - bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - }); + if (currency) { + expectedBids[0].currency = expectedBids[1].currency = bidderResponse.body.cur = currency; + } - it('pass on valid request', function () { - const bids = spec.interpretResponse(bidderResponse, bidRequest); - assert.deepEqual(bids[0], expectedBids[0]); - if (FEATURES.VIDEO) { - assert.deepEqual(bids[1], expectedBids[1]); - } - }); + bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); + }); + + it('pass on valid request', function () { + const bids = spec.interpretResponse(bidderResponse, bidRequest); + expectedBids[0].ad = expandAuctionMacros(expectedBids[0].ad, expectedBids[0].cpm, bidderResponse.body.cur); + assert.deepEqual(bids[0], expectedBids[0]); + if (FEATURES.VIDEO) { + expectedBids[1].vastXml = + expandAuctionMacros(expectedBids[1].vastXml, expectedBids[1].cpm, bidderResponse.body.cur); + assert.deepEqual(bids[1], expectedBids[1]); + } + }); - it('fails on empty response', function () { - const bids = spec.interpretResponse({body: ''}, bidRequest); - assert.empty(bids); + it('fails on empty response', function () { + const bids = spec.interpretResponse({body: ''}, bidRequest); + assert.empty(bids); + }); }); }); });