Some checks are pending
CI / Lint bridge (Biome) (push) Waiting to run
CI / Type-check bridge (push) Blocked by required conditions
CI / Tests unit bridge (push) Blocked by required conditions
CI / Tests integration bridge (push) Blocked by required conditions
CI / Security scan (push) Waiting to run
CI / Docker build + healthcheck (push) Blocked by required conditions
Pivot strategique : DocAdenice = produit Notion-like generique. Le bridge
est livre vide a un user qui cree ses tables Baserow comme il veut. Code
sans aucune ontologie metier.
Suppressions :
- 9 entites domain metier (Personne, Formation, Bloc, Module, Attribution,
Client, Projet, Tache, Intervention) + types.ts (Role, statuts)
- baserow-repo.ts (mega-fichier 554 LOC avec 9 repos heritant BaseRepo)
- 6 routes metier (personnes, formations, projets, modules, interventions,
attributions) + tests associes
- Lookup PersonneRepo.findByEmail dans middleware auth
- Mapping DEFAULT_ROLE_SCOPES dans middleware/scopes.ts
- Cascade rollup metier dans webhooks/baserow-handler.ts
Ajouts :
- Domain generique : Table, Row, Field, View + schemas zod refondus
- 4 repos generiques : tables / rows / fields / views
- Route unique routes/tables.ts avec 9 endpoints REST CRUD generiques
- Claim JWT acadenice_permissions[] lu directement dans le middleware auth
(alimente par RBAC dynamique cote DocAdenice en R2)
- examples/acadenice-formation-hub/ : README + seed-baserow.md schema
9 tables + example-roles.md (Formateur, Developpeur, Direction, Support,
Admin avec permissions generiques)
Refactors :
- BaserowClient etendu : listTables, getTable, listFields, listViews,
getGridViewRows
- middleware/auth.ts : extractPermissions(payload), AuthenticatedUser
remplace roles[] par permissions[]
- middleware/scopes.ts : computeOidcScopes(groups, permissions, map)
- webhooks/baserow-handler.ts : invalidation generique
bridge:tables:<tableId>:* sans cascade cross-table
- lib/cache.ts : invalidateEntity -> invalidateTable(redis, tableId, rowId?)
- container.ts : drop tableIds, RepoSet={tables, rows, fields, views}
- 501 NOT_IMPLEMENTED si DB token sur endpoints /tables qui exigent JWT
Tests : 250/250 verts (depuis 319). Coverage : domain 98.9%, adapters 89%,
auth 97.08%, rate-limit 100%, cache 100%, webhooks 100%.
Quality gates verts : typecheck, lint biome, vitest, coverage thresholds.
Refs: R1 dans le pivot strategique DocAdenice Notion-like generique.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
108 lines
3.2 KiB
TypeScript
108 lines
3.2 KiB
TypeScript
import { Hono } from 'hono';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { z } from 'zod';
|
|
import { dec, parseBody, parseListQuery } from '../../src/lib/http.js';
|
|
import { errorHandler } from '../../src/middleware/error-handler.js';
|
|
|
|
describe('parseListQuery', () => {
|
|
it('extrait page/per_page/sort/filter', async () => {
|
|
const app = new Hono();
|
|
app.get('/', (c) => {
|
|
const q = parseListQuery(c);
|
|
return c.json(q);
|
|
});
|
|
const res = await app.request('/?page=2&per_page=20&sort=-name&filter[statut]=actif');
|
|
const body = (await res.json()) as {
|
|
page: number;
|
|
per_page: number;
|
|
sort: string;
|
|
filter: Record<string, string>;
|
|
};
|
|
expect(body.page).toBe(2);
|
|
expect(body.per_page).toBe(20);
|
|
expect(body.sort).toBe('-name');
|
|
expect(body.filter.statut).toBe('actif');
|
|
});
|
|
|
|
it('clamp per_page entre 1 et 200', async () => {
|
|
const app = new Hono();
|
|
app.get('/', (c) => c.json(parseListQuery(c)));
|
|
|
|
const r1 = await app.request('/?per_page=500');
|
|
const b1 = (await r1.json()) as { per_page: number };
|
|
expect(b1.per_page).toBe(200);
|
|
|
|
const r2 = await app.request('/?per_page=0');
|
|
const b2 = (await r2.json()) as { per_page: number };
|
|
// 0 -> default fallback 50
|
|
expect(b2.per_page).toBeGreaterThanOrEqual(1);
|
|
});
|
|
|
|
it('defaults page=1 per_page=50', async () => {
|
|
const app = new Hono();
|
|
app.get('/', (c) => c.json(parseListQuery(c)));
|
|
const res = await app.request('/');
|
|
const body = (await res.json()) as { page: number; per_page: number };
|
|
expect(body.page).toBe(1);
|
|
expect(body.per_page).toBe(50);
|
|
});
|
|
});
|
|
|
|
describe('dec', () => {
|
|
it('toFixed 2 sur Decimal', async () => {
|
|
const { Decimal } = await import('decimal.js');
|
|
expect(dec(new Decimal('40.123'))).toBe('40.12');
|
|
expect(dec(new Decimal(0))).toBe('0.00');
|
|
});
|
|
it('null/undefined -> "0"', () => {
|
|
expect(dec(null)).toBe('0');
|
|
expect(dec(undefined)).toBe('0');
|
|
});
|
|
});
|
|
|
|
describe('parseBody', () => {
|
|
it('valide via schema', async () => {
|
|
const app = new Hono();
|
|
app.onError(errorHandler);
|
|
app.post('/', async (c) => {
|
|
const body = await parseBody(c, z.object({ a: z.number() }));
|
|
return c.json(body);
|
|
});
|
|
const res = await app.request('/', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ a: 1 }),
|
|
});
|
|
expect(res.status).toBe(200);
|
|
});
|
|
|
|
it('400 si body pas JSON', async () => {
|
|
const app = new Hono();
|
|
app.onError(errorHandler);
|
|
app.post('/', async (c) => {
|
|
await parseBody(c, z.object({}));
|
|
return c.json({});
|
|
});
|
|
const res = await app.request('/', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: 'not-json',
|
|
});
|
|
expect(res.status).toBe(400);
|
|
});
|
|
|
|
it('400 si schema mismatch', async () => {
|
|
const app = new Hono();
|
|
app.onError(errorHandler);
|
|
app.post('/', async (c) => {
|
|
await parseBody(c, z.object({ a: z.number() }));
|
|
return c.json({});
|
|
});
|
|
const res = await app.request('/', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ a: 'not-a-number' }),
|
|
});
|
|
expect(res.status).toBe(400);
|
|
});
|
|
});
|