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:
+59
-9
@@ -385,20 +385,70 @@ describe("Promotion Module Service: Campaigns", () => {
|
||||
})
|
||||
|
||||
describe("deleteCampaigns", () => {
|
||||
beforeEach(async () => {
|
||||
await createCampaigns(repositoryManager)
|
||||
})
|
||||
|
||||
const id = "campaign-id-1"
|
||||
|
||||
it("should delete the campaigns given an id successfully", async () => {
|
||||
await service.deleteCampaigns([id])
|
||||
const [createdCampaign] = await service.createCampaigns([
|
||||
{
|
||||
name: "test",
|
||||
campaign_identifier: "test",
|
||||
starts_at: new Date("01/01/2024"),
|
||||
ends_at: new Date("01/01/2025"),
|
||||
},
|
||||
])
|
||||
|
||||
const campaigns = await service.list({
|
||||
id: [id],
|
||||
await service.deleteCampaigns([createdCampaign.id])
|
||||
|
||||
const campaigns = await service.listCampaigns(
|
||||
{
|
||||
id: [createdCampaign.id],
|
||||
},
|
||||
{ withDeleted: true }
|
||||
)
|
||||
|
||||
expect(campaigns).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("softDeleteCampaigns", () => {
|
||||
it("should soft delete the campaigns given an id successfully", async () => {
|
||||
const [createdCampaign] = await service.createCampaigns([
|
||||
{
|
||||
name: "test",
|
||||
campaign_identifier: "test",
|
||||
starts_at: new Date("01/01/2024"),
|
||||
ends_at: new Date("01/01/2025"),
|
||||
},
|
||||
])
|
||||
|
||||
await service.softDeleteCampaigns([createdCampaign.id])
|
||||
|
||||
const campaigns = await service.listCampaigns({
|
||||
id: [createdCampaign.id],
|
||||
})
|
||||
|
||||
expect(campaigns).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("restoreCampaigns", () => {
|
||||
it("should restore the campaigns given an id successfully", async () => {
|
||||
const [createdCampaign] = await service.createCampaigns([
|
||||
{
|
||||
name: "test",
|
||||
campaign_identifier: "test",
|
||||
starts_at: new Date("01/01/2024"),
|
||||
ends_at: new Date("01/01/2025"),
|
||||
},
|
||||
])
|
||||
|
||||
await service.softDeleteCampaigns([createdCampaign.id])
|
||||
|
||||
let campaigns = await service.listCampaigns({ id: [createdCampaign.id] })
|
||||
|
||||
expect(campaigns).toHaveLength(0)
|
||||
await service.restoreCampaigns([createdCampaign.id])
|
||||
|
||||
campaigns = await service.listCampaigns({ id: [createdCampaign.id] })
|
||||
expect(campaigns).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+44
-6
@@ -762,23 +762,61 @@ describe("Promotion Service", () => {
|
||||
})
|
||||
|
||||
describe("delete", () => {
|
||||
beforeEach(async () => {
|
||||
await createPromotions(repositoryManager)
|
||||
it("should soft delete the promotions given an id successfully", async () => {
|
||||
const createdPromotion = await service.create({
|
||||
code: "TEST",
|
||||
type: "standard",
|
||||
})
|
||||
|
||||
await service.delete([createdPromotion.id])
|
||||
|
||||
const promotions = await service.list(
|
||||
{
|
||||
id: [createdPromotion.id],
|
||||
},
|
||||
{ withDeleted: true }
|
||||
)
|
||||
|
||||
expect(promotions).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
const id = "promotion-id-1"
|
||||
describe("softDelete", () => {
|
||||
it("should soft delete the promotions given an id successfully", async () => {
|
||||
const createdPromotion = await service.create({
|
||||
code: "TEST",
|
||||
type: "standard",
|
||||
})
|
||||
|
||||
it("should delete the promotions given an id successfully", async () => {
|
||||
await service.delete([id])
|
||||
await service.softDelete([createdPromotion.id])
|
||||
|
||||
const promotions = await service.list({
|
||||
id: [id],
|
||||
id: [createdPromotion.id],
|
||||
})
|
||||
|
||||
expect(promotions).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("restore", () => {
|
||||
it("should restore the promotions given an id successfully", async () => {
|
||||
const createdPromotion = await service.create({
|
||||
code: "TEST",
|
||||
type: "standard",
|
||||
})
|
||||
|
||||
await service.softDelete([createdPromotion.id])
|
||||
|
||||
let promotions = await service.list({ id: [createdPromotion.id] })
|
||||
|
||||
expect(promotions).toHaveLength(0)
|
||||
await service.restore([createdPromotion.id])
|
||||
|
||||
promotions = await service.list({ id: [createdPromotion.id] })
|
||||
expect(promotions).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("addPromotionRules", () => {
|
||||
let promotion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user