Skip to content

Commit

Permalink
✨ New lesson model added
Browse files Browse the repository at this point in the history
  • Loading branch information
reMRKableDev committed Jan 18, 2021
1 parent fb29148 commit 6cc7a5b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
1 change: 1 addition & 0 deletions configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
myCoursesTeachStudentListPrefix: '/my-courses/teach/:id/studentList',
myCoursesTeachEditCoursePrefix: '/my-courses/teach/:id/edit',
myCoursesTeachDeleteCoursePrefix: '/my-courses/teach/:id/delete',
myCoursesTeachNewLessonPrefix: '/my-courses/teach/:id/lesson/new',
myCoursesLearnPrefix: '/my-courses/learn/:id',

/* Database */
Expand Down
13 changes: 5 additions & 8 deletions database/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ exports.fakeCourseData = {
description: 'Dummy Description',
instructors: [],
students: [],
lessons: [],
};

exports.fakeModuleData = {
units: [
{
title: 'Dummy Unit',
content: 'Dummy Content',
videoUrl: 'https://dummy.video.com',
},
],
exports.fakeLessonData = {
topic: 'Dummy Topic',
content: 'Dummy Content',
videoUrl: 'www.dummy.video',
};

exports.fakeUserData = {
Expand Down
63 changes: 63 additions & 0 deletions database/models/__tests__/lesson.model.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const Lesson = require('../lesson.model');
const Course = require('../course.model');
const User = require('../user.model');

const {
fakeUserData,
fakeCourseData,
fakeLessonData,
} = require('../../fixtures');
const {
validateNotEmpty,
validateEquality,
validateObjectMatch,
validateArrayLength,
validateStringEquality,
validateArrayContaining,
} = require('../../../utils/test-utils/validators.utils');
const {
dbConnect,
dbDisconnect,
} = require('../../../utils/test-utils/dbHandler.utils');

let validCourse;
let validLesson;
let validInstructor;

describe('Lesson Model Test Suite', () => {
beforeAll(async () => {
await dbConnect();

validInstructor = await User.create({
local: fakeUserData,
role: fakeUserData.role,
});

const { _id: instructorId } = validInstructor;

fakeCourseData.instructors.push(instructorId);

validCourse = await Course.create(fakeCourseData);

validLesson = await Lesson.create(fakeLessonData);
});

afterAll(async () => dbDisconnect());

test('should validate Lesson created & saved', () => {
const { _id: lessonId } = validLesson;

validCourse.lessons.push(lessonId);

validateNotEmpty(validLesson);
validateObjectMatch(validLesson, fakeLessonData);

validateNotEmpty(validCourse.lessons);
const { lessons } = validCourse;

validateNotEmpty(lessons);

validateArrayLength(lessons, 1);
validateStringEquality(lessons[0], lessonId);
});
});
1 change: 1 addition & 0 deletions database/models/course.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const courseSchema = new Schema({
imageUrl: { type: String, default: 'https://via.placeholder.com/200x150' },
instructors: [{ type: Schema.Types.ObjectId, ref: 'User' }],
students: [{ type: Schema.Types.ObjectId, ref: 'User' }],
lessons: [{ type: Schema.Types.ObjectId, ref: 'Lesson' }],
});

module.exports = model('Course', courseSchema);
10 changes: 10 additions & 0 deletions database/models/lesson.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { Schema, model } = require('mongoose');

const lessonSchema = new Schema({
topic: { type: String, trim: true, unique: true },
content: { type: String, trim: true },
videoUrl: { type: String, default: 'https://via.placeholder.com/200x150' },
isComplete: { type: Boolean, default: false },
});

module.exports = model('Lesson', lessonSchema);

0 comments on commit 6cc7a5b

Please sign in to comment.