feat: Add unit tests for backend validators and configure Jest.
This commit is contained in:
parent
ebcae0b3e7
commit
9bb941b45e
16 changed files with 2071 additions and 381 deletions
|
|
@ -0,0 +1,67 @@
|
|||
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);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue