51bb6f1e89
new wrapper for medusa integration tests. for now it is only applied to the modules directory, but it could be used in the api integration tests or any other integrations that requires a db and a server up and running. It is not perfect, but I wanted to have something working and centralised before improving it, also avoiding too many conflicts with other prs
111 lines
3.3 KiB
TypeScript
111 lines
3.3 KiB
TypeScript
import { IPromotionModuleService } from "@medusajs/types"
|
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|
import { PromotionType } from "@medusajs/utils"
|
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
|
|
|
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", () => {
|
|
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: does-not-exist was not found"
|
|
)
|
|
})
|
|
|
|
it("should get the requested promotion", async () => {
|
|
const createdPromotion = await promotionModuleService.create({
|
|
code: "TEST",
|
|
type: PromotionType.STANDARD,
|
|
application_method: {
|
|
type: "fixed",
|
|
target_type: "order",
|
|
value: "100",
|
|
},
|
|
})
|
|
|
|
const response = await api.get(
|
|
`/admin/promotions/${createdPromotion.id}`,
|
|
adminHeaders
|
|
)
|
|
|
|
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",
|
|
max_quantity: 0,
|
|
allocation: null,
|
|
created_at: expect.any(String),
|
|
updated_at: expect.any(String),
|
|
deleted_at: null,
|
|
}),
|
|
})
|
|
)
|
|
})
|
|
|
|
it("should get the requested promotion with filtered fields and relations", async () => {
|
|
const createdPromotion = await promotionModuleService.create({
|
|
code: "TEST",
|
|
type: PromotionType.STANDARD,
|
|
application_method: {
|
|
type: "fixed",
|
|
target_type: "order",
|
|
value: "100",
|
|
},
|
|
})
|
|
|
|
const response = await api.get(
|
|
`/admin/promotions/${createdPromotion.id}?fields=id,code&expand=`,
|
|
adminHeaders
|
|
)
|
|
|
|
expect(response.status).toEqual(200)
|
|
expect(response.data.promotion).toEqual({
|
|
id: expect.any(String),
|
|
code: "TEST",
|
|
})
|
|
})
|
|
})
|
|
},
|
|
})
|