Skip to content

Commit

Permalink
tests(integration-tests): Allow null updates in discounts (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
pKorsholm authored Aug 21, 2022
1 parent 8c4be33 commit 448fd5b
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions integration-tests/api/__tests__/admin/discount.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,70 @@ describe("/admin/discounts", () => {
})
})

describe("POST /admin/discounts/:id", () => {
beforeEach(async () => {
await adminSeeder(dbConnection)
await dbConnection.manager.insert(DiscountRule, {
id: "test-discount-rule",
description: "Test discount rule",
type: "percentage",
value: 10,
allocation: "total",
})
await dbConnection.manager.insert(Discount, {
id: "test-discount",
code: "TESTING",
rule_id: "test-discount-rule",
is_dynamic: false,
is_disabled: false,
ends_at: new Date(),
usage_limit: 10,
valid_duration: "P1D",
})
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("Removes ends_at, valid_duration and usage_limit when fields are updated with null", async () => {
const api = useApi()

await api
.post(
"/admin/discounts/test-discount",
{
ends_at: null,
valid_duration: null,
usage_limit: null,
},
{
headers: {
Authorization: "Bearer test_token",
},
}
)
.catch((err) => {
console.log(err)
})

const resultingDiscount = await api.get(
"/admin/discounts/test-discount",
{ headers: { Authorization: "Bearer test_token" } }
)

expect(resultingDiscount.status).toEqual(200)
expect(resultingDiscount.data.discount).toEqual(
expect.objectContaining({
ends_at: null,
valid_duration: null,
usage_limit: null,
})
)
})
})

describe("testing for soft-deletion + uniqueness on discount codes", () => {
let manager
beforeEach(async () => {
Expand Down

0 comments on commit 448fd5b

Please sign in to comment.