Skip to content

Commit

Permalink
Clear currency conversionCache after rate file has been downloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Caspervw committed Aug 30, 2022
1 parent ece711e commit 13a6663
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function initCurrency(url) {
try {
currencyRates = JSON.parse(response);
logInfo('currencyRates set to ' + JSON.stringify(currencyRates));
conversionCache = {};
currencyRatesLoaded = true;
processBidResponseQueue();
ready.done();
Expand Down
22 changes: 22 additions & 0 deletions test/spec/modules/currency_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@ describe('currency', function () {
expect(getGlobal().convertCurrency(1.0, 'USD', 'EUR')).to.equal(4);
expect(getGlobal().convertCurrency(1.0, 'USD', 'JPY')).to.equal(200);
});
it('uses default rates until currency file is loaded', function () {
setConfig({
adServerCurrency: 'USD',
defaultRates: {
USD: {
JPY: 100
}
}
});

// Race condition where a bid is converted before the file has been loaded
expect(getGlobal().convertCurrency(1.0, 'USD', 'JPY')).to.equal(100);

fakeCurrencyFileServer.respondWith(JSON.stringify({
'dataAsOf': '2017-04-25',
'conversions': {
'USD': { JPY: 200 }
}
}));
fakeCurrencyFileServer.respond();
expect(getGlobal().convertCurrency(1.0, 'USD', 'JPY')).to.equal(200);
});
});
describe('bidder override', function () {
it('allows setConfig to set bidder currency', function () {
Expand Down

0 comments on commit 13a6663

Please sign in to comment.