40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { importFile } from '../../src/importers/importer';
|
|
import { genericProfile } from '../../src/profiles/generic/generic-profile';
|
|
import { ImportError } from '../../src/shared/errors';
|
|
|
|
const options = { profiles: [genericProfile] };
|
|
|
|
describe('structured import errors', () => {
|
|
it('wraps unexpected parser failures with a machine-readable diagnostic', async () => {
|
|
const file = new File(['{"finding":'], 'broken.json', { type: 'application/json' });
|
|
|
|
try {
|
|
await importFile(file, options);
|
|
throw new Error('Expected JSON import to fail.');
|
|
} catch (error) {
|
|
expect(error).toBeInstanceOf(ImportError);
|
|
expect((error as ImportError).diagnostics).toContainEqual(expect.objectContaining({
|
|
code: 'file-parse-error',
|
|
severity: 'error',
|
|
details: { extension: 'json' }
|
|
}));
|
|
}
|
|
});
|
|
|
|
it('reports an empty decoded import with a dedicated diagnostic', async () => {
|
|
const file = new File(['\r\n\r\n'], 'empty.csv', { type: 'text/csv' });
|
|
|
|
try {
|
|
await importFile(file, options);
|
|
throw new Error('Expected empty import to fail.');
|
|
} catch (error) {
|
|
expect(error).toBeInstanceOf(ImportError);
|
|
expect((error as ImportError).diagnostics).toContainEqual(expect.objectContaining({
|
|
code: 'empty-import',
|
|
severity: 'error'
|
|
}));
|
|
}
|
|
});
|
|
});
|