mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 12:18:11 +00:00
fix(reports): stop the 'first N rows' option failing on large exports
The export path used one number for two different things: the format's hard row cap, and the caller's explicit 'give me the first N rows'. Because resolveExportCap() returned min(requested, formatCap) and runAll() then threw when the result reached it, picking 'Records: First 100' in the export dialog 400'd on any report with more than 100 rows — the user asked to be truncated and got an error instead. Splits them: formatRowCap() is the hard, non-caller-controllable ceiling that still throws when exceeded (a silently short file hides missing rows), while resolveRowLimit() is the deliberate truncation and is honoured by slicing. Verified against a 223-row dataset: limit=5 now returns 5 rows, and no limit returns all 223.
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { EXPORT_MIME, pickByKey, resolveExportCap, resolveExportFormat } from './export-request.util';
|
||||
import {
|
||||
EXPORT_MIME,
|
||||
formatRowCap,
|
||||
pickByKey,
|
||||
resolveExportFormat,
|
||||
resolveRowLimit,
|
||||
} from './export-request.util';
|
||||
import { CSV_ROW_CAP, PDF_ROW_CAP, XLSX_ROW_CAP } from './tabular-export.service';
|
||||
|
||||
describe('resolveExportFormat', () => {
|
||||
@@ -15,25 +21,32 @@ describe('resolveExportFormat', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveExportCap', () => {
|
||||
it('missing limit uses the full format cap', () => {
|
||||
expect(resolveExportCap('xlsx', undefined)).toBe(XLSX_ROW_CAP);
|
||||
expect(resolveExportCap('csv', undefined)).toBe(CSV_ROW_CAP);
|
||||
expect(resolveExportCap('pdf', undefined)).toBe(PDF_ROW_CAP);
|
||||
describe('formatRowCap', () => {
|
||||
it('is the format\'s hard ceiling and is not caller-controllable', () => {
|
||||
expect(formatRowCap('xlsx')).toBe(XLSX_ROW_CAP);
|
||||
expect(formatRowCap('csv')).toBe(CSV_ROW_CAP);
|
||||
expect(formatRowCap('pdf')).toBe(PDF_ROW_CAP);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveRowLimit', () => {
|
||||
it('no limit means "everything, up to the cap"', () => {
|
||||
expect(resolveRowLimit('xlsx', undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('a limit under the cap is used as-is', () => {
|
||||
expect(resolveExportCap('pdf', '100')).toBe(100);
|
||||
it('an explicit limit is the caller asking to be truncated — kept as-is', () => {
|
||||
// Distinct from the cap: 100 here must yield 100 rows, not a 400, even
|
||||
// when the unfiltered result is far larger.
|
||||
expect(resolveRowLimit('pdf', '100')).toBe(100);
|
||||
});
|
||||
|
||||
it('a limit over the cap is clamped down', () => {
|
||||
expect(resolveExportCap('pdf', String(PDF_ROW_CAP + 1000))).toBe(PDF_ROW_CAP);
|
||||
expect(resolveExportCap('xlsx', String(XLSX_ROW_CAP + 1))).toBe(XLSX_ROW_CAP);
|
||||
expect(resolveExportCap('csv', String(CSV_ROW_CAP + 1))).toBe(CSV_ROW_CAP);
|
||||
it('an explicit limit over the format cap is clamped down', () => {
|
||||
expect(resolveRowLimit('pdf', String(PDF_ROW_CAP + 1000))).toBe(PDF_ROW_CAP);
|
||||
expect(resolveRowLimit('csv', String(CSV_ROW_CAP + 1))).toBe(CSV_ROW_CAP);
|
||||
});
|
||||
|
||||
it.each(['0', '-5', 'not-a-number', ''])('non-positive/invalid limit %p falls back to the cap', (raw) => {
|
||||
expect(resolveExportCap('xlsx', raw)).toBe(XLSX_ROW_CAP);
|
||||
it.each(['0', '-5', 'not-a-number', ''])('non-positive/invalid limit %p means no limit', (raw) => {
|
||||
expect(resolveRowLimit('xlsx', raw)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user