Example #1
0
export const _calculateDiscount = (
  price: Decimal,
  amountType: string,
  amount: Decimal
): Decimal => {
  let newPrice = price
  switch (amountType) {
  case COUPON_AMOUNT_TYPE_PERCENT_DISCOUNT:
    newPrice = price.times(Decimal("1").minus(amount))
    break
  case COUPON_AMOUNT_TYPE_FIXED_DISCOUNT:
    newPrice = price.minus(amount)
    break
  case COUPON_AMOUNT_TYPE_FIXED_PRICE:
    newPrice = amount
    break
  }
  if (newPrice.lessThan(0)) {
    newPrice = Decimal("0")
  }
  if (newPrice.greaterThan(price)) {
    newPrice = price
  }
  return newPrice
}
    it(`All defined currencies should be a positive number ${ExchangeRates[getSupportedCurrencyInfos()[key].code]} `, () => {
      var exchangeRate = new Decimal(ExchangeRates[getSupportedCurrencyInfos()[key].code])

      expect(exchangeRate.isPositive()).toBeTruthy()
      expect(ExchangeRates[getSupportedCurrencyInfos()[key].code]).toBeDefined()
    })