feat: Wabenhain Honig-Shop Anwendung
Vollstaendige Next.js/Prisma-E-Commerce-Anwendung fuer eine Imkerei: Shop, Warenkorb, Stripe-Checkout, Kundenkonto mit 2FA, Admin-Bereich (Produkte, Ernten, Chargen, Bestellungen, Gutscheine, admin-editierbare Website-Inhalte), i18n (DE/EN), Rate-Limiting/CSP/Audit-Log-Haertung, PostgreSQL- und MySQL-Unterstuetzung ueber austauschbare Prisma- Treiber-Adapter, Unit-/Komponenten-/E2E-Tests.
This commit is contained in:
1 parent
5c76fcc266
commit
c7927f2883
240 files changed
+26096
-137
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { describe, test, expect } from "vitest";
|
||||
import { resolveBulkDiscount, getNextBulkDiscountTier } from "./bulk-discount-calc";
|
||||
|
||||
const tiers = [
|
||||
{ code: "MENGE10", minQuantity: 3, percent: 10 },
|
||||
{ code: "MENGE15", minQuantity: 6, percent: 15 },
|
||||
];
|
||||
|
||||
describe("resolveBulkDiscount", () => {
|
||||
test("returns null when no tier is configured", () => {
|
||||
expect(resolveBulkDiscount([], 5)).toBeNull();
|
||||
});
|
||||
|
||||
test("returns null below the lowest threshold", () => {
|
||||
expect(resolveBulkDiscount(tiers, 2)).toBeNull();
|
||||
});
|
||||
|
||||
test("picks the lowest tier at its boundary", () => {
|
||||
expect(resolveBulkDiscount(tiers, 3)).toEqual({ code: "MENGE10", minQuantity: 3, percent: 10 });
|
||||
});
|
||||
|
||||
test("picks the higher tier once its threshold is reached", () => {
|
||||
expect(resolveBulkDiscount(tiers, 6)).toEqual({ code: "MENGE15", minQuantity: 6, percent: 15 });
|
||||
});
|
||||
|
||||
test("is unaffected by tier input order", () => {
|
||||
const shuffled = [...tiers].reverse();
|
||||
expect(resolveBulkDiscount(shuffled, 6)).toEqual({ code: "MENGE15", minQuantity: 6, percent: 15 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("getNextBulkDiscountTier", () => {
|
||||
test("returns null when no tier is configured", () => {
|
||||
expect(getNextBulkDiscountTier([], 1)).toBeNull();
|
||||
});
|
||||
|
||||
test("returns null once the highest tier is reached", () => {
|
||||
expect(getNextBulkDiscountTier(tiers, 6)).toBeNull();
|
||||
});
|
||||
|
||||
test("reports units and percent of the next tier", () => {
|
||||
expect(getNextBulkDiscountTier(tiers, 1)).toEqual({ unitsUntilNext: 2, percent: 10 });
|
||||
});
|
||||
|
||||
test("reports the tier after the currently active one", () => {
|
||||
expect(getNextBulkDiscountTier(tiers, 3)).toEqual({ unitsUntilNext: 3, percent: 15 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user