Files
KomediruzeckiandGitHub 5b4a4d913c test(contract): one CRUD suite for cloud and local-first, and the 35 bugs it found (#606)
Every route both runtimes serve now has a scenario, written once and run against the Worker on D1 and against local-first on IndexedDB: create from the body the form sends, read it back to the cent, edit, delete, and check that another profile can neither read nor change it. Guards fail when a served route is on no list or has no passing scenario.

- shared/contract/ holds 120 scenarios in 24 entity files and the route lists: 171 routes served by both runtimes, 69 by the Worker only, 25 by local-first only. One-runtime write routes are tested in their own runtime.
- 52 places where the runtimes still answer differently are pinned at the check (// DIFFERENCE <id>) and described in shared/contract/differences.ts, each with the slice that settles it.
- 35 bugs are fixed, each in its own commit with a test that fails without it. Among them: Copy last month deleted the month's budgets before copying, in both runtimes (it now fills only the categories with no budget yet, and says how many already had one); a cloud month summary counted every later month; a local-first bill lost its account, so paying it moved no balance; deleting a cloud loan left its rate periods and extra payments in D1.
- Local-first's PUT /loans/:id/rate, which answered 404 for every loan and had no caller, is gone with api.updateLoanRate.
2026-10-08 16:14:52 +02:00

39 lines
1.5 KiB
TypeScript

import { expectOk, scenario } from '../types';
export const session = [
scenario('the signed-in person, and signing out', async (api, expect) => {
// The app asks who is signed in when it starts (api.checkLogin); the email banner reads the
// same answer.
const me = await api.get('/api/auth/me');
expectOk(expect, me, 'GET /api/auth/me');
// DIFFERENCE auth-local-user
if (api.runtime === 'worker') {
expect(me.body).toMatchObject({
id: expect.any(Number),
email: expect.any(String),
auth_provider: 'password',
});
} else {
expect(me.body).toEqual({ id: 1, username: 'local', role: 'admin' });
}
// Logout signs this browser out (App.tsx handleLogout), in either mode.
const out = await api.post('/api/auth/logout');
expectOk(expect, out, 'POST /api/auth/logout');
expect(out.body).toEqual({ ok: true });
// DIFFERENCE auth-local-user: local-first has no session to end.
expect((await api.get('/api/auth/me')).status).toBe(api.runtime === 'worker' ? 401 : 200);
}),
scenario('the health check', async (api, expect) => {
const reply = await api.get('/api/health');
expectOk(expect, reply, 'GET /api/health');
// DIFFERENCE health-answer
if (api.runtime === 'worker') {
expect(reply.body).toEqual({ ok: true, env: 'development', captcha: 'disabled' });
} else {
expect(reply.body).toEqual({ status: 'ok', timestamp: expect.any(String) });
}
}),
];