import { TargetMeta } from '../api/api.types'; import { suggestTarget, words } from './target-suggester'; const targets = ['Paciente', 'OrdenesEstudio', 'CitologiaCervical', 'NotaMedica', 'BiopsiaCervical', 'BiometriaHematica'].map( (table) => ({ key: `cacu.${table}`, domain: 'cacu', table, conflict_fields: null, fields: [] }) as TargetMeta, ); describe('suggestTarget', () => { it('splits camelCase, strips accents and extensions', () => { expect(words('OrdenesEstudio')).toEqual(['ordenes', 'estudio']); expect(words('Notas médicas.xlsx')).toEqual(['notas', 'medicas']); }); it.each([ ['pacientes.csv', '', 'Paciente'], ['Órdenes', 'libro.xlsx', 'OrdenesEstudio'], ['Notas médicas', 'libro.xlsx', 'NotaMedica'], ['cacu_biometrias.json', '', 'BiometriaHematica'], // Nothing in the table's own name — fall back to the connection's. ['Tabla 1 · pág. 1', 'cacu_biopsias_reporte.pdf', 'BiopsiaCervical'], ['Regiones 1', 'pacientes_escaneados.pdf', 'Paciente'], // Hospital tables named without separators. ['citologiacervical', 'hospital_cacu', 'CitologiaCervical'], ['biopsiacervical', 'hospital_cacu', 'BiopsiaCervical'], ['notamedica', 'hospital_cacu', 'NotaMedica'], ])('%s (%s) → %s', (table, connection, expected) => { expect(suggestTarget(table, targets, connection)?.table).toBe(expected); }); it('suggests nothing rather than guessing', () => { expect(suggestTarget('datos', targets, 'export.csv')).toBeNull(); }); });