feat(promotion,dashboard,types,utils,medusa): Add statuses to promotions (#10950)

what:

- adds a status column to promotion table
- introduce active promotion query
- scope revert, register and compute actions to active promotions
- admin to create and update promotion with statuses

RESOLVES CMRC-845
RESOLVES CMRC-846
RESOLVES CMRC-847
RESOLVES CMRC-848
RESOLVES CMRC-849
RESOLVES CMRC-850
This commit is contained in:
Riqwan Thamir authored and GitHub committed 2025-01-16 19:17:22 +00:00
1 parent effee5c8bb
commit 5eab9e7399
35 files changed
+1208 -1743

No files matched your search

@@ -5,6 +5,7 @@ import {
PriceListType,
ProductStatus,
PromotionRuleOperator,
PromotionStatus,
PromotionType,
} from "@medusajs/utils"
import {
@@ -176,6 +177,7 @@ medusaIntegrationTestRunner({
{
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
status: PromotionStatus.ACTIVE,
application_method: {
type: "fixed",
target_type: "items",
@@ -488,6 +490,65 @@ medusaIntegrationTestRunner({
)
})
it("should remove promotions when promotion is no longer in active state", async () => {
let responseBeforePromotionUpdate = await api.post(
`/store/carts/${cart.id}/line-items`,
{
variant_id: product.variants[0].id,
quantity: 1,
},
storeHeaders
)
expect(responseBeforePromotionUpdate.data.cart).toEqual(
expect.objectContaining({
id: cart.id,
items: expect.arrayContaining([
expect.objectContaining({
adjustments: [
{
id: expect.any(String),
code: "PROMOTION_APPLIED",
promotion_id: promotion.id,
amount: 100,
},
],
}),
]),
})
)
await api.post(
`/admin/promotions/${promotion.id}`,
{ status: PromotionStatus.INACTIVE },
adminHeaders
)
let responseAfterPromotionUpdate = await api.post(
`/store/carts/${cart.id}/line-items`,
{
variant_id: product.variants[0].id,
quantity: 1,
},
storeHeaders
)
expect(responseAfterPromotionUpdate.status).toEqual(200)
expect(responseAfterPromotionUpdate.data.cart).toEqual(
expect.objectContaining({
id: cart.id,
items: expect.arrayContaining([
expect.objectContaining({
adjustments: [],
}),
expect.objectContaining({
adjustments: [],
}),
]),
})
)
})
describe("with custom shipping options prices", () => {
beforeEach(async () => {
cart = (
@@ -1205,6 +1266,7 @@ medusaIntegrationTestRunner({
{
code: "PROMOTION_TEST",
type: PromotionType.STANDARD,
status: PromotionStatus.ACTIVE,
application_method: {
type: "fixed",
target_type: "items",