feat: Admin V2 Customers (#6998)

This commit is contained in:
Oli Juhl
2024-04-07 21:38:50 +02:00
committed by GitHub
parent f132929c7e
commit 4f88743591
53 changed files with 619 additions and 724 deletions
@@ -1,17 +1,19 @@
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
const { medusaIntegrationTestRunner } = require("medusa-test-utils")
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
medusaIntegrationTestRunner({
env,
env: {
MEDUSA_FF_MEDUSA_V2: true,
},
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/customers", () => {
let appContainer
@@ -52,6 +54,45 @@ medusaIntegrationTestRunner({
])
})
it("should get all customers in specific customer group and its count", async () => {
const vipGroup = await customerModuleService.createCustomerGroup({
name: "VIP",
})
const [john] = await customerModuleService.create([
{
first_name: "John",
last_name: "Doe",
email: "john.doe@example.com",
},
{
first_name: "Jane",
last_name: "Smith",
email: "jane.smith@example.com",
},
])
await customerModuleService.addCustomerToGroup({
customer_id: john.id,
customer_group_id: vipGroup.id,
})
const response = await api.get(
`/admin/customers?limit=20&offset=0&groups%5B0%5D=${vipGroup.id}`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.customers).toEqual([
expect.objectContaining({
first_name: "John",
last_name: "Doe",
email: "john.doe@example.com",
}),
])
})
it("should filter customers by last name", async () => {
await customerModuleService.create([
{