Three-column grid (sidebar / main / right rail) with Cradle aesthetic: blackflame accent on Cinzel display headings + Cormorant Garamond body in cards, system UI for chrome. Hash-based router covers all entity routes plus search, inbox, sacred-valley. api.js stores OWNER_TOKEN in localStorage and prompts via a modal on 401. dom.js provides safe el() + mount() builders so no component ever assigns innerHTML from API data (the only exception is an explicit, scary-named html: opt-in for sanitizer output, used later by the markdown editor). state.js is a tiny event bus for shared chrome state (pending count). Components and views are loaded as ES modules — sidebar / topbar / rightrail + 9 view stubs that the later Phase E tasks fill in. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import request from 'supertest';
|
|
import { createApp } from '../server.js';
|
|
import { resetDb } from './helpers/db.js';
|
|
import { migrateUp } from '../lib/db/migrate.js';
|
|
|
|
let app;
|
|
beforeAll(async () => {
|
|
await resetDb();
|
|
await migrateUp();
|
|
process.env.OWNER_TOKEN = 'test-token';
|
|
app = createApp();
|
|
});
|
|
|
|
describe('server', () => {
|
|
it('GET /health returns 200 with db_ok=true', async () => {
|
|
const res = await request(app).get('/health');
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.db_ok).toBe(true);
|
|
expect(res.body.version).toBeDefined();
|
|
});
|
|
|
|
it('GET /api/spaces without token returns 401', async () => {
|
|
const res = await request(app).get('/api/spaces');
|
|
expect(res.status).toBe(401);
|
|
});
|
|
|
|
it('GET /api/spaces with token returns 200 and empty array', async () => {
|
|
const res = await request(app)
|
|
.get('/api/spaces')
|
|
.set('Authorization', 'Bearer test-token');
|
|
expect(res.status).toBe(200);
|
|
expect(res.body).toEqual([]);
|
|
});
|
|
|
|
it('unknown /api route returns 404 with structured error', async () => {
|
|
const res = await request(app).get('/api/nope').set('Authorization', 'Bearer test-token');
|
|
expect(res.status).toBe(404);
|
|
expect(res.body).toEqual({ error: { code: 'not_found', message: 'route not found' } });
|
|
});
|
|
|
|
it('unknown non-api route returns 404', async () => {
|
|
const res = await request(app).get('/missing');
|
|
expect(res.status).toBe(404);
|
|
});
|
|
|
|
it('GET / serves the SPA shell (text/html)', async () => {
|
|
const res = await request(app).get('/');
|
|
expect(res.status).toBe(200);
|
|
expect(res.headers['content-type']).toMatch(/text\/html/);
|
|
expect(res.text).toMatch(/<div id="shell">/);
|
|
});
|
|
});
|