import { describe, expect, it } from "vitest";
import { allocateDiscount } from "./allocate";
describe("allocateDiscount", () => {
it("splits by share of the subtotal", () => {
const lines = allocateDiscount([{ amount: 7500 }, { amount: 2500 }], 1000);
expect(lines.map((line) => line.discount)).toEqual([750, 250]);
});
it("gives a single line the whole discount", () => {
const [line] = allocateDiscount([{ amount: 4200 }], 500);
expect(line.discount).toBe(500);
});
+
+ it("adds up to the whole discount", () => {
+ const items = [{ amount: 1000 }, { amount: 1000 }, { amount: 1000 }];
+ const lines = allocateDiscount(items, 1000);
+ const total = lines.reduce((sum, line) => sum + line.discount, 0);
+ expect(total).toBe(1000);
+ });
});