import { describe, expect, it } from 'vitest'; import { cancellationOutcome } from '../src/cancellation'; const NOW = new Date('2026-06-01T12:00:00Z'); const inHours = (h: number) => new Date(NOW.getTime() + h * 3_600_000); describe('cancellationOutcome', () => { it('refunds in full when the client cancels well ahead', () => { const out = cancellationOutcome({ amountCents: 20_000, scheduledStart: inHours(48), cancelledBy: 'client', now: NOW, }); expect(out.refundCents).toBe(20_000); expect(out.feeCents).toBe(0); }); it('charges a fee when the client cancels inside the window', () => { const out = cancellationOutcome({ amountCents: 20_000, scheduledStart: inHours(3), cancelledBy: 'client', now: NOW, }); expect(out.feeCents).toBe(5_000); // 25% expect(out.refundCents).toBe(15_000); }); it('treats exactly 24h out as still free', () => { const out = cancellationOutcome({ amountCents: 20_000, scheduledStart: inHours(24), cancelledBy: 'client', now: NOW, }); expect(out.feeCents).toBe(0); }); it('never charges the client when the pro drops the job', () => { const out = cancellationOutcome({ amountCents: 20_000, scheduledStart: inHours(1), cancelledBy: 'pro', now: NOW, }); expect(out.refundCents).toBe(20_000); expect(out.feeCents).toBe(0); }); it('refunds in full on an admin cancellation', () => { const out = cancellationOutcome({ amountCents: 20_000, scheduledStart: inHours(1), cancelledBy: 'admin', now: NOW, }); expect(out.refundCents).toBe(20_000); }); it('always splits the full amount, whatever the branch', () => { for (const hours of [-5, 0, 1, 23.9, 24, 100]) { const out = cancellationOutcome({ amountCents: 12_345, scheduledStart: inHours(hours), cancelledBy: 'client', now: NOW, }); expect(out.refundCents + out.feeCents).toBe(12_345); } }); });