From 0b2046e23be8e0157e3830d0885d3331647a3631 Mon Sep 17 00:00:00 2001 From: Tejas Nair <85873779+TejasNair9977@users.noreply.github.com> Date: Mon, 30 Oct 2023 00:01:42 +0530 Subject: [PATCH 1/2] Rename EntityIdValidation.js to entityIdValidation.js hotpatch --- middleware/{EntityIdValidation.js => entityIdValidation.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename middleware/{EntityIdValidation.js => entityIdValidation.js} (100%) diff --git a/middleware/EntityIdValidation.js b/middleware/entityIdValidation.js similarity index 100% rename from middleware/EntityIdValidation.js rename to middleware/entityIdValidation.js From 6233d2b138e6fdcdd93a09f60f01f7300432be65 Mon Sep 17 00:00:00 2001 From: Tejas Nair <85873779+TejasNair9977@users.noreply.github.com> Date: Mon, 6 Nov 2023 20:04:51 +0530 Subject: [PATCH 2/2] added mocks for even more models --- .env.example | 10 ++++ .gitignore | 3 +- misc/initDB.js | 65 +++++++++++++++++++++- misc/mockDB/attendanceMock.js | 34 ++++++++++++ misc/mockDB/facultyMock.js | 97 +++++++++++++++++++++++++++++++++ misc/mockDB/notificationMock.js | 33 +++++++++++ misc/mockDB/studentMock.js | 84 ++++++++++++++++++++++++++++ misc/mockDB/userMock.js | 74 +++++++++++++++++++++++++ models/attendance.js | 27 ++++++++- models/faculty.js | 50 ++++++++++++++++- models/notification.js | 19 ++++++- models/student.js | 19 +++++++ models/user.js | 21 ++++++- package.json | 4 +- test/routes/exam.test.js | 40 ++++++++++---- 15 files changed, 559 insertions(+), 21 deletions(-) create mode 100644 .env.example create mode 100644 misc/mockDB/attendanceMock.js create mode 100644 misc/mockDB/facultyMock.js create mode 100644 misc/mockDB/notificationMock.js create mode 100644 misc/mockDB/studentMock.js create mode 100644 misc/mockDB/userMock.js diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..58eb6e1b --- /dev/null +++ b/.env.example @@ -0,0 +1,10 @@ +PORT=4000 +TOKEN_SECRET=mysecret +ENVIRONMENT=local +DB_URL=mongodb://mongo1:30001,mongo2:30002,mongo3:30003/?replicaSet=my-replica-set +EMAIL_HOST= +EMAIL_PORT= +EMAIL_USER= +EMAIL_PASS= + +# get email stuff from mailtrap \ No newline at end of file diff --git a/.gitignore b/.gitignore index 47657fad..4199a2d0 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,5 @@ dist .pnp.* # ingore genrated APIdocs -apidoc \ No newline at end of file +apidoc +data/ \ No newline at end of file diff --git a/misc/initDB.js b/misc/initDB.js index c669e180..49f3d6e4 100644 --- a/misc/initDB.js +++ b/misc/initDB.js @@ -9,6 +9,11 @@ import Tutorial from "#models/tutorial"; import Practical from "#models/practical"; import Semester from "#models/semester"; import Course from "#models/course"; +import Faculty from "#models/faculty"; +import Student from "#models/student"; +import Attendance from "#models/attendance"; +import Notification from "#models/notification"; +import User from "#models/user"; import generateOrganizations from "#mockDB/orgMock"; import ACCREDS from "#mockDB/accredMock"; import TOPICS from "#mockDB/topicMock"; @@ -19,6 +24,11 @@ import generatePracticals from "#mockDB/pracMock"; import generateTutorials from "#mockDB/tutMock"; import generateSemesters from "#mockDB/semMock"; import generateCourses from "#mockDB/courseMock"; +import generateFaculty from "#mockDB/facultyMock"; +import generateStudents from "#mockDB/studentMock"; +import generateAttendance from "#mockDB/attendanceMock"; +import generateNotifications from "#mockDB/notificationMock"; +import generateUsers from "#mockDB/userMock"; // eslint-disable-line no-unused-vars /* eslint-disable no-underscore-dangle */ const createdAccreds = await Accreditation.createMultiple(ACCREDS); @@ -86,6 +96,59 @@ const COURSES = generateCourses( createdDepts.map((createdDept) => createdDept._id), ); -const createdCourses = await Course.createMultiple(COURSES); // eslint-disable-line no-unused-vars +const createdCourses = await Course.createMultiple(COURSES); + +const FACULTY = generateFaculty( + createdDepts.map((createdDept) => createdDept._id), + createdCourses.map((createdCourse) => createdCourse._id), +); + +const createdFaculty = await Faculty.createMultiple(FACULTY); + +const STUDENTS = generateStudents( + createdDepts.map((createdDept) => createdDept._id), + createdCourses.map((createdCourse) => createdCourse._id), +); + +const createdStudents = await Student.createMultiple(STUDENTS); + +const studentCourseList = createdStudents.map((student) => { + const studentId = student._id.toString(); + const coursesOpted = student.coursesOpted.map((courseId) => + courseId.toString(), + ); + return { studentId, coursesOpted }; +}); + +const ATTENDANCE = generateAttendance(studentCourseList); + +const createdAttendance = await Attendance.createMultiple(ATTENDANCE); + +// const USERS = generateUsers( // TODO this takes forever bruhh +// createdStudents.map((createdStudent) => createdStudent.ERPID), +// createdFaculty.map((createdFaculty) => createdFaculty.ERPID), +// ) + +// const createdUsers = await User.createMultiple(USERS) + +const createdUsers = await User.read(); // use this after you initialized Users at least once, or wait for years every time + +const NOTIFS = generateNotifications( + createdUsers.data + .filter((user) => user.userType === "STUDENT") + .map((student) => student._id), + createdUsers.data + .filter((user) => user.userType === "FACULTY") + .map((faculty) => faculty._id), + createdUsers.data + .filter((user) => user.userType === "ADMIN") + .map((admin) => admin._id), +); + +const createdNotifications = await Notification.createMultiple(NOTIFS); + +console.log(createdNotifications); +console.log(createdAttendance); +console.log(createdFaculty); process.exit(0); diff --git a/misc/mockDB/attendanceMock.js b/misc/mockDB/attendanceMock.js new file mode 100644 index 00000000..bc16b9d7 --- /dev/null +++ b/misc/mockDB/attendanceMock.js @@ -0,0 +1,34 @@ +import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies + +const createRandomAttendance = (studentId, courseId) => { + const monthlyAttendedInt = faker.number.int({ min: 0, max: 25 }); + return { + student: studentId, + course: courseId, + monthlyAttended: monthlyAttendedInt, + monthlyOccured: faker.number.int({ min: 25, max: 27 }), + cumulativeAttended: + monthlyAttendedInt + faker.number.int({ min: 0, max: 150 }), + cumulativeOccured: + monthlyAttendedInt + faker.number.int({ min: 150, max: 175 }), + }; +}; + +const generateAttendance = (studentCourseList) => { + const attendance = []; + for (let i = 0, j = 0; i < studentCourseList.length; j += 1) { + attendance.push( + createRandomAttendance( + studentCourseList[i].studentId, + studentCourseList[i].coursesOpted[j], + ), + ); + if (j >= 6) { + i += 1; + j = 0; + } + } + return attendance; +}; + +export default generateAttendance; diff --git a/misc/mockDB/facultyMock.js b/misc/mockDB/facultyMock.js new file mode 100644 index 00000000..258792ca --- /dev/null +++ b/misc/mockDB/facultyMock.js @@ -0,0 +1,97 @@ +import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies + +function getRandomLetter() { + const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const randomIndex = Math.floor(Math.random() * alphabet.length); + return alphabet[randomIndex]; +} + +function randomDate(start, end) { + return new Date( + start.getTime() + Math.random() * (end.getTime() - start.getTime()), + ); +} + +// Function to generate random 4-digit number +function getRandomNumber() { + return Math.floor(1000 + Math.random() * 9000); +} + +const generatedIDs = []; + +const createRandomFaculty = (departmentId, createdCourses) => { + let id; + do { + const letter = getRandomLetter(); + const number = getRandomNumber(); + id = `F${letter}${number}`; + } while (generatedIDs.includes(id)); + generatedIDs.push(id); + const doj = faker.date.past({ years: 5 }); + return { + ERPID: id, + dateOfJoining: doj, + dateOfLeaving: faker.datatype.boolean({ probability: 0.4 }) + ? randomDate(doj, new Date()) + : null, + profileLink: faker.internet.url(), + qualifications: [ + faker.lorem.word(), + faker.lorem.word(), + faker.lorem.word(), + ], + totalExperience: faker.number.int({ min: 1, max: 20 }), + achievements: [ + faker.lorem.words(), + faker.lorem.words(), + faker.lorem.words(), + ], + areaOfSpecialization: [ + faker.lorem.word(), + faker.lorem.word(), + faker.lorem.word(), + ], + papersPublishedPG: faker.number.int({ min: 0, max: 50 }), + papersPublishedUG: faker.number.int({ min: 0, max: 50 }), + department: departmentId, + preferredSubjects: createdCourses, + designation: faker.helpers.arrayElements( + [ + "HOD", + "Assistant Professor", + "Associate Professor", + "Activity Head", + "Professor", + "Director", + "T&P Officer", + "R&D Activity Head", + ], + { min: 1, max: 3 }, + ), + natureOfAssociation: faker.helpers.arrayElement([ + "Regular", + "Contract", + "Adjunct", + ]), + additionalResponsibilities: faker.lorem.words(), + }; +}; + +const generateFaculty = (createdDepts, createdCourses) => { + const faculty = []; + let selectedCourses; + for (let i = 0, j = 1; i < createdDepts.length; j += 1) { + selectedCourses = faker.helpers.arrayElements(createdCourses, { + min: 4, + max: 8, + }); + faculty.push(createRandomFaculty(createdDepts[i], selectedCourses)); + if (j > 30) { + i += 1; + j = 0; + } + } + return faculty; +}; + +export default generateFaculty; diff --git a/misc/mockDB/notificationMock.js b/misc/mockDB/notificationMock.js new file mode 100644 index 00000000..4037c3f3 --- /dev/null +++ b/misc/mockDB/notificationMock.js @@ -0,0 +1,33 @@ +import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies + +const generateNotifications = (studentIds, facultyIds, adminIds) => { + const notifications = []; + const notificationTypes = ["Student", "Faculty"]; + + for (let i = 0; i < 300; i += 1) { + const notification = { + data: faker.lorem.lines({ min: 3, max: 7 }), + title: faker.lorem.sentence(), + from: faker.helpers.arrayElement([...facultyIds, ...adminIds]), + type: faker.helpers.arrayElement(notificationTypes), + filter: [], + }; + + if (notification.type === "Student") { + notification.filter = faker.helpers.arrayElements(studentIds, { + min: 5, + max: 100, + }); + } else { + notification.filter = faker.helpers.arrayElements( + [...facultyIds, ...adminIds], + { min: 5, max: 100 }, + ); + } + notifications.push(notification); + } + + return notifications; +}; + +export default generateNotifications; diff --git a/misc/mockDB/studentMock.js b/misc/mockDB/studentMock.js new file mode 100644 index 00000000..50212c47 --- /dev/null +++ b/misc/mockDB/studentMock.js @@ -0,0 +1,84 @@ +import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies + +const departmentAbbrev = [ + "ME", + "CE", + "CS", + "IT", + "ETE", + "ECS", + "AIDS", + "IOT", + "AIML", + "CSS", + "MEMM", + "AIDS", + "SD", + "AGD", + "DA", +]; + +function generateRandomYear() { + const currentYear = new Date().getFullYear(); + const availableYears = Array.from( + { length: 4 }, + (_, index) => currentYear - index, + ); + const randomIndex = Math.floor(Math.random() * availableYears.length); + return availableYears[randomIndex].toString().slice(-2); +} + +function generateRandomThreeDigitNumber() { + return Math.floor(100 + Math.random() * 900); +} + +function generateStudentID(i) { + const departmentInitials = departmentAbbrev[i]; + const year = generateRandomYear(); + const randomThreeDigitNumber = generateRandomThreeDigitNumber(); + return `S${departmentInitials}${year}${randomThreeDigitNumber}`; +} + +const generatedIDs = []; + +const createRandomStudent = (department, createdCourses, k, j, i) => { + let id; + let divisionLetter; + do id = generateStudentID(i); + while (generatedIDs.includes(id)); + generatedIDs.push(id); + if (j >= 120) divisionLetter = "C"; + else if (j >= 60) divisionLetter = "B"; + else divisionLetter = "A"; + return { + ERPID: id, + name: faker.person.fullName(), + joiningYear: new Date().getFullYear() - k, + branch: department, + division: divisionLetter, + rollNo: (j % 60) + 1, + coursesOpted: createdCourses, + }; +}; + +const generateStudents = (createdDepts, createdCourses) => { + const students = []; + let selectedCourses; + for (let i = 0, j = 0, k = 0; k < 4; j += 1) { + selectedCourses = faker.helpers.arrayElements(createdCourses, 7); + students.push( + createRandomStudent(createdDepts[i], selectedCourses, k, j, i), + ); + if (j >= 179) { + i += 1; + j = -1; + } + if (i === createdDepts.length) { + i = 0; + k += 1; + } + } + return students; +}; + +export default generateStudents; diff --git a/misc/mockDB/userMock.js b/misc/mockDB/userMock.js new file mode 100644 index 00000000..e5af10c1 --- /dev/null +++ b/misc/mockDB/userMock.js @@ -0,0 +1,74 @@ +import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies + +const departmentAbbrev = [ + "ME", + "CE", + "CS", + "IT", + "ETE", + "ECS", + "AIDS", + "IOT", + "AIML", + "CSS", + "MEMM", + "SD", + "AGD", + "DA", +]; + +function getRandomLetter() { + const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const randomIndex = Math.floor(Math.random() * alphabet.length); + return alphabet[randomIndex]; +} + +function getRandomNumber() { + return Math.floor(100 + Math.random() * 900); +} + +const generatedEmails = new Set(); + +const createRandomUser = (ID, type) => { + let email; + do { + email = faker.internet.email(); + } while (generatedEmails.has(email)); + + generatedEmails.add(email); + + return { + name: faker.person.fullName(), + emailId: email, + password: faker.internet.password(), + uid: ID, + userType: type, + }; +}; + +const generatedIDs = []; + +const generateUsers = (studentIds, facultyIds) => { + const users = []; + for (let i = 0; i < studentIds.length; i += 1) { + users.push(createRandomUser(studentIds[i], "STUDENT")); + } + for (let i = 0; i < facultyIds.length; i += 1) { + users.push(createRandomUser(facultyIds[i], "FACULTY")); + } + for (let i = 0; i < 300; i += 1) { + let id; + do { + id = `E${getRandomLetter()}${getRandomLetter()}${getRandomNumber()}`; + } while (generatedIDs.includes(id)); + generatedIDs.push(id); + users.push(createRandomUser(id, "EMPLOYEE")); + } + for (let i = 0; i < departmentAbbrev.length; i += 1) { + users.push(createRandomUser(`A${departmentAbbrev[i]}001`, "ADMIN")); + } + users.push(createRandomUser("A001", "ADMIN")); + return users; +}; + +export default generateUsers; diff --git a/models/attendance.js b/models/attendance.js index c1ef29c0..3bfb51b1 100644 --- a/models/attendance.js +++ b/models/attendance.js @@ -1,7 +1,5 @@ import connector from "#models/databaseUtil"; -connector.set("debug", true); - const attendanceSchema = { student: { type: connector.Schema.Types.ObjectId, @@ -42,6 +40,30 @@ async function create(attendanceData) { return attendanceDoc; } +async function createMultiple(attendanceDataArray) { + const attendances = attendanceDataArray.map( + ({ + student, + course, + monthlyAttended, + monthlyOccured, + cumulativeAttended, + cumulativeOccured, + }) => + Attendance({ + student, + course, + monthlyAttended, + monthlyOccured, + cumulativeAttended, + cumulativeOccured, + }), + ); + + const attendanceDocs = await Attendance.insertMany(attendances); + return attendanceDocs; +} + async function read(filter, limit = 0, page = 1) { const attendanceDoc = await Attendance.find(filter) .limit(limit) @@ -70,4 +92,5 @@ export default { remove, update, read, + createMultiple, }; diff --git a/models/faculty.js b/models/faculty.js index c63a316e..e94a1bfe 100644 --- a/models/faculty.js +++ b/models/faculty.js @@ -26,6 +26,10 @@ const facultySchema = { "Assistant Professor", "Associate Professor", "Activity Head", + "Professor", + "Director", + "T&P Officer", + "R&D Activity Head", ], required: true, }, @@ -52,11 +56,52 @@ async function create(facultyData) { return facultyDoc; } +async function createMultiple(facultyDataArray) { + const facultys = facultyDataArray.map( + ({ + ERPID, + dateOfJoining, + dateOfLeaving, + profileLink, + qualifications, + totalExperience, + achievements, + areaOfSpecialization, + papersPublishedPG, + papersPublishedUG, + department, + preferredSubjects, + designation, + natureOfAssociation, + additionalResponsibilities, + }) => + Faculty({ + ERPID, + dateOfJoining, + dateOfLeaving, + profileLink, + qualifications, + totalExperience, + achievements, + areaOfSpecialization, + papersPublishedPG, + papersPublishedUG, + department, + preferredSubjects, + designation, + natureOfAssociation, + additionalResponsibilities, + }), + ); + + const facultyDocs = await Faculty.insertMany(facultys); + return facultyDocs; +} + async function read(filter, limit = 0, page = 1) { const facultyDoc = await Faculty.find(filter) .limit(limit) - .skip((page - 1) * limit) - .exec(); + .skip((page - 1) * limit); const count = await Faculty.count(); const totalPages = Math.ceil(count / limit); return { totalPages, data: facultyDoc }; @@ -76,4 +121,5 @@ export default { read, update, remove, + createMultiple, }; diff --git a/models/notification.js b/models/notification.js index 8cac4fe9..61da260e 100644 --- a/models/notification.js +++ b/models/notification.js @@ -11,7 +11,7 @@ const notificationSchema = { }, from: { type: connector.Schema.Types.ObjectId, - ref: "Faculty", // Reference to the Faculty model + ref: "User", // Reference to the Faculty model required: true, }, type: { @@ -44,6 +44,22 @@ async function create(notificationData) { return notificationDOC; } +async function createMultiple(notificationDataArray) { + const notifications = notificationDataArray.map( + ({ data, title, from, type, filter }) => + Notification({ + data, + title, + from, + type, + filter, + }), + ); + + const notificationDocs = await Notification.insertMany(notifications); + return notificationDocs; +} + async function read(filter, limit = 0, page = 1) { const notificationDoc = await Notification.find(filter) .limit(limit) @@ -73,4 +89,5 @@ export default { read, update, remove, + createMultiple, }; diff --git a/models/student.js b/models/student.js index afdab1f3..f72d06d5 100644 --- a/models/student.js +++ b/models/student.js @@ -43,6 +43,24 @@ async function create(studentData) { return studentDoc; } +async function createMultiple(studentDataArray) { + const students = studentDataArray.map( + ({ ERPID, name, joiningYear, branch, division, rollNo, coursesOpted }) => + Student({ + ERPID, + name, + joiningYear, + branch, + division, + rollNo, + coursesOpted, + }), + ); + + const studentDocs = await Student.insertMany(students); + return studentDocs; +} + async function read(filter, limit = 0, page = 1) { const studentDoc = await Student.find(filter) .limit(limit) @@ -67,4 +85,5 @@ export default { read, update, remove, + createMultiple, }; diff --git a/models/user.js b/models/user.js index 00c2f24d..e100c458 100644 --- a/models/user.js +++ b/models/user.js @@ -1,7 +1,6 @@ import connector from "#models/databaseUtil"; import { hashPassword } from "#util"; -connector.set("debug", true); const userSchema = { name: { type: String, required: true }, emailId: { type: String, unique: true, required: true }, @@ -10,7 +9,7 @@ const userSchema = { userType: { type: String, required: true, - enum: ["ADMIN", "FACULTY", "EMPLOYEE", "STUDENT"], + enum: ["ADMIN", "FACULTY", "EMPLOYEE", "STUDENT", "PARENT", "DEV"], default: "ADMIN", // for now we are keeping the default usertype as ADMIN }, @@ -37,6 +36,23 @@ async function create(userData) { return userDoc; } +async function createMultiple(userDataArray) { + const hashPromises = userDataArray.map(async (userData) => { + const { name, emailId, password, uid, userType } = userData; + const hashedPassword = await hashPassword(password); + return User({ + name, + password: hashedPassword, + emailId, + uid, + userType, + }); + }); + const users = await Promise.all(hashPromises); + const userDocs = await User.insertMany(users); + return userDocs; +} + async function read(filter, limit = 0, page = 1) { const userDoc = await User.find(filter) .limit(limit) @@ -61,4 +77,5 @@ export default { read, update, remove, + createMultiple, }; diff --git a/package.json b/package.json index b1ca24b3..391927b6 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,10 @@ "devstart": "nodemon ./bin/www", "serverstart": "DEBUG=api:* npm run devstart", "serverstartWin": "SET DEBUG=api:* && npm run devstart", - "test": "NODE_OPTIONS=--experimental-vm-modules npx jest", + "test": "NODE_OPTIONS=--experimental-vm-modules npx jest --runInBand", "test:watch": "NODE_OPTIONS=--experimental-vm-modules npx jest --watch", "test:openHandles": "NODE_OPTIONS=--experimental-vm-modules npx jest --detectOpenHandles", - "testWin": "SET NODE_OPTIONS=--experimental-vm-modules && npx jest", + "testWin": "SET NODE_OPTIONS=--experimental-vm-modules && npx jest --runInBand", "testWin:watch": "SET NODE_OPTIONS=--experimental-vm-modules && npx jest --watch", "testWin:openHandles": "SET NODE_OPTIONS=--experimental-vm-modules && npx jest --detectOpenHandles", "eslint": "eslint", diff --git a/test/routes/exam.test.js b/test/routes/exam.test.js index 5500fb40..dece571a 100644 --- a/test/routes/exam.test.js +++ b/test/routes/exam.test.js @@ -1,14 +1,20 @@ import { jest } from "@jest/globals"; // eslint-disable-line import/no-extraneous-dependencies import connector from "#models/databaseUtil"; import examModel from "#models/exam"; +import facultyModel from "#models/faculty"; +import courseModel from "#models/course"; +import infraModel from "#models/infrastructure"; +/* eslint-disable no-underscore-dangle */ jest.mock("#util"); const { agent } = global; - +let supervisorId; +let infraId; +let courseId; function cleanUp(callback) { examModel .remove({ - supervisor: "5f8778b54b553439ac49a03a", + supervisor: supervisorId, }) .then(() => { connector.disconnect((DBerr) => { @@ -18,19 +24,33 @@ function cleanUp(callback) { }); } +async function getIds(callback) { + supervisorId = await facultyModel.read({}, 1); + supervisorId = supervisorId.data[0]._id; + infraId = await infraModel.read({}, 1); + infraId = infraId.data[0]._id; + courseId = await courseModel.read({}, 1); + courseId = courseId.data[0]._id; + callback(); +} + afterAll((done) => { cleanUp(done); }); +beforeAll((done) => { + getIds(done); +}); + describe("exam API", () => { it("should create exam", async () => { const response = await agent.post("/exam/add").send({ date: "2023-06-18T14:11:30Z", startTime: "2023-06-18T14:11:30Z", duration: 5, - supervisor: "5f8778b54b553439ac49a03a", - infrastructure: "5f8778b54b553439ac49a03a", - course: "5f8778b54b553439ac49a03a", + supervisor: supervisorId, + infrastructure: infraId, + course: courseId, }); expect(response.headers["content-type"]).toMatch(/json/); expect(response.status).toBe(200); @@ -44,21 +64,21 @@ describe("exam API", () => { date: "2023-06-18T14:11:30Z", startTime: "2023-06-18T14:11:30Z", duration: 5, - supervisor: "64453a62c8f2146f2f34c73a", - infrastructure: "64453a62c8f2146f2f34c73a", - course: "64453a62c8f2146f2f34c73a", + supervisor: supervisorId, + infrastructure: infraId, + course: courseId, }); id = JSON.parse(id.res.text).id; }); afterEach(async () => { - await examModel.remove({ supervisor: "64453a62c8f2146f2f34c73a" }); + await examModel.remove({ supervisor: supervisorId }); }); it("should read exam", async () => { const response = await agent .get("/exam/list") - .send({ supervisor: "64453a62c8f2146f2f34c73a" }); + .send({ supervisor: supervisorId }); expect(response.status).toBe(200); expect(response.body.res).toBeDefined(); });