diff --git a/static/js/lib/ecommerce_test.js b/static/js/lib/ecommerce_test.js index c1ef26b16..235c9438d 100644 --- a/static/js/lib/ecommerce_test.js +++ b/static/js/lib/ecommerce_test.js @@ -8,6 +8,8 @@ import { makeItem, makeCouponSelection } from "../factories/ecommerce" import { calcSelectedRunIds, calculatePrice, + calculateTax, + calculateTotalAfterTax, formatPrice, formatRunTitle } from "./ecommerce" @@ -40,6 +42,46 @@ describe("ecommerce", () => { }) }) + describe("calculateTax", () => { + [ + ["100", "0", 20, "20"], + ["123", "1", 20, "0"], + ["200", "0.5", 20, "20"], + ].forEach(([price, discountAmount, taxRate, tax]) => { + it("calculates the tax of an item price", () => { + const item = { + ...makeItem(), + price: price + } + const coupon = { + ...makeCouponSelection(item), + amount: discountAmount + } + assert.equal(calculateTax(item, coupon, taxRate), tax) + }) + }) + }) + + describe("calculateTotalAfterTax", () => { + [ + ["100", "0", 20, "120"], + ["123", "1", 20, "0"], + ["200", "0.5", 20, "120"], + ].forEach(([price, discountAmount, taxRate, tax]) => { + it("calculates the total including the tax for an item", () => { + const item = { + ...makeItem(), + price: price + } + const coupon = { + ...makeCouponSelection(item), + amount: discountAmount + } + assert.equal(calculateTotalAfterTax(item, coupon, taxRate), tax) + }) + }) + }) + describe("formatPrice", () => { it("format price", () => { assert.equal(formatPrice(20), "$20")