Feat: Add groups to list customer (#1113)
* add controllers directory and loaders * update integration tests * start groups * move controllers to pure functions * group filtering for customers * print errors * remove verbose flag * controller refactor * update imports * Feat/list customers by customer group (#1114) * move controllers to pure functions * add customer group test * add api for list customer group customers * remove unused imports * controller refactor * update imports * Update packages/medusa/src/api/routes/admin/customer-groups/get-customer-group-customers.ts Co-authored-by: Sebastian Rindom <skrindom@gmail.com> Co-authored-by: Sebastian Rindom <skrindom@gmail.com> * fix: dedupe Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
This commit is contained in:
@@ -193,6 +193,53 @@ describe("/admin/customer-groups", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /admin/customer-groups/{id}/customers", () => {
|
||||
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("lists customers in group and count", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/customer-groups/test-group-5/customers", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(3)
|
||||
expect(response.data.customers).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-customer-5",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-customer-6",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-customer-7",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/customer-groups/{id}/customers/batch", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
|
||||
@@ -75,6 +75,36 @@ describe("/admin/customers", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("lists customers in group and count", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/customers?groups[]=test-group-5", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(3)
|
||||
expect(response.data.customers).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-customer-5",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-customer-6",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-customer-7",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("lists customers with specific query", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user