Files
medusa-store/integration-tests/modules/__tests__/promotion/admin/retrieve-promotion.spec.ts
T
Adrien de Peretti 48963f55ef Chore/rm main entity concept (#7709)
**What**
Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate.
This pr also includes various fixes in different modules

Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-06-19 13:02:16 +00:00

106 lines
3.1 KiB
TypeScript

import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPromotionModuleService } from "@medusajs/types"
import { PromotionType } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/promotions/:id", () => {
let appContainer
let promotionModuleService: IPromotionModuleService
beforeAll(async () => {
appContainer = getContainer()
promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION
)
})
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders, appContainer)
})
it("should throw an error if id does not exist", async () => {
const { response } = await api
.get(`/admin/promotions/does-not-exist`, adminHeaders)
.catch((e) => e)
expect(response.status).toEqual(404)
expect(response.data.message).toEqual(
"Promotion with id or code: does-not-exist was not found"
)
})
it("should get the requested promotion by id or codde", async () => {
const createdPromotion = await promotionModuleService.createPromotions({
code: "TEST",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "order",
value: "100",
currency_code: "USD",
},
})
let response = await api.get(
`/admin/promotions/${createdPromotion.id}`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.promotion).toEqual(
expect.objectContaining({
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,
})
)
})
it("should get the requested promotion with filtered fields and relations", async () => {
const createdPromotion = await promotionModuleService.createPromotions({
code: "TEST",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "order",
value: "100",
currency_code: "USD",
},
})
const response = await api.get(
`/admin/promotions/${createdPromotion.id}?fields=id,code`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.promotion).toEqual({
id: expect.any(String),
code: "TEST",
})
})
})
},
})