fix(schedules): support editable schedule notes
This commit is contained in:
29
apps/server/src/schedules/dto/schedule.dto.spec.ts
Normal file
29
apps/server/src/schedules/dto/schedule.dto.spec.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'reflect-metadata';
|
||||
import { validate } from 'class-validator';
|
||||
import { CreateScheduleDto, UpdateScheduleDto } from './schedule.dto';
|
||||
|
||||
const createSchedule = (notes: string) =>
|
||||
Object.assign(new CreateScheduleDto(), {
|
||||
classId: 1,
|
||||
classroomId: 2,
|
||||
weekDay: 1,
|
||||
startTime: '09:00',
|
||||
endTime: '10:00',
|
||||
startDate: '2026-07-01',
|
||||
endDate: '2026-07-31',
|
||||
subject: '语文',
|
||||
notes,
|
||||
});
|
||||
|
||||
describe('schedule notes validation', () => {
|
||||
it('rejects notes longer than 500 characters when creating', async () => {
|
||||
const errors = await validate(createSchedule('a'.repeat(501)));
|
||||
expect(errors.some((error) => error.property === 'notes')).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects notes longer than 500 characters when updating', async () => {
|
||||
const dto = Object.assign(new UpdateScheduleDto(), { notes: 'a'.repeat(501) });
|
||||
const errors = await validate(dto);
|
||||
expect(errors.some((error) => error.property === 'notes')).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
Matches,
|
||||
Min,
|
||||
Max,
|
||||
MaxLength,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
@@ -59,6 +60,7 @@ export class CreateScheduleDto {
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(500)
|
||||
notes?: string;
|
||||
|
||||
@IsOptional()
|
||||
@@ -115,6 +117,7 @@ export class UpdateScheduleDto {
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(500)
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user