Assessor_2.0/tests/importers/import-load.test.ts

32 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { nodeImportRuntimeAdapters } from '../../server/node-import-runtime-adapters';
import { importSource } from '../../src/importers/engine';
import { genericProfile } from '../../src/profiles/generic/generic-profile';
describe('import load boundaries', () => {
it('processes a 30000-record CSV without loss inside the supported policy', async () => {
const rowCount = 30_000;
const text = ['Rule ID;Title;Severity', ...Array.from({ length: rowCount }, (_, index) => `LOAD-${index};Finding ${index};High`)].join('\n');
const bytes = new TextEncoder().encode(text);
const dataset = await importSource({
metadata: { name: 'load.csv', sizeBytes: bytes.length, lastModified: 0 }, bytes
}, { profiles: [genericProfile], delimiter: ';' }, nodeImportRuntimeAdapters);
expect(dataset.sheets[0].analysis.records).toHaveLength(rowCount);
expect(dataset.sheets[0].analysis.records[0].title).toBe('Finding 0');
expect(dataset.sheets[0].analysis.records.at(-1)?.title).toBe(`Finding ${rowCount - 1}`);
}, 15_000);
it('rejects physical row counts beyond a configured boundary before CSV allocation', async () => {
const text = ['Title', ...Array.from({ length: 101 }, (_, index) => `Finding ${index}`)].join('\n');
const bytes = new TextEncoder().encode(text);
await expect(importSource({
metadata: { name: 'over-limit.csv', sizeBytes: bytes.length, lastModified: 0 }, bytes
}, {
profiles: [genericProfile], delimiter: ';', resourcePolicy: { maximumTotalRows: 100 }
}, nodeImportRuntimeAdapters)).rejects.toMatchObject({
diagnostics: [expect.objectContaining({ code: 'row-limit' })]
});
});
});