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/addresses/:address_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 address", async () => {
32 const customer = await customerModuleService.createCustomers({
33 first_name: "John",
34 last_name: "Doe",
35 })
36
37 const address = await customerModuleService.createCustomerAddresses({
38 customer_id: customer.id,
39 first_name: "John",
40 last_name: "Doe",
41 address_1: "Test street 1",
42 })
43
44 const response = await api.delete(
45 `/admin/customers/${customer.id}/addresses/${address.id}`,
46 adminHeaders
47 )
48
49 expect(response.status).toEqual(200)
50
51 const updatedCustomer = await customerModuleService.retrieveCustomer(
52 customer.id,
53 {
54 relations: ["addresses"],
55 }
56 )
57
58 expect(updatedCustomer.addresses?.length).toEqual(0)
59 })
60 })
61 },
62 })