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>
103 lines
2.9 KiB
TypeScript
103 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
FieldSchema,
|
|
RowFieldsSchema,
|
|
RowSchema,
|
|
TableSchema,
|
|
ViewSchema,
|
|
} from '../../src/domain/schemas.js';
|
|
|
|
describe('FieldSchema', () => {
|
|
it('valide un field minimal', () => {
|
|
const r = FieldSchema.parse({ id: 1, name: 'nom', type: 'text' });
|
|
expect(r.primary).toBe(false);
|
|
expect(r.options).toBeUndefined();
|
|
});
|
|
|
|
it('rejette name vide', () => {
|
|
expect(() => FieldSchema.parse({ id: 1, name: '', type: 'text' })).toThrow();
|
|
});
|
|
|
|
it('accepte type custom (Baserow expose tout)', () => {
|
|
const r = FieldSchema.parse({ id: 1, name: 'x', type: 'rollup' });
|
|
expect(r.type).toBe('rollup');
|
|
});
|
|
|
|
it('options accept Record<string, unknown>', () => {
|
|
const r = FieldSchema.parse({
|
|
id: 1,
|
|
name: 'statut',
|
|
type: 'single_select',
|
|
options: { select_options: [{ id: 1 }] },
|
|
});
|
|
expect(r.options).toEqual({ select_options: [{ id: 1 }] });
|
|
});
|
|
});
|
|
|
|
describe('ViewSchema', () => {
|
|
it('valide une view grid', () => {
|
|
const r = ViewSchema.parse({ id: 1, name: 'Tous', type: 'grid', tableId: 5 });
|
|
expect(r.type).toBe('grid');
|
|
});
|
|
|
|
it('accepte un type custom', () => {
|
|
const r = ViewSchema.parse({ id: 1, name: 'X', type: 'weird', tableId: 5 });
|
|
expect(r.type).toBe('weird');
|
|
});
|
|
|
|
it('rejette tableId negatif', () => {
|
|
expect(() => ViewSchema.parse({ id: 1, name: 'X', type: 'grid', tableId: 0 })).toThrow();
|
|
});
|
|
});
|
|
|
|
describe('TableSchema', () => {
|
|
it('valide une table minimale', () => {
|
|
const r = TableSchema.parse({ id: 1, name: 'Personne', databaseId: 5 });
|
|
expect(r.orderIndex).toBe(0);
|
|
});
|
|
|
|
it('rejette id <= 0', () => {
|
|
expect(() => TableSchema.parse({ id: 0, name: 'x', databaseId: 1 })).toThrow();
|
|
});
|
|
});
|
|
|
|
describe('RowSchema', () => {
|
|
it('valide une row avec fields opaques', () => {
|
|
const r = RowSchema.parse({
|
|
id: 1,
|
|
tableId: 5,
|
|
fields: { nom: 'x', heures: 40 },
|
|
});
|
|
expect(r.fields.heures).toBe(40);
|
|
});
|
|
|
|
it('id 0 est accepte (NEW row temp client-side)', () => {
|
|
const r = RowSchema.parse({ id: 0, tableId: 1, fields: {} });
|
|
expect(r.id).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('RowFieldsSchema', () => {
|
|
it('accepte n importe quel record', () => {
|
|
expect(RowFieldsSchema.parse({ a: 1, b: 'x', c: null })).toEqual({ a: 1, b: 'x', c: null });
|
|
});
|
|
|
|
it('rejette un non-objet', () => {
|
|
expect(() => RowFieldsSchema.parse([1, 2])).toThrow();
|
|
expect(() => RowFieldsSchema.parse('foo')).toThrow();
|
|
});
|
|
|
|
it('accepte un objet vide (PATCH partiel possible)', () => {
|
|
expect(RowFieldsSchema.parse({})).toEqual({});
|
|
});
|
|
|
|
it('accepte des valeurs nested arbitraires (link_row, select, formula result)', () => {
|
|
const v = {
|
|
link: [{ id: 1, value: 'X' }],
|
|
select: { id: 5, value: 'actif', color: 'green' },
|
|
formula_result: 42.5,
|
|
tags: ['a', 'b'],
|
|
};
|
|
expect(RowFieldsSchema.parse(v)).toEqual(v);
|
|
});
|
|
});
|