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
45
Backend/tests/unit/validators/Lessons.validator.test.ts
Normal file
45
Backend/tests/unit/validators/Lessons.validator.test.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { SetYouTubeVideoValidator } from '@/validators/Lessons.validator';
|
||||
|
||||
describe('SetYouTubeVideoValidator', () => {
|
||||
it('should pass with valid youtube_video_id and video_title', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
youtube_video_id: 'dQw4w9WgXcQ',
|
||||
video_title: 'Introduction to TypeScript',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without youtube_video_id', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
video_title: 'Intro to TS',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/YouTube video ID is required/i);
|
||||
});
|
||||
|
||||
it('should fail with empty youtube_video_id string', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
youtube_video_id: '',
|
||||
video_title: 'Intro to TS',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/cannot be empty/i);
|
||||
});
|
||||
|
||||
it('should fail without video_title', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
youtube_video_id: 'dQw4w9WgXcQ',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Video title is required/i);
|
||||
});
|
||||
|
||||
it('should fail with empty video_title string', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
youtube_video_id: 'dQw4w9WgXcQ',
|
||||
video_title: '',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/cannot be empty/i);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue