37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import 'reflect-metadata';
|
|
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { plainToInstance } from 'class-transformer';
|
|
import { validate } from 'class-validator';
|
|
import { ListAuditQueryDto } from '../../src/audit/dto/list-audit-query.dto';
|
|
import { AuditSource } from '../../src/database/entities';
|
|
|
|
test('ListAuditQueryDto transforms pagination and normalized enums', async () => {
|
|
const dto = plainToInstance(ListAuditQueryDto, {
|
|
page: '2',
|
|
pageSize: '50',
|
|
action: ' user_created ',
|
|
source: 'web',
|
|
from: '2026-08-01T00:00:00.000Z',
|
|
});
|
|
|
|
assert.deepEqual(await validate(dto), []);
|
|
assert.equal(dto.page, 2);
|
|
assert.equal(dto.pageSize, 50);
|
|
assert.equal(dto.action, 'USER_CREATED');
|
|
assert.equal(dto.source, AuditSource.WEB);
|
|
});
|
|
|
|
test('ListAuditQueryDto rejects oversized pages and invalid dates', async () => {
|
|
const dto = plainToInstance(ListAuditQueryDto, {
|
|
page: '0',
|
|
pageSize: '500',
|
|
from: 'fecha-invalida',
|
|
});
|
|
const properties = new Set((await validate(dto)).map((error) => error.property));
|
|
|
|
assert.equal(properties.has('page'), true);
|
|
assert.equal(properties.has('pageSize'), true);
|
|
assert.equal(properties.has('from'), true);
|
|
});
|