From 13a6663ce6fdcdddf2d230b249bf69415de95504 Mon Sep 17 00:00:00 2001 From: Caspervw Date: Tue, 30 Aug 2022 11:10:11 +0200 Subject: [PATCH] Clear currency conversionCache after rate file has been downloaded --- modules/currency.js | 1 + test/spec/modules/currency_spec.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/modules/currency.js b/modules/currency.js index 392817b5822..5b0f9af7afc 100644 --- a/modules/currency.js +++ b/modules/currency.js @@ -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(); diff --git a/test/spec/modules/currency_spec.js b/test/spec/modules/currency_spec.js index 928c252943c..6eb4f929a42 100644 --- a/test/spec/modules/currency_spec.js +++ b/test/spec/modules/currency_spec.js @@ -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 () {