feat: customer bulk endpoint form managing customer groups (#9761)
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
@@ -354,6 +354,68 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/customers/:id/customer-groups", () => {
|
||||
it("should batch add and remove customer to/from customer groups", async () => {
|
||||
const group1 = (
|
||||
await api.post(
|
||||
"/admin/customer-groups",
|
||||
{
|
||||
name: "VIP 1",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.customer_group
|
||||
|
||||
const group2 = (
|
||||
await api.post(
|
||||
"/admin/customer-groups",
|
||||
{
|
||||
name: "VIP 2",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.customer_group
|
||||
|
||||
const group3 = (
|
||||
await api.post(
|
||||
"/admin/customer-groups",
|
||||
{
|
||||
name: "VIP 3",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.customer_group
|
||||
|
||||
// Add with cg endpoint so we can test remove
|
||||
await api.post(
|
||||
`/admin/customer-groups/${group1.id}/customers`,
|
||||
{
|
||||
add: [customer1.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/customers/${customer1.id}/customer-groups?fields=groups.id`,
|
||||
{
|
||||
remove: [group1.id],
|
||||
add: [group2.id, group3.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.customer.groups.length).toEqual(2)
|
||||
expect(response.data.customer.groups).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: group2.id }),
|
||||
expect.objectContaining({ id: group3.id }),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /admin/customers/:id", () => {
|
||||
it("should fetch a customer", async () => {
|
||||
const response = await api.get(
|
||||
|
||||
Reference in New Issue
Block a user