import pino from 'pino'; import { describe, expect, it } from 'vitest'; import type { BaserowClient } from '../../src/adapters/baserow-client.js'; import { BaserowFieldsRepo } from '../../src/repos/baserow-fields-repo.js'; const silentLogger = () => pino({ level: 'silent' }); class FakeClient { constructor( public raws: Array< { id: number; name: string; type: string; primary?: boolean } & Record > = [], ) {} listFields(_tableId: number) { return Promise.resolve(this.raws); } } describe('BaserowFieldsRepo', () => { it('list mappe raw fields -> Field[] avec options groupees', async () => { const fake = new FakeClient([ { id: 10, name: 'titre', type: 'text', primary: true }, { id: 11, name: 'statut', type: 'single_select', primary: false, select_options: [{ id: 1, value: 'a' }], }, ]); const repo = new BaserowFieldsRepo({ client: fake as unknown as BaserowClient, logger: silentLogger(), }); const fields = await repo.list(5); expect(fields).toHaveLength(2); expect(fields[0]?.primary).toBe(true); expect(fields[0]?.options).toBeNull(); expect(fields[1]?.options).toEqual({ select_options: [{ id: 1, value: 'a' }] }); }); it('field sans meta extra : options=null', async () => { const fake = new FakeClient([{ id: 1, name: 'x', type: 'text', primary: false }]); const repo = new BaserowFieldsRepo({ client: fake as unknown as BaserowClient, logger: silentLogger(), }); const fields = await repo.list(5); expect(fields[0]?.options).toBeNull(); }); });