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

Fixing the issue introduced in #3845 for rubi analytics adapter #3996

Merged
merged 2 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions modules/rubiconAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,17 @@ function sendMessage(auctionId, bidWonId) {
);
}

function parseBidResponse(bid) {
export function parseBidResponse(bid) {
return _pick(bid, [
'getCpmInNewCurrency as bidPriceUSD', (fn) => {
'bidPriceUSD', () => {
if (typeof bid.currency === 'string' && bid.currency.toUpperCase() === 'USD') {
return Number(bid.cpm);
}
// use currency conversion function if present
if (typeof fn === 'function') {
return Number(fn('USD'));
if (typeof bid.getCpmInNewCurrency === 'function') {
return Number(bid.getCpmInNewCurrency('USD'));
}
// TODO: throw error or something if not USD and currency module wasn't present?
utils.logWarn('Rubicon Analytics Adapter: Could not determine the bidPriceUSD of the bid ', bid);
},
'dealId',
'status',
Expand Down
39 changes: 38 additions & 1 deletion test/spec/modules/rubiconAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import rubiconAnalyticsAdapter, { SEND_TIMEOUT } from 'modules/rubiconAnalyticsAdapter';
import rubiconAnalyticsAdapter, { SEND_TIMEOUT, parseBidResponse } from 'modules/rubiconAnalyticsAdapter';
import CONSTANTS from 'src/constants.json';
import { config } from 'src/config';

import {
setConfig,
addBidResponseHook,
} from 'modules/currency';

let Ajv = require('ajv');
let schema = require('./rubiconAnalyticsSchema.json');
let ajv = new Ajv({
allErrors: true
});

function clone(obj) {
idettman marked this conversation as resolved.
Show resolved Hide resolved
return JSON.parse(JSON.stringify(obj));
}

let validator = ajv.compile(schema);

function validate(message) {
Expand Down Expand Up @@ -694,5 +703,33 @@ describe('rubicon analytics adapter', function () {
expect(timedOutBid.error.code).to.equal('timeout-error');
expect(timedOutBid).to.not.have.property('bidResponse');
});

it('should successfully convert bid price to USD in parseBidResponse', function () {
// Set the rates
setConfig({
adServerCurrency: 'JPY',
rates: {
USD: {
JPY: 100
}
}
});

// set our bid response to JPY
const bidCopy = clone(BID2);
bidCopy.currency = 'JPY';
bidCopy.cpm = 100;

// Now add the bidResponse hook which hooks on the currenct conversion function onto the bid response
let innerBid;
addBidResponseHook(function(adCodeId, bid) {
innerBid = bid;
}, 'elementId', bidCopy);

// Use the rubi analytics parseBidResponse Function to get the resulting cpm from the bid response!
const bidResponseObj = parseBidResponse(innerBid);
expect(bidResponseObj).to.have.property('bidPriceUSD');
expect(bidResponseObj.bidPriceUSD).to.equal(1.0);
});
});
});