feat: list customer groups (#1099)

This commit is contained in:
Frane Polić
2022-03-02 11:38:44 +01:00
committed by GitHub
parent e844f4a5b7
commit a514d84ccf
11 changed files with 294 additions and 65 deletions

View File

@@ -466,6 +466,66 @@ describe("/admin/customer-groups", () => {
const db = useDb()
await db.teardown()
})
it("retreive a list of customer groups", async () => {
const api = useApi()
const response = await api
.get(
`/admin/customer-groups?limit=5&offset=2&expand=customers&order=created_at`,
{
headers: {
Authorization: "Bearer test_token",
},
}
)
.catch(console.log)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(7)
expect(response.data.customer_groups.length).toEqual(5)
expect(response.data.customer_groups[0]).toEqual(
expect.objectContaining({ id: "customer-group-3" })
)
expect(response.data.customer_groups[0]).toHaveProperty("customers")
})
it("retreive a list of customer groups filtered by name using `q` param", async () => {
const api = useApi()
const response = await api.get(`/admin/customer-groups?q=vip-customers`, {
headers: {
Authorization: "Bearer test_token",
},
})
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.customer_groups).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: "customer-group-1" }),
])
)
expect(response.data.customer_groups[0]).not.toHaveProperty("customers")
})
})
describe("GET /admin/customer-groups/:id", () => {
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("gets customer group", async () => {
const api = useApi()

View File

@@ -276,7 +276,10 @@ describe("/admin/customers", () => {
expect(response.status).toEqual(200)
expect(response.data.customer.groups).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: "test-group-4", name: "test-group-4" }),
expect.objectContaining({
id: "test-group-4",
name: "test-group-4",
}),
])
)
@@ -323,8 +326,11 @@ describe("/admin/customers", () => {
expect(response.data.customer.groups.length).toEqual(2)
expect(response.data.customer.groups).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: "test-group-4", name: "test-group-4" }),
expect.objectContaining({ id: "test-group-5", name: "test-group-5" }),
expect.objectContaining({
id: "test-group-4",
name: "test-group-4",
}),
])
)
})