Files
linkder/packages/shared/test/cancellation.test.ts
T
serfowiandClaude Opus 5 19623bcccb M0: foundation — monorepo, PostGIS schema, deck query, app shell
Greenfield scaffold for Linkder, a swipe-to-hire marketplace for local
professional services.

- pnpm/turbo monorepo: apps/web, packages/{shared,db}
- Postgres 16 + PostGIS via docker compose (ports 5442/6389 to avoid
  clashing with other local stacks)
- Drizzle schema, 23 tables, geography(Point,4326) with GiST indexes
- Domain core in packages/shared: integer-cent money, status transition
  graphs, deck ranking weights, cancellation policy — 46 unit tests
- Deck query: filtering in Postgres on the GiST index, ranking in JS so
  the weights stay tunable — 18 integration tests against a seeded DB
- Deterministic seed placing pros at known distances, including three
  that must NOT appear on a deck (out of radius, unverified, away)
- Next.js 15 app shell with a working swipe deck
- CI: typecheck, lint, test, build against live postgres+redis

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 13:32:35 -04:00

73 lines
2.0 KiB
TypeScript

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);
}
});
});