feat(medusa,types,core-flows,utils): added delete endpoints for campaigns and promotions (#6152)

what:

adds delete endpoints for:
- campaigns (RESOLVES CORE-1686)
- promotions (RESOLVES CORE-1680)
This commit is contained in:
Riqwan Thamir
2024-01-22 13:06:49 +00:00
committed by GitHub
parent 76291823f4
commit 99045848fd
25 changed files with 699 additions and 84 deletions
@@ -0,0 +1,72 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPromotionModuleService } 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"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
describe("DELETE /admin/campaigns/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION
)
})
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 delete campaign successfully", async () => {
const [createdCampaign] = await promotionModuleService.createCampaigns([
{
name: "test",
campaign_identifier: "test",
starts_at: new Date("01/01/2024"),
ends_at: new Date("01/01/2025"),
},
])
const api = useApi() as any
const deleteRes = await api.delete(
`/admin/campaigns/${createdCampaign.id}`,
adminHeaders
)
expect(deleteRes.status).toEqual(200)
const campaigns = await promotionModuleService.listCampaigns({
id: [createdCampaign.id],
})
expect(campaigns.length).toEqual(0)
})
})
@@ -0,0 +1,73 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPromotionModuleService } 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"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
describe("DELETE /admin/promotions/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION
)
})
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 delete promotion successfully", async () => {
const createdPromotion = await promotionModuleService.create({
code: "TEST",
type: "standard",
application_method: {
type: "fixed",
target_type: "order",
value: "100",
},
})
const api = useApi() as any
const deleteRes = await api.delete(
`/admin/promotions/${createdPromotion.id}`,
adminHeaders
)
expect(deleteRes.status).toEqual(200)
const promotions = await promotionModuleService.list({
id: [createdPromotion.id],
})
expect(promotions.length).toEqual(0)
})
})