Skip to content

Commit

Permalink
myTargetBidAdapter: support currency config (#4188)
Browse files Browse the repository at this point in the history
  • Loading branch information
vfedoseev authored and Fawke committed Sep 16, 2019
1 parent e4cc081 commit 59532e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion modules/mytargetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ function getSiteName(referrer) {
return sitename;
}

function getCurrency() {
let currency = config.getConfig('currency.adServerCurrency');

return (currency === 'USD') ? currency : DEFAULT_CURRENCY;
}

function generateRandomId() {
return Math.random().toString(16).substring(2);
}
Expand All @@ -60,7 +66,7 @@ export const spec = {
page: referrer
},
settings: {
currency: DEFAULT_CURRENCY,
currency: getCurrency(),
windowSize: {
width: window.screen.width,
height: window.screen.height
Expand Down
30 changes: 30 additions & 0 deletions test/spec/modules/mytargetBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import { config } from 'src/config';
import { spec } from 'modules/mytargetBidAdapter';

describe('MyTarget Adapter', function() {
Expand Down Expand Up @@ -114,6 +115,35 @@ describe('MyTarget Adapter', function() {
expect(settings.windowSize.width).to.equal(window.screen.width);
expect(settings.windowSize.height).to.equal(window.screen.height);
});

it('should pass currency from currency.adServerCurrency', function() {
const configStub = sinon.stub(config, 'getConfig').callsFake(
key => key === 'currency.adServerCurrency' ? 'USD' : '');

let bidRequest = spec.buildRequests(bidRequests, bidderRequest);
let settings = bidRequest.data.settings;

expect(settings).to.be.an('object');
expect(settings.currency).to.equal('USD');
expect(settings.windowSize).to.be.an('object');
expect(settings.windowSize.width).to.equal(window.screen.width);
expect(settings.windowSize.height).to.equal(window.screen.height);

configStub.restore();
});

it('should ignore currency other than "RUB" or "USD"', function() {
const configStub = sinon.stub(config, 'getConfig').callsFake(
key => key === 'currency.adServerCurrency' ? 'EUR' : '');

let bidRequest = spec.buildRequests(bidRequests, bidderRequest);
let settings = bidRequest.data.settings;

expect(settings).to.be.an('object');
expect(settings.currency).to.equal('RUB');

configStub.restore();
});
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit 59532e4

Please sign in to comment.