Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: adds frontend tests for the taxes #2779

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions static/js/lib/ecommerce_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { makeItem, makeCouponSelection } from "../factories/ecommerce"
import {
calcSelectedRunIds,
calculatePrice,
calculateTax,
calculateTotalAfterTax,
formatPrice,
formatRunTitle
} from "./ecommerce"
Expand Down Expand Up @@ -40,6 +42,82 @@ describe("ecommerce", () => {
})
})

describe("calculateTax", () => {
it("calculates the tax of an item", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: There are 3 similar tests below. Could you convert those into a single parameterized test? It should take price, coupon value, tax, and expected amount in the params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be resolved in b3070a7

const item = {
...makeItem(),
price: "100"
}
const coupon = {
...makeCouponSelection(item),
amount: "0"
}
assert.equal(calculateTax(item, coupon, 20), 20)
})

it("calculates the tax of an item including the 100% off coupon", () => {
const item = {
...makeItem(),
price: "123"
}
const coupon = {
...makeCouponSelection(item),
amount: "1"
}
assert.equal(calculateTax(item, coupon, 20), 0)
})

it("calculates the tax of an item including the 50% off coupon", () => {
const item = {
...makeItem(),
price: "200"
}
const coupon = {
...makeCouponSelection(item),
amount: "0.5"
}
assert.equal(calculateTax(item, coupon, 20), 20)
})
})

describe("calculateTotalAfterTax", () => {
it("calculates the total including the tax for an item", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get resolved in b3070a7

const item = {
...makeItem(),
price: "100"
}
const coupon = {
...makeCouponSelection(item),
amount: "0"
}
assert.equal(calculateTotalAfterTax(item, coupon, 20), 120)
})

it("calculates the total including tax for an item including the 100% off coupon", () => {
const item = {
...makeItem(),
price: "123"
}
const coupon = {
...makeCouponSelection(item),
amount: "1"
}
assert.equal(calculateTotalAfterTax(item, coupon, 20), 0)
})

it("calculates the total including tax for an item including the 50% off coupon", () => {
const item = {
...makeItem(),
price: "200"
}
const coupon = {
...makeCouponSelection(item),
amount: "0.5"
}
assert.equal(calculateTotalAfterTax(item, coupon, 20), 120)
})
})

describe("formatPrice", () => {
it("format price", () => {
assert.equal(formatPrice(20), "$20")
Expand Down
Loading