Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…y-converter into pr/34
  • Loading branch information
paul-shuvo committed Nov 4, 2022
2 parents 528f30a + 00fd838 commit 65d0fff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ class CurrencyConverter {
}

addRateToRatesCache(currencyPair, rate_) {
if (typeof currencyPair != "string")
throw new TypeError("currency pair should be a string")

if (typeof rate_ != "number")
throw new TypeError("rate should be a number")

let now = new Date();
if (currencyPair in this.ratesCache) {
if (now > this.ratesCache[currencyPair].expiryDate) {
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ describe("currencyConverter", () => {
expect(() => currencyConverter.setupRatesCache(ratesCacheOptions)).to.throw(Error);
})
})

describe("addRateToRatesCache", () => {
it("should throw an error", () => {
let ratesCacheOptions = {
isRatesCaching: true,
ratesCacheDuration: 3600
}
currencyConverter.setupRatesCache(ratesCacheOptions);
expect(() => currencyConverter.addRateToRatesCache("USDCAD", "0.31")).to.throw(Error);
})

it("should throw an error", () => {
let ratesCacheOptions = {
isRatesCaching: true,
ratesCacheDuration: 3600
}
currencyConverter.setupRatesCache(ratesCacheOptions);
expect(() => currencyConverter.addRateToRatesCache(100, "0.31")).to.throw(Error);
})
})
})

// console.log(cf)
Expand Down

0 comments on commit 65d0fff

Please sign in to comment.