Skip to content

Commit

Permalink
fix: endpoint and testing skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
srindom committed Jan 24, 2024
1 parent efd155f commit 711a7ad
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"

const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}

describe("GET /admin/customer-groups", () => {
let dbConnection
let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})

beforeEach(async () => {
await adminSeeder(dbConnection)
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("should get all customer groups and its count", async () => {
await customerModuleService.createCustomerGroup({
name: "Test",
})

const api = useApi() as any
const response = await api.get(`/admin/customer-groups`, adminHeaders)

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.groups).toEqual([
expect.objectContaining({
id: expect.any(String),
name: "Test",
}),
])
})
})
4 changes: 4 additions & 0 deletions packages/medusa/src/api-v2/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { MiddlewaresConfig } from "../loaders/helpers/routing/types"
import { adminCampaignRoutesMiddlewares } from "./admin/campaigns/middlewares"
import { adminPromotionRoutesMiddlewares } from "./admin/promotions/middlewares"
import { adminCustomerRoutesMiddlewares } from "./admin/customers/middlewares"
import { adminCustomerGroupRoutesMiddlewares } from "./admin/customer-groups/middlewares"

export const config: MiddlewaresConfig = {
routes: [
...adminCustomerGroupRoutesMiddlewares,
...adminCustomerRoutesMiddlewares,
...adminPromotionRoutesMiddlewares,
...adminCampaignRoutesMiddlewares,
],
Expand Down

0 comments on commit 711a7ad

Please sign in to comment.