mirror of
https://github.com/Since-3/Kuma.git
synced 2026-10-12 21:41:17 +00:00
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import {
|
|
courseAmountCents,
|
|
payoutAmountCents,
|
|
sumCourseRevenueCents,
|
|
} from "@/src/lib/booking-amounts";
|
|
|
|
describe("courseAmountCents", () => {
|
|
it("zieht die Gebühr ab, wenn sie dem Kunden aufgeschlagen wurde", () => {
|
|
// Kunde zahlte 29,50 €, davon 0,50 € Servicegebühr an die Plattform.
|
|
expect(courseAmountCents({ amountPaid: 2950, platformFee: 50, platformFeeOnTop: true })).toBe(
|
|
2900
|
|
);
|
|
});
|
|
|
|
it("lässt Altbuchungen mit prozentualer Fee unverändert", () => {
|
|
// Kunde zahlte 29,00 €, davon wurden 5 % aus dem Kurspreis einbehalten -
|
|
// amountPaid ist hier bereits der Kursanteil und darf nicht erneut
|
|
// gekürzt werden, sonst ändern sich bestehende Rechnungen rückwirkend.
|
|
expect(courseAmountCents({ amountPaid: 2900, platformFee: 145, platformFeeOnTop: false })).toBe(
|
|
2900
|
|
);
|
|
});
|
|
|
|
it("behandelt fehlende Beträge als 0", () => {
|
|
expect(courseAmountCents({ amountPaid: null, platformFee: null, platformFeeOnTop: true })).toBe(
|
|
0
|
|
);
|
|
expect(courseAmountCents({ amountPaid: 2950, platformFee: null, platformFeeOnTop: true })).toBe(
|
|
2950
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("sumCourseRevenueCents", () => {
|
|
it("summiert Kursanteile über beide Gebührenmodelle und zieht Erstattungen ab", () => {
|
|
const revenue = sumCourseRevenueCents([
|
|
{ amountPaid: 2950, platformFee: 50, platformFeeOnTop: true, refundedAmount: null },
|
|
{ amountPaid: 2900, platformFee: 145, platformFeeOnTop: false, refundedAmount: null },
|
|
// Teilerstattung: 50 % des Kursanteils gingen zurück.
|
|
{ amountPaid: 2950, platformFee: 50, platformFeeOnTop: true, refundedAmount: 1450 },
|
|
]);
|
|
expect(revenue).toBe(2900 + 2900 + (2900 - 1450));
|
|
});
|
|
|
|
it("ist bei leerer Liste 0", () => {
|
|
expect(sumCourseRevenueCents([])).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe("payoutAmountCents", () => {
|
|
it("zieht bei Direct Charges Plattform- und Stripe-Gebühr ab", () => {
|
|
// Kunde zahlte 29,50 €; 0,50 € gingen an Kumasy, 0,69 € an Stripe.
|
|
expect(
|
|
payoutAmountCents({
|
|
amountPaid: 2950,
|
|
platformFee: 50,
|
|
platformFeeOnTop: true,
|
|
stripeFee: 69,
|
|
})
|
|
).toBe(2831);
|
|
});
|
|
|
|
it("zieht bei Altbuchungen die prozentuale Gebühr vom Kurspreis ab", () => {
|
|
// Dem Studio gingen 5 % ab, die Stripe-Gebühr trug die Plattform. Den
|
|
// Kursanteil (2900) als Auszahlung zu zeigen, wäre 1,45 € zu viel.
|
|
expect(
|
|
payoutAmountCents({
|
|
amountPaid: 2900,
|
|
platformFee: 145,
|
|
platformFeeOnTop: false,
|
|
stripeFee: null,
|
|
})
|
|
).toBe(2755);
|
|
});
|
|
|
|
it("zeigt bis zur Abrechnung durch Stripe den Betrag ohne Stripe-Gebühr", () => {
|
|
expect(
|
|
payoutAmountCents({
|
|
amountPaid: 2950,
|
|
platformFee: 50,
|
|
platformFeeOnTop: true,
|
|
stripeFee: null,
|
|
})
|
|
).toBe(2900);
|
|
});
|
|
});
|