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("DELETE /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 delete a customer", async () => {
32 const customer = await customerModuleService.createCustomers({
33 first_name: "John",
34 last_name: "Doe",
35 })
36
37 const response = await api.delete(
38 `/admin/customers/${customer.id}`,
39 adminHeaders
40 )
41
42 expect(response.status).toEqual(200)
43
44 const deletedCustomer = await customerModuleService.retrieveCustomer(
45 customer.id,
46 {
47 withDeleted: true,
48 }
49 )
50 expect(deletedCustomer.deleted_at).toBeTruthy()
51 })
52 })
53 },
54 })