From cda0c512cf75692022f95b5ac8d7732c682e28c0 Mon Sep 17 00:00:00 2001 From: oDestroyeRo <13649162+oDestroyeRo@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:19:54 +0700 Subject: [PATCH 1/3] fix: replace req.params.id with customerId in customer refetch --- packages/medusa/src/api/store/customers/me/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/medusa/src/api/store/customers/me/route.ts b/packages/medusa/src/api/store/customers/me/route.ts index d7488876fad68..40ba3357fcd13 100644 --- a/packages/medusa/src/api/store/customers/me/route.ts +++ b/packages/medusa/src/api/store/customers/me/route.ts @@ -46,7 +46,7 @@ export const POST = async ( }) const customer = await refetchCustomer( - req.params.id, + customerId, req.scope, req.remoteQueryConfig.fields ) From e012d37bac7ae9aad7b7d77a0e0ae41334fdecbd Mon Sep 17 00:00:00 2001 From: oDestroyeRo <13649162+oDestroyeRo@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:42:04 +0700 Subject: [PATCH 2/3] add unit test --- .../customer/store/update-customer.spec.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 integration-tests/modules/__tests__/customer/store/update-customer.spec.ts diff --git a/integration-tests/modules/__tests__/customer/store/update-customer.spec.ts b/integration-tests/modules/__tests__/customer/store/update-customer.spec.ts new file mode 100644 index 0000000000000..aea4cb96712da --- /dev/null +++ b/integration-tests/modules/__tests__/customer/store/update-customer.spec.ts @@ -0,0 +1,60 @@ +import { medusaIntegrationTestRunner } from "@medusajs/test-utils" +import { + generatePublishableKey, + generateStoreHeaders, +} from "../../../../helpers/create-admin-user" +import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" + +jest.setTimeout(50000) + +const env = { MEDUSA_FF_MEDUSA_V2: true } + +medusaIntegrationTestRunner({ + env, + testSuite: ({ dbConnection, getContainer, api }) => { + describe("POST /store/customers/me", () => { + let appContainer + let storeHeaders + + beforeAll(async () => { + appContainer = getContainer() + }) + + beforeEach(async () => { + const publishableKey = await generatePublishableKey(appContainer) + storeHeaders = generateStoreHeaders({ publishableKey }) + }) + + it("should update a customer", async () => { + const { customer, jwt } = await createAuthenticatedCustomer( + api, + storeHeaders + ) + + const response = await api.post( + `/store/customers/me`, + { + first_name: "John2", + last_name: "Doe2", + }, + { + headers: { + authorization: `Bearer ${jwt}`, + ...storeHeaders.headers, + }, + } + ) + + expect(response.status).toEqual(200) + expect(response.data.customer).toEqual( + expect.objectContaining({ + id: customer.id, + first_name: "John2", + last_name: "Doe2", + email: "tony@start.com", + }) + ) + }) + }) + }, +}) From 990d4e1571b503f5f99fcfea15e38a1956b856ff Mon Sep 17 00:00:00 2001 From: oDestroyeRo <13649162+oDestroyeRo@users.noreply.github.com> Date: Fri, 22 Nov 2024 21:34:39 +0700 Subject: [PATCH 3/3] chore: move unit test to test/http --- .../__tests__/customer/store/customer.spec.ts | 34 +++++++++++ .../customer/store/update-customer.spec.ts | 60 ------------------- 2 files changed, 34 insertions(+), 60 deletions(-) delete mode 100644 integration-tests/modules/__tests__/customer/store/update-customer.spec.ts diff --git a/integration-tests/http/__tests__/customer/store/customer.spec.ts b/integration-tests/http/__tests__/customer/store/customer.spec.ts index 4fade4635f749..1e94b32b9992c 100644 --- a/integration-tests/http/__tests__/customer/store/customer.spec.ts +++ b/integration-tests/http/__tests__/customer/store/customer.spec.ts @@ -6,6 +6,7 @@ import { generatePublishableKey, generateStoreHeaders, } from "../../../../helpers/create-admin-user" +import { createAuthenticatedCustomer } from "../../../../modules/helpers/create-authenticated-customer" jest.setTimeout(50000) @@ -265,5 +266,38 @@ medusaIntegrationTestRunner({ }) }) }) + + describe("POST /store/customers/me", () => { + it("should successfully update a customer", async () => { + const { customer, jwt } = await createAuthenticatedCustomer( + api, + storeHeaders + ) + + const response = await api.post( + `/store/customers/me`, + { + first_name: "John2", + last_name: "Doe2", + }, + { + headers: { + authorization: `Bearer ${jwt}`, + ...storeHeaders.headers, + }, + } + ) + + expect(response.status).toEqual(200) + expect(response.data).toEqual({ + customer: expect.objectContaining({ + id: customer.id, + first_name: "John2", + last_name: "Doe2", + email: "tony@start.com", + }), + }) + }) + }) }, }) diff --git a/integration-tests/modules/__tests__/customer/store/update-customer.spec.ts b/integration-tests/modules/__tests__/customer/store/update-customer.spec.ts deleted file mode 100644 index aea4cb96712da..0000000000000 --- a/integration-tests/modules/__tests__/customer/store/update-customer.spec.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { medusaIntegrationTestRunner } from "@medusajs/test-utils" -import { - generatePublishableKey, - generateStoreHeaders, -} from "../../../../helpers/create-admin-user" -import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" - -jest.setTimeout(50000) - -const env = { MEDUSA_FF_MEDUSA_V2: true } - -medusaIntegrationTestRunner({ - env, - testSuite: ({ dbConnection, getContainer, api }) => { - describe("POST /store/customers/me", () => { - let appContainer - let storeHeaders - - beforeAll(async () => { - appContainer = getContainer() - }) - - beforeEach(async () => { - const publishableKey = await generatePublishableKey(appContainer) - storeHeaders = generateStoreHeaders({ publishableKey }) - }) - - it("should update a customer", async () => { - const { customer, jwt } = await createAuthenticatedCustomer( - api, - storeHeaders - ) - - const response = await api.post( - `/store/customers/me`, - { - first_name: "John2", - last_name: "Doe2", - }, - { - headers: { - authorization: `Bearer ${jwt}`, - ...storeHeaders.headers, - }, - } - ) - - expect(response.status).toEqual(200) - expect(response.data.customer).toEqual( - expect.objectContaining({ - id: customer.id, - first_name: "John2", - last_name: "Doe2", - email: "tony@start.com", - }) - ) - }) - }) - }, -})