feat(medusa,types): GET admin promotion endpoint to fetch by code (#6697)

what:

- GET admin promotion endpoint will search for a promotion either through ID or code
This commit is contained in:
Riqwan Thamir
2024-03-14 16:13:53 +01:00
committed by GitHub
parent c3f8c30ba6
commit 1a661adf3e
4 changed files with 53 additions and 36 deletions

View File

@@ -14,7 +14,7 @@ const adminHeaders = {
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/promotions", () => {
describe("GET /admin/promotions/:id", () => {
let appContainer
let promotionModuleService: IPromotionModuleService
@@ -36,11 +36,11 @@ medusaIntegrationTestRunner({
expect(response.status).toEqual(404)
expect(response.data.message).toEqual(
"Promotion with id: does-not-exist was not found"
"Promotion with id or code: does-not-exist was not found"
)
})
it("should get the requested promotion", async () => {
it("should get the requested promotion by id or codde", async () => {
const createdPromotion = await promotionModuleService.create({
code: "TEST",
type: PromotionType.STANDARD,
@@ -51,7 +51,7 @@ medusaIntegrationTestRunner({
},
})
const response = await api.get(
let response = await api.get(
`/admin/promotions/${createdPromotion.id}`,
adminHeaders
)
@@ -59,22 +59,19 @@ medusaIntegrationTestRunner({
expect(response.status).toEqual(200)
expect(response.data.promotion).toEqual(
expect.objectContaining({
id: expect.any(String),
code: "TEST",
campaign: null,
is_automatic: false,
type: "standard",
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
application_method: expect.objectContaining({
id: expect.any(String),
promotion: expect.any(Object),
value: 100,
type: "fixed",
target_type: "order",
allocation: null,
}),
id: createdPromotion.id,
})
)
response = await api.get(
`/admin/promotions/${createdPromotion.code}`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.promotion).toEqual(
expect.objectContaining({
id: createdPromotion.id,
})
)
})