Three test files covering the Phase 1 invariants: - derivePulseStatus: draft/closed are sticky; open auto-closes by date. - vote UNIQUE(pulse_id, user_id): castVote (OR IGNORE) keeps the first vote silently, a raw second INSERT raises a constraint error, and uniqueness is per-pulse (same user on a different pulse is fine). - homeRouteForRole: cab/fenja → /pulse, pilot → null (render existing home). tests/setup.ts opens BIFROST_DB_PATH=':memory:' and applies all migrations before tests run, so the in-memory DB has the live schema. Each vitest fork gets its own globalThis → its own fresh in-memory DB. The homeRouteForRole helper extraction makes the / role-redirect testable without booting Astro. Step 6 will use it from /index.astro. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
16 lines
554 B
TypeScript
16 lines
554 B
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { homeRouteForRole } from '../src/lib/routing.js';
|
|
|
|
describe('homeRouteForRole — what / does per user role', () => {
|
|
it('cab → redirect to /pulse', () => {
|
|
expect(homeRouteForRole('cab')).toBe('/pulse');
|
|
});
|
|
|
|
it('fenja → redirect to /pulse (admins see the member view by default)', () => {
|
|
expect(homeRouteForRole('fenja')).toBe('/pulse');
|
|
});
|
|
|
|
it('pilot → null (render existing editorial home in place)', () => {
|
|
expect(homeRouteForRole('pilot')).toBeNull();
|
|
});
|
|
});
|