Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
George Schneeloch committed May 20, 2019
1 parent e7206a9 commit ec4fbf7
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions static/js/containers/pages/CheckoutPage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,40 @@ describe("CheckoutPage", () => {
})
})

//
;[[true, false], [true, true], [false, false], [false, true]].forEach(
([hasValidProductId, hasValidCoupon]) => {
describe("mount", () => {
const productError = "product error",
couponError = "coupon error",
couponCode = "codeforcoupon",
productId = 12345
let couponPayload, productPayload

beforeEach(() => {
couponPayload = {
body: { coupons: [{ code: couponCode }] },
credentials: undefined,
headers: {
"X-CSRFTOKEN": null
}
}
productPayload = {
body: { items: [{ id: productId }] },
credentials: undefined,
headers: {
"X-CSRFTOKEN": null
}
}
})
;[
[true, false, couponError],
[true, true, null],
[false, false, productError],
[false, true, productError]
].forEach(([hasValidProductId, hasValidCoupon, expError]) => {
it(`updates the basket with a ${
hasValidProductId ? "" : "in"
}valid product id and a ${
hasValidCoupon ? "" : "in"
}valid coupon code from the query parameter`, async () => {
const couponCode = "codeforcoupon"
const productId = 12345
const couponPayload = {
body: { coupons: [{ code: couponCode }] },
credentials: undefined,
headers: {
"X-CSRFTOKEN": null
}
}
const productPayload = {
body: { items: [{ id: productId }] },
credentials: undefined,
headers: {
"X-CSRFTOKEN": null
}
}

if (!hasValidProductId) {
helper.handleRequestStub
.withArgs("/api/basket/", "PATCH", productPayload)
Expand Down Expand Up @@ -196,7 +205,7 @@ describe("CheckoutPage", () => {
}
)
// wait for componentDidMount to resolve
await wait(15)
await wait(0)
sinon.assert.calledWith(
helper.handleRequestStub,
"/api/basket/",
Expand All @@ -219,17 +228,10 @@ describe("CheckoutPage", () => {
)
}

assert.equal(
inner.state().errors,
!hasValidProductId
? "product error"
: !hasValidCoupon
? "coupon error"
: null
)
assert.equal(inner.state().errors, expError)
})
}
)
})
})

it("displays the coupon code", async () => {
const { inner } = await renderPage()
Expand Down

0 comments on commit ec4fbf7

Please sign in to comment.