Merge pull request #1073 from medusajs/feat/get-customer-group
feat: get customer group
This commit is contained in:
@@ -85,4 +85,88 @@ describe("/admin/customer-groups", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /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("gets customer group", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const id = "customer-group-1"
|
||||
|
||||
const response = await api.get(`/admin/customer-groups/${id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.customerGroup).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "customer-group-1",
|
||||
name: "vip-customers",
|
||||
})
|
||||
)
|
||||
expect(response.data.customerGroup).not.toHaveProperty("customers")
|
||||
})
|
||||
|
||||
it("gets customer group with `customers` prop", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const id = "customer-group-1"
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/customer-groups/${id}?expand=customers`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.customerGroup).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "customer-group-1",
|
||||
name: "vip-customers",
|
||||
})
|
||||
)
|
||||
expect(response.data.customerGroup.customers).toEqual([])
|
||||
})
|
||||
|
||||
it("throws error when a customer group doesn't exist", async () => {
|
||||
expect.assertions(3)
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const id = "test-group-000"
|
||||
|
||||
await api
|
||||
.get(`/admin/customer-groups/${id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
expect(err.response.status).toEqual(404)
|
||||
expect(err.response.data.type).toEqual("not_found")
|
||||
expect(err.response.data.message).toEqual(
|
||||
`CustomerGroup with ${id} was not found`
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user