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>
87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
BOOKING_STATUSES,
|
|
TransitionError,
|
|
assertTransition,
|
|
canTransition,
|
|
isTerminal,
|
|
nextStates,
|
|
} from '../src/state-machines';
|
|
|
|
describe('booking transitions', () => {
|
|
it('walks the happy path', () => {
|
|
expect(canTransition('booking', 'scheduled', 'in_progress')).toBe(true);
|
|
expect(canTransition('booking', 'in_progress', 'awaiting_confirmation')).toBe(true);
|
|
expect(canTransition('booking', 'awaiting_confirmation', 'completed')).toBe(true);
|
|
});
|
|
|
|
it('refuses to skip straight to completed — the payout guard', () => {
|
|
expect(canTransition('booking', 'scheduled', 'completed')).toBe(false);
|
|
expect(() => assertTransition('booking', 'scheduled', 'completed')).toThrow(TransitionError);
|
|
});
|
|
|
|
it('cannot resurrect a cancelled booking', () => {
|
|
expect(isTerminal('booking', 'cancelled')).toBe(true);
|
|
expect(canTransition('booking', 'cancelled', 'scheduled')).toBe(false);
|
|
});
|
|
|
|
it('still allows a dispute after completion', () => {
|
|
expect(canTransition('booking', 'completed', 'disputed')).toBe(true);
|
|
});
|
|
|
|
it('rejects unknown states instead of silently allowing them', () => {
|
|
expect(canTransition('booking', 'nonsense', 'completed')).toBe(false);
|
|
expect(nextStates('booking', 'nonsense')).toEqual([]);
|
|
});
|
|
|
|
it('every declared status appears in the graph', () => {
|
|
for (const status of BOOKING_STATUSES) {
|
|
expect(() => nextStates('booking', status)).not.toThrow();
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('payment transitions', () => {
|
|
it('holds before it releases', () => {
|
|
expect(canTransition('payment', 'pending', 'held')).toBe(true);
|
|
expect(canTransition('payment', 'held', 'released')).toBe(true);
|
|
});
|
|
|
|
it('never releases straight from pending — money only moves after capture', () => {
|
|
expect(canTransition('payment', 'pending', 'released')).toBe(false);
|
|
});
|
|
|
|
it('lets a failed payment be retried', () => {
|
|
expect(canTransition('payment', 'failed', 'pending')).toBe(true);
|
|
});
|
|
|
|
it('treats a full refund as final', () => {
|
|
expect(isTerminal('payment', 'refunded')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('verification transitions', () => {
|
|
it('requires review before a pro is verified', () => {
|
|
expect(canTransition('verification', 'draft', 'verified')).toBe(false);
|
|
expect(canTransition('verification', 'draft', 'pending')).toBe(true);
|
|
expect(canTransition('verification', 'pending', 'verified')).toBe(true);
|
|
});
|
|
|
|
it('can suspend a verified pro and reinstate them', () => {
|
|
expect(canTransition('verification', 'verified', 'suspended')).toBe(true);
|
|
expect(canTransition('verification', 'suspended', 'verified')).toBe(true);
|
|
});
|
|
|
|
it('lets a rejected pro reapply', () => {
|
|
expect(canTransition('verification', 'rejected', 'pending')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('request transitions', () => {
|
|
it('is one-shot — an accepted request cannot change', () => {
|
|
expect(isTerminal('request', 'accepted')).toBe(true);
|
|
expect(canTransition('request', 'accepted', 'declined')).toBe(false);
|
|
expect(canTransition('request', 'expired', 'accepted')).toBe(false);
|
|
});
|
|
});
|