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/customer-groups/:id/customers", () => {
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 batch delete customers from a group", async () => {
32 const group = await customerModuleService.createCustomerGroups({
33 name: "VIP",
34 })
35 const customers = await customerModuleService.createCustomers([
36 {
37 first_name: "Test",
38 last_name: "Test",
39 },
40 {
41 first_name: "Test2",
42 last_name: "Test2",
43 },
44 {
45 first_name: "Test3",
46 last_name: "Test3",
47 },
48 ])
49
50 await customerModuleService.addCustomerToGroup(
51 customers.map((c) => ({
52 customer_id: c.id,
53 customer_group_id: group.id,
54 }))
55 )
56
57 const response = await api.post(
58 `/admin/customer-groups/${group.id}/customers`,
59 {
60 remove: customers.map((c) => c.id),
61 },
62 adminHeaders
63 )
64
65 expect(response.status).toEqual(200)
66
67 const updatedGroup = await customerModuleService.retrieveCustomerGroup(
68 group.id,
69 {
70 relations: ["customers"],
71 }
72 )
73 expect(updatedGroup.customers?.length).toEqual(0)
74 })
75 })
76 },
77 })