forked from wangziqi/gongxue-base
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import 'reflect-metadata';
|
|
import { plainToInstance } from 'class-transformer';
|
|
import { validate } from 'class-validator';
|
|
import { CreateNotificationDto, NotificationQueryDto } from './notification.dto';
|
|
|
|
describe('NotificationQueryDto', () => {
|
|
it('converts numeric query-string values before integer validation', async () => {
|
|
const dto = plainToInstance(NotificationQueryDto, {
|
|
after: '42',
|
|
limit: '20',
|
|
});
|
|
|
|
await expect(validate(dto)).resolves.toEqual([]);
|
|
expect(dto.after).toBe(42);
|
|
expect(dto.limit).toBe(20);
|
|
});
|
|
});
|
|
|
|
describe('notification DTO boundaries', () => {
|
|
it('rejects an empty recipient set', async () => {
|
|
const dto = plainToInstance(CreateNotificationDto, {
|
|
recipientIds: [],
|
|
type: 'test',
|
|
title: '标题',
|
|
});
|
|
await expect(validate(dto)).resolves.toEqual(expect.arrayContaining([expect.any(Object)]));
|
|
});
|
|
|
|
it('rejects non-positive cursors and page sizes outside 1-100', async () => {
|
|
for (const value of [{ after: '0' }, { limit: '0' }, { limit: '101' }]) {
|
|
const dto = plainToInstance(NotificationQueryDto, value);
|
|
expect(await validate(dto)).not.toEqual([]);
|
|
}
|
|
});
|
|
});
|