test: harden business boundary conditions

This commit is contained in:
2026-07-15 00:03:55 +08:00
parent 17a5046ea0
commit b1f35f9d1a
65 changed files with 2311 additions and 293 deletions

View File

@@ -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([]);
}
});
});