feat(medusa,utils): added campaign get endpoints (#6125)
what: adds endpoints for the following: - list endpoint (RESOLVES CORE-1682) - retrieve endpoint (RESOLVES CORE-1683)
This commit is contained in:
+65
@@ -27,6 +27,71 @@ describe("Promotion Module Service: Campaigns", () => {
|
||||
await MikroOrmWrapper.clearDatabase()
|
||||
})
|
||||
|
||||
describe("listAndCountCampaigns", () => {
|
||||
beforeEach(async () => {
|
||||
await createCampaigns(repositoryManager)
|
||||
})
|
||||
|
||||
it("should return all campaigns and its count", async () => {
|
||||
const [campaigns, count] = await service.listAndCountCampaigns()
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(campaigns).toEqual([
|
||||
{
|
||||
id: "campaign-id-1",
|
||||
name: "campaign 1",
|
||||
description: "test description",
|
||||
currency: "USD",
|
||||
campaign_identifier: "test-1",
|
||||
starts_at: expect.any(Date),
|
||||
ends_at: expect.any(Date),
|
||||
budget: expect.any(String),
|
||||
created_at: expect.any(Date),
|
||||
updated_at: expect.any(Date),
|
||||
deleted_at: null,
|
||||
},
|
||||
{
|
||||
id: "campaign-id-2",
|
||||
name: "campaign 1",
|
||||
description: "test description",
|
||||
currency: "USD",
|
||||
campaign_identifier: "test-2",
|
||||
starts_at: expect.any(Date),
|
||||
ends_at: expect.any(Date),
|
||||
budget: expect.any(String),
|
||||
created_at: expect.any(Date),
|
||||
updated_at: expect.any(Date),
|
||||
deleted_at: null,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should return all campaigns based on config select and relations param", async () => {
|
||||
const [campaigns, count] = await service.listAndCountCampaigns(
|
||||
{
|
||||
id: ["campaign-id-1"],
|
||||
},
|
||||
{
|
||||
relations: ["budget"],
|
||||
select: ["name", "budget.limit"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(campaigns).toEqual([
|
||||
{
|
||||
id: "campaign-id-1",
|
||||
name: "campaign 1",
|
||||
budget: {
|
||||
id: expect.any(String),
|
||||
campaign: expect.any(Object),
|
||||
limit: 1000,
|
||||
},
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("createCampaigns", () => {
|
||||
it("should throw an error when required params are not passed", async () => {
|
||||
const error = await service
|
||||
|
||||
Reference in New Issue
Block a user