feat(medusa,types): add promotion list/get endpoint (#6110)
what: - adds get promotion endpoint (RESOLVES CORE-1677) - adds list promotions endpoint (RESOLVES CORE-1676) - uses new API routes
This commit is contained in:
+82
-1
@@ -1,5 +1,9 @@
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { CampaignBudgetType, PromotionType } from "@medusajs/utils"
|
||||
import {
|
||||
ApplicationMethodType,
|
||||
CampaignBudgetType,
|
||||
PromotionType,
|
||||
} from "@medusajs/utils"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initialize } from "../../../../src"
|
||||
import { createCampaigns } from "../../../__fixtures__/campaigns"
|
||||
@@ -680,6 +684,83 @@ describe("Promotion Service", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("listAndCount", () => {
|
||||
beforeEach(async () => {
|
||||
await createPromotions(repositoryManager, [
|
||||
{
|
||||
id: "promotion-id-1",
|
||||
code: "PROMOTION_1",
|
||||
type: PromotionType.STANDARD,
|
||||
application_method: {
|
||||
type: ApplicationMethodType.FIXED,
|
||||
value: "200",
|
||||
target_type: "items",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "promotion-id-2",
|
||||
code: "PROMOTION_2",
|
||||
type: PromotionType.STANDARD,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should return all promotions and count", async () => {
|
||||
const [promotions, count] = await service.listAndCount()
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(promotions).toEqual([
|
||||
{
|
||||
id: "promotion-id-1",
|
||||
code: "PROMOTION_1",
|
||||
campaign: null,
|
||||
is_automatic: false,
|
||||
type: "standard",
|
||||
application_method: expect.any(String),
|
||||
created_at: expect.any(Date),
|
||||
updated_at: expect.any(Date),
|
||||
deleted_at: null,
|
||||
},
|
||||
{
|
||||
id: "promotion-id-2",
|
||||
code: "PROMOTION_2",
|
||||
campaign: null,
|
||||
is_automatic: false,
|
||||
type: "standard",
|
||||
application_method: null,
|
||||
created_at: expect.any(Date),
|
||||
updated_at: expect.any(Date),
|
||||
deleted_at: null,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should return all promotions based on config select and relations param", async () => {
|
||||
const [promotions, count] = await service.listAndCount(
|
||||
{
|
||||
id: ["promotion-id-1"],
|
||||
},
|
||||
{
|
||||
relations: ["application_method"],
|
||||
select: ["code", "application_method.type"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(promotions).toEqual([
|
||||
{
|
||||
id: "promotion-id-1",
|
||||
code: "PROMOTION_1",
|
||||
application_method: {
|
||||
id: expect.any(String),
|
||||
promotion: expect.any(Object),
|
||||
type: "fixed",
|
||||
},
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("delete", () => {
|
||||
beforeEach(async () => {
|
||||
await createPromotions(repositoryManager)
|
||||
|
||||
Reference in New Issue
Block a user