feat(): added percentage calculations for all cases (#6300)
what: - adds missing percentage calculations for items and shipping methods
This commit is contained in:
+3622
-1713
File diff suppressed because it is too large
Load Diff
+24
-5
@@ -1,16 +1,17 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import {
|
||||
ApplicationMethodTargetType,
|
||||
ApplicationMethodType,
|
||||
CampaignBudgetType,
|
||||
PromotionType,
|
||||
} from "@medusajs/utils"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { createCampaigns } from "../../../__fixtures__/campaigns"
|
||||
import { createPromotions } from "../../../__fixtures__/promotion"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -114,6 +115,24 @@ describe("Promotion Service", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw error when percentage type and value is greater than 100", async () => {
|
||||
const error = await service
|
||||
.create({
|
||||
code: "PROMOTION_TEST",
|
||||
type: PromotionType.STANDARD,
|
||||
application_method: {
|
||||
type: ApplicationMethodType.PERCENTAGE,
|
||||
target_type: ApplicationMethodTargetType.ORDER,
|
||||
value: "1000",
|
||||
},
|
||||
})
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.message).toContain(
|
||||
"Application Method value should be a percentage number between 0 and 100"
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when both campaign and campaign_id are provided", async () => {
|
||||
const startsAt = new Date("01/01/2023")
|
||||
const endsAt = new Date("01/01/2023")
|
||||
@@ -655,7 +674,7 @@ describe("Promotion Service", () => {
|
||||
is_automatic: true,
|
||||
code: "TEST",
|
||||
type: PromotionType.BUYGET,
|
||||
},
|
||||
} as any,
|
||||
])
|
||||
|
||||
expect(updatedPromotion).toEqual(
|
||||
@@ -899,12 +918,12 @@ describe("Promotion Service", () => {
|
||||
value: "200",
|
||||
target_type: "items",
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
{
|
||||
id: "promotion-id-2",
|
||||
code: "PROMOTION_2",
|
||||
type: PromotionType.STANDARD,
|
||||
},
|
||||
} as any,
|
||||
])
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user