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

getCpmInNewCurrency to use current value of bid.cpm and bid.currency #3845

Merged
merged 2 commits into from
Jun 3, 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
5 changes: 1 addition & 4 deletions modules/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,9 @@ export function addBidResponseHook(fn, adUnitCode, bid) {
bid.currency = 'USD';
}

let fromCurrency = bid.currency;
let cpm = bid.cpm;

// used for analytics
bid.getCpmInNewCurrency = function(toCurrency) {
return (parseFloat(cpm) * getCurrencyConversion(fromCurrency, toCurrency)).toFixed(3);
return (parseFloat(this.cpm) * getCurrencyConversion(this.currency, toCurrency)).toFixed(3);
};

// execute immediately if the bid is already in the desired currency
Expand Down
28 changes: 28 additions & 0 deletions test/spec/modules/currency_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,34 @@ describe('currency', function () {
expect(innerBid.getCpmInNewCurrency('JPY')).to.equal('100.000');
});

it('uses rates specified in json when provided and consider boosted bid', function () {
setConfig({
adServerCurrency: 'USD',
rates: {
USD: {
JPY: 100
}
}
});

var bid = { cpm: 100, currency: 'JPY', bidder: 'rubicon' };
var innerBid;

addBidResponseHook(function(adCodeId, bid) {
innerBid = bid;
}, 'elementId', bid);

expect(innerBid.cpm).to.equal('1.0000');
expect(typeof innerBid.getCpmInNewCurrency).to.equal('function');
expect(innerBid.getCpmInNewCurrency('JPY')).to.equal('100.000');

// Boosting the bid now
innerBid.cpm *= 10;
expect(innerBid.cpm).to.equal(10.0000);
expect(typeof innerBid.getCpmInNewCurrency).to.equal('function');
expect(innerBid.getCpmInNewCurrency('JPY')).to.equal('1000.000');
});

it('uses default rates when currency file fails to load', function () {
setConfig({});

Expand Down