import pino from 'pino'; import { describe, expect, it } from 'vitest'; import type { BaserowClient } from '../../src/adapters/baserow-client.js'; import { BaserowTablesRepo } from '../../src/repos/baserow-tables-repo.js'; const silentLogger = () => pino({ level: 'silent' }); class FakeClient { constructor( public tables: Array<{ id: number; name: string; order: number; database_id: number }> = [], ) {} listTables(_databaseId: number) { return Promise.resolve(this.tables); } getTable(tableId: number) { const t = this.tables.find((x) => x.id === tableId); if (!t) throw new Error('not found'); return Promise.resolve(t); } } describe('BaserowTablesRepo', () => { it('list mappe raw tables -> Table[]', async () => { const fake = new FakeClient([ { id: 1, name: 'Personne', order: 0, database_id: 5 }, { id: 2, name: 'Bloc', order: 1, database_id: 5 }, ]); const repo = new BaserowTablesRepo({ client: fake as unknown as BaserowClient, logger: silentLogger(), }); const res = await repo.list(5); expect(res).toHaveLength(2); expect(res[0]?.id).toBe(1); expect(res[0]?.name).toBe('Personne'); expect(res[0]?.databaseId).toBe(5); expect(res[0]?.orderIndex).toBe(0); }); it('get retourne une Table', async () => { const fake = new FakeClient([{ id: 42, name: 'X', order: 3, database_id: 7 }]); const repo = new BaserowTablesRepo({ client: fake as unknown as BaserowClient, logger: silentLogger(), }); const t = await repo.get(42); expect(t.id).toBe(42); expect(t.databaseId).toBe(7); expect(t.orderIndex).toBe(3); }); });