1 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
2 import { ICustomerModuleService } from "@medusajs/types"
3 import { Modules } from "@medusajs/utils"
4 import { createAdminUser } from "../../../../helpers/create-admin-user"
5
6 jest.setTimeout(50000)
7
8 const env = {}
9 const adminHeaders = {
10 headers: { "x-medusa-access-token": "test_token" },
11 }
12
13 medusaIntegrationTestRunner({
14 env,
15 testSuite: ({ dbConnection, getContainer, api, dbUtils }) => {
16 describe("POST /admin/customers/:id", () => {
17 let appContainer
18 let customerModuleService: ICustomerModuleService
19
20 beforeAll(async () => {
21 appContainer = getContainer()
22 customerModuleService = appContainer.resolve(Modules.CUSTOMER)
23 })
24
25 beforeAll(async () => {
26 await createAdminUser(dbConnection, adminHeaders, appContainer)
27
28 await dbUtils.snapshot()
29 })
30
31 it("should update a customer", async () => {
32 const customer = await customerModuleService.createCustomers({
33 first_name: "John",
34 last_name: "Doe",
35 })
36
37 const response = await api.post(
38 `/admin/customers/${customer.id}`,
39 {
40 first_name: "Jane",
41 },
42 adminHeaders
43 )
44
45 expect(response.status).toEqual(200)
46 expect(response.data.customer).toEqual(
47 expect.objectContaining({
48 id: expect.any(String),
49 first_name: "Jane",
50 last_name: "Doe",
51 })
52 )
53 })
54 })
55 },
56 })