68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
|
|
import {
|
||
|
|
ApproveCourseValidator,
|
||
|
|
RejectCourseValidator,
|
||
|
|
} from '@/validators/AdminCourseApproval.validator';
|
||
|
|
|
||
|
|
describe('ApproveCourseValidator', () => {
|
||
|
|
it('should pass with no body (comment optional)', () => {
|
||
|
|
const { error } = ApproveCourseValidator.validate({});
|
||
|
|
expect(error).toBeUndefined();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should pass with optional comment', () => {
|
||
|
|
const { error } = ApproveCourseValidator.validate({
|
||
|
|
comment: 'Looks great!',
|
||
|
|
});
|
||
|
|
expect(error).toBeUndefined();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should fail when comment exceeds 1000 characters', () => {
|
||
|
|
const { error } = ApproveCourseValidator.validate({
|
||
|
|
comment: 'a'.repeat(1001),
|
||
|
|
});
|
||
|
|
expect(error).toBeDefined();
|
||
|
|
expect(error?.details[0].message).toMatch(/must not exceed 1000/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should pass with comment exactly 1000 characters', () => {
|
||
|
|
const { error } = ApproveCourseValidator.validate({
|
||
|
|
comment: 'a'.repeat(1000),
|
||
|
|
});
|
||
|
|
expect(error).toBeUndefined();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('RejectCourseValidator', () => {
|
||
|
|
it('should pass with valid rejection comment', () => {
|
||
|
|
const { error } = RejectCourseValidator.validate({
|
||
|
|
comment: 'The content is incomplete and needs more details.',
|
||
|
|
});
|
||
|
|
expect(error).toBeUndefined();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should fail without comment', () => {
|
||
|
|
const { error } = RejectCourseValidator.validate({});
|
||
|
|
expect(error).toBeDefined();
|
||
|
|
expect(error?.details[0].message).toMatch(/Comment is required when rejecting/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should fail when comment is too short (< 10 chars)', () => {
|
||
|
|
const { error } = RejectCourseValidator.validate({ comment: 'Too short' });
|
||
|
|
expect(error).toBeDefined();
|
||
|
|
expect(error?.details[0].message).toMatch(/at least 10 characters/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should pass with exactly 10 characters', () => {
|
||
|
|
const { error } = RejectCourseValidator.validate({ comment: '1234567890' });
|
||
|
|
expect(error).toBeUndefined();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should fail when comment exceeds 1000 characters', () => {
|
||
|
|
const { error } = RejectCourseValidator.validate({
|
||
|
|
comment: 'a'.repeat(1001),
|
||
|
|
});
|
||
|
|
expect(error).toBeDefined();
|
||
|
|
expect(error?.details[0].message).toMatch(/must not exceed 1000/i);
|
||
|
|
});
|
||
|
|
});
|