From 448fd5b44e7899c624a03801f21c4c86c9f7ef6b Mon Sep 17 00:00:00 2001 From: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com> Date: Sun, 21 Aug 2022 17:54:30 +0700 Subject: [PATCH] tests(integration-tests): Allow null updates in discounts (#1299) --- .../api/__tests__/admin/discount.js | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/integration-tests/api/__tests__/admin/discount.js b/integration-tests/api/__tests__/admin/discount.js index 6135a7b687..5a83ec7a00 100644 --- a/integration-tests/api/__tests__/admin/discount.js +++ b/integration-tests/api/__tests__/admin/discount.js @@ -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 () => {