Feat: Delete customer group (#1102)
This commit is contained in:
@@ -86,6 +86,113 @@ describe("/admin/customer-groups", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("DELETE /admin/customer-groups", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await customerSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("removes customer group from get endpoint", async () => {
|
||||
expect.assertions(3)
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const id = "customer-group-1"
|
||||
|
||||
const deleteResponse = await api.delete(`/admin/customer-groups/${id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
|
||||
expect(deleteResponse.data).toEqual({
|
||||
id: id,
|
||||
object: "customer_group",
|
||||
deleted: true,
|
||||
})
|
||||
|
||||
await api
|
||||
.get(`/admin/customer-groups/${id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((error) => {
|
||||
expect(error.response.data.type).toEqual("not_found")
|
||||
expect(error.response.data.message).toEqual(
|
||||
`CustomerGroup with ${id} was not found`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("removes customer group from customer upon deletion", async () => {
|
||||
expect.assertions(3)
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const id = "test-group-delete"
|
||||
|
||||
const customerRes_preDeletion = await api.get(
|
||||
`/admin/customers/test-customer-delete-cg?expand=groups`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(customerRes_preDeletion.data.customer).toEqual(
|
||||
expect.objectContaining({
|
||||
groups: [
|
||||
expect.objectContaining({
|
||||
id: "test-group-delete",
|
||||
name: "test-group-delete",
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
|
||||
const deleteResponse = await api
|
||||
.delete(`/admin/customer-groups/${id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(deleteResponse.data).toEqual({
|
||||
id: id,
|
||||
object: "customer_group",
|
||||
deleted: true,
|
||||
})
|
||||
|
||||
const customerRes = await api.get(
|
||||
`/admin/customers/test-customer-delete-cg?expand=groups`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(customerRes.data.customer).toEqual(
|
||||
expect.objectContaining({
|
||||
groups: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /admin/customer-groups", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
|
||||
@@ -56,7 +56,7 @@ describe("/admin/customers", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(5)
|
||||
expect(response.data.count).toEqual(6)
|
||||
expect(response.data.customers).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -42,6 +42,11 @@ module.exports = async (connection, data = {}) => {
|
||||
groups: [{ id: "test-group-5", name: "test-group-5" }],
|
||||
})
|
||||
|
||||
const deletionCustomer = await manager.create(Customer, {
|
||||
id: "test-customer-delete-cg",
|
||||
email: "test-deletetion-cg@email.com",
|
||||
})
|
||||
|
||||
await manager.insert(CustomerGroup, {
|
||||
id: "customer-group-1",
|
||||
name: "vip-customers",
|
||||
@@ -56,4 +61,12 @@ module.exports = async (connection, data = {}) => {
|
||||
id: "test-group-5",
|
||||
name: "test-group-5",
|
||||
})
|
||||
|
||||
const c_group_delete = manager.create(CustomerGroup, {
|
||||
id: "test-group-delete",
|
||||
name: "test-group-delete",
|
||||
})
|
||||
|
||||
deletionCustomer.groups = [c_group_delete]
|
||||
await manager.save(deletionCustomer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user