forked from wangziqi/gongxue-base
test: harden business boundary conditions
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'reflect-metadata';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
import { validate } from 'class-validator';
|
||||
import { NotificationQueryDto } from './notification.dto';
|
||||
import { CreateNotificationDto, NotificationQueryDto } from './notification.dto';
|
||||
|
||||
describe('NotificationQueryDto', () => {
|
||||
it('converts numeric query-string values before integer validation', async () => {
|
||||
@@ -15,3 +15,21 @@ describe('NotificationQueryDto', () => {
|
||||
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([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user