Commit 008d415
authored
fix(dashboard): don't mark promotions with per-attribute campaign budgets as expired (#16018)
## What
Stop the dashboard from showing a red "Campaign expired" badge on active promotions whose campaign uses a per-attribute budget (`use_by_attribute` / `spend_by_attribute`).
Fixes #15960
## Why
`getPromotionStatus` compares `campaignBudget.used > campaignBudget.limit` without looking at the budget type. For per-attribute budgets, `used` is the aggregate across all attribute values (e.g. every customer email) while `limit` applies to each attribute value individually, so the comparison is meaningless — as soon as more distinct customers than the per-customer limit use the promotion, the list and detail views flag it as expired even though the backend keeps redeeming it correctly. Display-only bug, exactly as the reporter diagnosed.
## How
Skip the over-budget check when the budget type is `use_by_attribute` or `spend_by_attribute` (same string-literal comparison the dashboard already uses elsewhere, e.g. the campaign detail widgets). Global `spend`/`usage` budgets and the `ends_at` check behave exactly as before.
## Testing
Added `src/lib/__tests__/promotions.spec.ts` covering: per-attribute budgets over the per-value "limit" stay active (both types — these two fail on current develop and pass with the fix), global `usage` budgets over the limit still show expired, and an ended campaign shows expired regardless of budget type. Ran with vitest in the dashboard workspace, plus eslint on the changed files. Changeset included (patch, `@medusajs/dashboard`).1 parent af4ab2f commit 008d415
3 files changed
Lines changed: 93 additions & 0 deletions
File tree
- .changeset
- packages/admin/dashboard/src/lib
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 81 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
| 53 | + | |
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
| |||
0 commit comments