From cc261a97d986902391155bc07c44799a0b296428 Mon Sep 17 00:00:00 2001 From: olivermrbl Date: Wed, 29 Nov 2023 14:12:02 +0000 Subject: [PATCH] fix startegy tests --- integration-tests/api/__tests__/store/cart/cart.js | 2 +- integration-tests/api/__tests__/store/orders.js | 8 ++++---- .../src/strategies/__tests__/cart-completion.js | 14 ++++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/integration-tests/api/__tests__/store/cart/cart.js b/integration-tests/api/__tests__/store/cart/cart.js index 3b07d62389aae..fe7dda9dac7df 100644 --- a/integration-tests/api/__tests__/store/cart/cart.js +++ b/integration-tests/api/__tests__/store/cart/cart.js @@ -49,7 +49,7 @@ describe("/store/carts", () => { beforeAll(async () => { const cwd = path.resolve(path.join(__dirname, "..", "..", "..")) dbConnection = await initDb({ cwd }) - medusaProcess = await setupServer({ cwd, verbose: true }) + medusaProcess = await setupServer({ cwd }) }) afterAll(async () => { diff --git a/integration-tests/api/__tests__/store/orders.js b/integration-tests/api/__tests__/store/orders.js index c41f3cd24c0db..c69674dee0a3b 100644 --- a/integration-tests/api/__tests__/store/orders.js +++ b/integration-tests/api/__tests__/store/orders.js @@ -501,20 +501,20 @@ describe("/store/carts", () => { }) ) - const responseFail = await api + const successRes = await api .post(`/store/carts/${cartId}/complete`) .catch((err) => { return err.response }) - expect(responseFail.status).toEqual(200) - expect(responseFail.data.data).toEqual( + expect(successRes.status).toEqual(200) + expect(successRes.data.data).toEqual( expect.objectContaining({ cart_id: cartId, id: expect.any(String), }) ) - expect(responseFail.data.type).toEqual("order") + expect(successRes.data.type).toEqual("order") }) }) diff --git a/packages/medusa/src/strategies/__tests__/cart-completion.js b/packages/medusa/src/strategies/__tests__/cart-completion.js index bd6bcfccc0fd5..ebfacc2653483 100644 --- a/packages/medusa/src/strategies/__tests__/cart-completion.js +++ b/packages/medusa/src/strategies/__tests__/cart-completion.js @@ -104,11 +104,16 @@ const toTest = [ idempotency_key: "ikey", recovery_point: "started", }, - validate: function (value) { + validate: function (value, { orderServiceMock }) { expect(value.response_code).toEqual(200) - expect(value.response_body.data).toEqual( - expect.objectContaining({ id: "test-cart" }) - ) + expect( + orderServiceMock.retrieveByCartIdWithTotals + ).toHaveBeenCalledTimes(1) + expect( + orderServiceMock.retrieveByCartIdWithTotals + ).toHaveBeenCalledWith("test-cart", { + relations: ["shipping_address", "items", "payments"], + }) }, }, ], @@ -202,6 +207,7 @@ describe("CartCompletionStrategy", () => { createFromCart: jest.fn(() => Promise.resolve(cart)), retrieve: jest.fn(() => Promise.resolve({})), retrieveWithTotals: jest.fn(() => Promise.resolve({})), + retrieveByCartIdWithTotals: jest.fn(() => Promise.resolve({})), newTotalsService: newTotalsServiceMock, } const swapServiceMock = {