mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
Rows-per-page was capped at 100 in three independent places: @Max on PaginationQueryDto, the same @Max repeated on ListWagonsQueryDto (which does not extend the base), and MAX_PAGE_SIZE in pagination.util. The first two reject with a 400, the third silently truncates, so a larger page size had to be lifted in all three or the endpoints that opted in would refuse it -- train schedules, routes, locomotives, wagons, audit, rule engine, built trains, batch board and the rest. No service overrides maxPageSize, so the util constant is the effective cap everywhere it is reached. Adds a spec pinning the three together: 500 validates, 501 rejects, and the util returns take: 500 rather than truncating. A fourth copy of the number lives in the backoffice data-table footer and is noted there.
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import { plainToInstance } from 'class-transformer';
|
|
import { validateSync } from 'class-validator';
|
|
|
|
import { PaginationQueryDto } from './pagination-query.dto';
|
|
import { ListWagonsQueryDto } from '../../modules/wagons/dto/list-wagons-query.dto';
|
|
import { normalizePagination } from '../utils/pagination.util';
|
|
|
|
/**
|
|
* The page-size ceiling is stated in three places that must agree: `@Max` on
|
|
* PaginationQueryDto, the same `@Max` repeated on ListWagonsQueryDto (which
|
|
* doesn't extend it), and `MAX_PAGE_SIZE` in pagination.util. A fourth copy
|
|
* lives outside this package — `MAX_PAGE_SIZE` in @edr/ui-common's data-table
|
|
* footer, which is what actually asks for the number. Drift between any of
|
|
* them shows up as a 400 on the largest rows-per-page option, so pin them.
|
|
*/
|
|
const errorsFor = (cls: any, pageSize: unknown) =>
|
|
validateSync(plainToInstance(cls, { pageSize }), { whitelist: false });
|
|
|
|
describe('page size ceiling', () => {
|
|
it.each([PaginationQueryDto, ListWagonsQueryDto])('accepts 500 on %p', (cls) => {
|
|
expect(errorsFor(cls, 500)).toHaveLength(0);
|
|
});
|
|
|
|
it.each([PaginationQueryDto, ListWagonsQueryDto])('rejects 501 on %p', (cls) => {
|
|
expect(errorsFor(cls, 501)).not.toHaveLength(0);
|
|
});
|
|
|
|
it('does not truncate 500 in the service-side clamp', () => {
|
|
expect(normalizePagination({ page: 1, pageSize: 500 }).take).toBe(500);
|
|
expect(normalizePagination({ page: 1, pageSize: 501 }).take).toBe(500);
|
|
});
|
|
});
|