-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(customer): add remove from group, update group (#6158)
Open #6149 again - was merged to wrong base branch.
- Loading branch information
Showing
3 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,4 +409,81 @@ describe("Customer Module Service", () => { | |
expect(remainingCustomers.length).toBe(0) | ||
}) | ||
}) | ||
|
||
describe("removeCustomerFromGroup", () => { | ||
it("should remove a single customer from a group", async () => { | ||
// Creating a customer and a group | ||
const [customer] = await service.create([ | ||
{ first_name: "John", last_name: "Doe", email: "[email protected]" }, | ||
]) | ||
const [group] = await service.createCustomerGroup([{ name: "VIP" }]) | ||
|
||
// Adding the customer to the group | ||
await service.addCustomerToGroup({ | ||
customer_id: customer.id, | ||
customer_group_id: group.id, | ||
}) | ||
|
||
const [customerInGroup] = await service.list( | ||
{ id: customer.id }, | ||
{ relations: ["groups"] } | ||
) | ||
expect(customerInGroup.groups).toEqual([ | ||
expect.objectContaining({ id: group.id }), | ||
]) | ||
|
||
// Removing the customer from the group | ||
await service.removeCustomerFromGroup({ | ||
customer_id: customer.id, | ||
customer_group_id: group.id, | ||
}) | ||
|
||
const [updatedCustomer] = await service.list( | ||
{ id: customer.id }, | ||
{ relations: ["groups"] } | ||
) | ||
expect(updatedCustomer.groups).toEqual([]) | ||
}) | ||
|
||
it("should remove multiple customers from groups", async () => { | ||
// Creating multiple customers and groups | ||
const customers = await service.create([ | ||
{ first_name: "John", last_name: "Doe", email: "[email protected]" }, | ||
{ | ||
first_name: "Jane", | ||
last_name: "Smith", | ||
email: "[email protected]", | ||
}, | ||
]) | ||
const groups = await service.createCustomerGroup([ | ||
{ name: "VIP" }, | ||
{ name: "Regular" }, | ||
]) | ||
|
||
// Adding customers to groups | ||
const pairsToAdd = [ | ||
{ customer_id: customers[0].id, customer_group_id: groups[0].id }, | ||
{ customer_id: customers[1].id, customer_group_id: groups[1].id }, | ||
] | ||
await service.addCustomerToGroup(pairsToAdd) | ||
|
||
// Removing customers from groups | ||
const pairsToRemove = [ | ||
{ customer_id: customers[0].id, customer_group_id: groups[0].id }, | ||
{ customer_id: customers[1].id, customer_group_id: groups[1].id }, | ||
] | ||
await service.removeCustomerFromGroup(pairsToRemove) | ||
|
||
// Verification for each customer | ||
for (const pair of pairsToRemove) { | ||
const [updatedCustomer] = await service.list( | ||
{ id: pair.customer_id }, | ||
{ relations: ["groups"] } | ||
) | ||
expect(updatedCustomer.groups).not.toContainEqual( | ||
expect.objectContaining({ id: pair.customer_group_id }) | ||
) | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters