fix: .js + sendStatusMock in backend controller
This commit is contained in:
		
							parent
							
								
									44c242fc57
								
							
						
					
					
						commit
						82c2197950
					
				
					 8 changed files with 68 additions and 62 deletions
				
			
		|  | @ -11,7 +11,7 @@ import { | ||||||
|     getStudentSubmissions, |     getStudentSubmissions, | ||||||
| } from '../services/students.js'; | } from '../services/students.js'; | ||||||
| import { StudentDTO } from '../interfaces/student.js'; | import { StudentDTO } from '../interfaces/student.js'; | ||||||
| import {requireFields} from "./error-helper"; | import {requireFields} from "./error-helper.js"; | ||||||
| 
 | 
 | ||||||
| export async function getAllStudentsHandler(req: Request, res: Response): Promise<void> { | export async function getAllStudentsHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const full = req.query.full === 'true'; |     const full = req.query.full === 'true'; | ||||||
|  |  | ||||||
|  | @ -12,7 +12,7 @@ import { ClassDTO } from '../interfaces/class.js'; | ||||||
| import { StudentDTO } from '../interfaces/student.js'; | import { StudentDTO } from '../interfaces/student.js'; | ||||||
| import { QuestionDTO, QuestionId } from '../interfaces/question.js'; | import { QuestionDTO, QuestionId } from '../interfaces/question.js'; | ||||||
| import { TeacherDTO } from '../interfaces/teacher.js'; | import { TeacherDTO } from '../interfaces/teacher.js'; | ||||||
| import {requireFields} from "./error-helper"; | import {requireFields} from "./error-helper.js"; | ||||||
| 
 | 
 | ||||||
| export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> { | export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const full = req.query.full === 'true'; |     const full = req.query.full === 'true'; | ||||||
|  | @ -93,7 +93,7 @@ export async function getStudentJoinRequestHandler(req: Request, res: Response) | ||||||
| export async function updateStudentJoinRequestHandler(req: Request, res: Response) { | export async function updateStudentJoinRequestHandler(req: Request, res: Response) { | ||||||
|     const studentUsername = req.query.studentUsername as string; |     const studentUsername = req.query.studentUsername as string; | ||||||
|     const classId = req.params.classId; |     const classId = req.params.classId; | ||||||
|     const accepted = req.body.accepted !== 'false'; // default = true
 |     const accepted = req.body.accepted !== 'false'; // Default = true
 | ||||||
|     requireFields({ studentUsername, classId }); |     requireFields({ studentUsername, classId }); | ||||||
| 
 | 
 | ||||||
|     await updateClassJoinRequestStatus(studentUsername, classId, accepted); |     await updateClassJoinRequestStatus(studentUsername, classId, accepted); | ||||||
|  |  | ||||||
|  | @ -12,18 +12,18 @@ import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js | ||||||
| import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js'; | import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js'; | ||||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js'; | import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js'; | ||||||
| import { getAllAssignments } from './assignments.js'; | import { getAllAssignments } from './assignments.js'; | ||||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question'; | import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | ||||||
| import {mapToStudentRequest, mapToStudentRequestDTO} from "../interfaces/student-request"; | import {mapToStudentRequest, mapToStudentRequestDTO} from "../interfaces/student-request.js"; | ||||||
| import {Student} from "../entities/users/student.entity"; | import {Student} from "../entities/users/student.entity.js"; | ||||||
| import {NotFoundException} from "../exceptions/not-found-exception"; | import {NotFoundException} from "../exceptions/not-found-exception.js"; | ||||||
| import {fetchClass} from "./classes"; | import {fetchClass} from "./classes.js"; | ||||||
| 
 | 
 | ||||||
| export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> { | export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> { | ||||||
|     const studentRepository = getStudentRepository(); |     const studentRepository = getStudentRepository(); | ||||||
|     const users = await studentRepository.findAll(); |     const users = await studentRepository.findAll(); | ||||||
| 
 | 
 | ||||||
|     if (full) |     if (full) | ||||||
|         return users.map(mapToStudentDTO); |         {return users.map(mapToStudentDTO);} | ||||||
| 
 | 
 | ||||||
|     return users.map((user) => user.username); |     return users.map((user) => user.username); | ||||||
| } | } | ||||||
|  | @ -54,7 +54,7 @@ export async function createStudent(userData: StudentDTO): Promise<void> { | ||||||
| export async function deleteStudent(username: string): Promise<void> { | export async function deleteStudent(username: string): Promise<void> { | ||||||
|     const studentRepository = getStudentRepository(); |     const studentRepository = getStudentRepository(); | ||||||
| 
 | 
 | ||||||
|     await fetchStudent(username); // throws error if it does not exist
 |     await fetchStudent(username); // Throws error if it does not exist
 | ||||||
| 
 | 
 | ||||||
|     await studentRepository.deleteByUsername(username); |     await studentRepository.deleteByUsername(username); | ||||||
| } | } | ||||||
|  | @ -116,16 +116,15 @@ export async function getStudentQuestions(username: string, full: boolean): Prom | ||||||
|     const questionsDTO = questions.map(mapToQuestionDTO); |     const questionsDTO = questions.map(mapToQuestionDTO); | ||||||
| 
 | 
 | ||||||
|     if (full) |     if (full) | ||||||
|         return questionsDTO; |         {return questionsDTO;} | ||||||
| 
 | 
 | ||||||
|     return questionsDTO.map(mapToQuestionId); |     return questionsDTO.map(mapToQuestionId); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function createClassJoinRequest(studentUsername: string, classId: string) { | export async function createClassJoinRequest(studentUsername: string, classId: string) { | ||||||
|     const classRepo = getClassRepository(); |  | ||||||
|     const requestRepo = getClassJoinRequestRepository(); |     const requestRepo = getClassJoinRequestRepository(); | ||||||
| 
 | 
 | ||||||
|     const student = await fetchStudent(studentUsername); // throws error if student not found
 |     const student = await fetchStudent(studentUsername); // Throws error if student not found
 | ||||||
|     const cls = await fetchClass(classId); |     const cls = await fetchClass(classId); | ||||||
| 
 | 
 | ||||||
|     const request = mapToStudentRequest(student, cls); |     const request = mapToStudentRequest(student, cls); | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { getGroupRepository, getSubmissionRepository } from '../data/repositories.js'; | import { getSubmissionRepository } from '../data/repositories.js'; | ||||||
| import { Language } from '../entities/content/language.js'; | import { Language } from '../entities/content/language.js'; | ||||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||||
| import { mapToSubmission, mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; | import { mapToSubmission, mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; | ||||||
|  |  | ||||||
|  | @ -8,22 +8,22 @@ import { | ||||||
| import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; | import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; | ||||||
| import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from '../interfaces/question.js'; | import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from '../interfaces/question.js'; | ||||||
| import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js'; | import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js'; | ||||||
| import {Teacher} from "../entities/users/teacher.entity"; | import {Teacher} from "../entities/users/teacher.entity.js"; | ||||||
| import {fetchStudent} from "./students"; | import {fetchStudent} from "./students.js"; | ||||||
| import {ClassJoinRequest, ClassJoinRequestStatus} from "../entities/classes/class-join-request.entity"; | import {ClassJoinRequest, ClassJoinRequestStatus} from "../entities/classes/class-join-request.entity.js"; | ||||||
| import {mapToStudentRequestDTO, StudentRequestDTO} from "../interfaces/student-request"; | import {mapToStudentRequestDTO, StudentRequestDTO} from "../interfaces/student-request.js"; | ||||||
| import {TeacherRepository} from "../data/users/teacher-repository"; | import {TeacherRepository} from "../data/users/teacher-repository.js"; | ||||||
| import {ClassRepository} from "../data/classes/class-repository"; | import {ClassRepository} from "../data/classes/class-repository.js"; | ||||||
| import {Class} from "../entities/classes/class.entity"; | import {Class} from "../entities/classes/class.entity.js"; | ||||||
| import {StudentDTO} from "../interfaces/student"; | import {StudentDTO} from "../interfaces/student.js"; | ||||||
| import {LearningObjectRepository} from "../data/content/learning-object-repository"; | import {LearningObjectRepository} from "../data/content/learning-object-repository.js"; | ||||||
| import {LearningObject} from "../entities/content/learning-object.entity"; | import {LearningObject} from "../entities/content/learning-object.entity.js"; | ||||||
| import {QuestionRepository} from "../data/questions/question-repository"; | import {QuestionRepository} from "../data/questions/question-repository.js"; | ||||||
| import {Question} from "../entities/questions/question.entity"; | import {Question} from "../entities/questions/question.entity.js"; | ||||||
| import {ClassJoinRequestRepository} from "../data/classes/class-join-request-repository"; | import {ClassJoinRequestRepository} from "../data/classes/class-join-request-repository.js"; | ||||||
| import {Student} from "../entities/users/student.entity"; | import {Student} from "../entities/users/student.entity.js"; | ||||||
| import {NotFoundException} from "../exceptions/not-found-exception"; | import {NotFoundException} from "../exceptions/not-found-exception.js"; | ||||||
| import {getClassStudents} from "./classes"; | import {getClassStudents} from "./classes.js"; | ||||||
| 
 | 
 | ||||||
| export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | ||||||
|     const teacherRepository: TeacherRepository = getTeacherRepository(); |     const teacherRepository: TeacherRepository = getTeacherRepository(); | ||||||
|  | @ -61,7 +61,7 @@ export async function createTeacher(userData: TeacherDTO): Promise<void> { | ||||||
| export async function deleteTeacher(username: string): Promise<void> { | export async function deleteTeacher(username: string): Promise<void> { | ||||||
|     const teacherRepository: TeacherRepository = getTeacherRepository(); |     const teacherRepository: TeacherRepository = getTeacherRepository(); | ||||||
| 
 | 
 | ||||||
|     await fetchTeacher(username); // throws error if it does not exist
 |     await fetchTeacher(username); // Throws error if it does not exist
 | ||||||
| 
 | 
 | ||||||
|     await teacherRepository.deleteByUsername(username); |     await teacherRepository.deleteByUsername(username); | ||||||
| } | } | ||||||
|  | @ -106,7 +106,7 @@ export async function getTeacherQuestions(username: string, full: boolean): Prom | ||||||
|     const learningObjectRepository: LearningObjectRepository = getLearningObjectRepository(); |     const learningObjectRepository: LearningObjectRepository = getLearningObjectRepository(); | ||||||
|     const learningObjects: LearningObject[] = await learningObjectRepository.findAllByTeacher(teacher); |     const learningObjects: LearningObject[] = await learningObjectRepository.findAllByTeacher(teacher); | ||||||
| 
 | 
 | ||||||
|     // console.log(learningObjects)
 |     // Console.log(learningObjects)
 | ||||||
|     // TODO returns empty
 |     // TODO returns empty
 | ||||||
| 
 | 
 | ||||||
|     if (!learningObjects || learningObjects.length === 0){ |     if (!learningObjects || learningObjects.length === 0){ | ||||||
|  |  | ||||||
|  | @ -14,11 +14,12 @@ import { | ||||||
|     getStudentRequestHandler, |     getStudentRequestHandler, | ||||||
|     deleteClassJoinRequestHandler |     deleteClassJoinRequestHandler | ||||||
| } from '../../src/controllers/students.js'; | } from '../../src/controllers/students.js'; | ||||||
| import {TEST_STUDENTS} from "../test_assets/users/students.testdata"; | import {TEST_STUDENTS} from "../test_assets/users/students.testdata.js"; | ||||||
| import {NotFoundException} from "../../src/exceptions/not-found-exception"; | import {NotFoundException} from "../../src/exceptions/not-found-exception.js"; | ||||||
| import {BadRequestException} from "../../src/exceptions/bad-request-exception"; | import {BadRequestException} from "../../src/exceptions/bad-request-exception.js"; | ||||||
| import {ConflictException} from "../../src/exceptions/conflict-exception"; | import {ConflictException} from "../../src/exceptions/conflict-exception.js"; | ||||||
| import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception"; | import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception.js"; | ||||||
|  | import {StudentDTO} from "../../src/interfaces/student.js"; | ||||||
| 
 | 
 | ||||||
| describe('Student controllers', () => { | describe('Student controllers', () => { | ||||||
|     let req: Partial<Request>; |     let req: Partial<Request>; | ||||||
|  | @ -26,6 +27,7 @@ describe('Student controllers', () => { | ||||||
| 
 | 
 | ||||||
|     let jsonMock: Mock; |     let jsonMock: Mock; | ||||||
|     let statusMock: Mock; |     let statusMock: Mock; | ||||||
|  |     let sendStatusMock: Mock; | ||||||
| 
 | 
 | ||||||
|     beforeAll(async () => { |     beforeAll(async () => { | ||||||
|         await setupTestApp(); |         await setupTestApp(); | ||||||
|  | @ -34,9 +36,11 @@ describe('Student controllers', () => { | ||||||
|     beforeEach(() => { |     beforeEach(() => { | ||||||
|         jsonMock = vi.fn(); |         jsonMock = vi.fn(); | ||||||
|         statusMock = vi.fn().mockReturnThis(); |         statusMock = vi.fn().mockReturnThis(); | ||||||
|  |         sendStatusMock = vi.fn().mockReturnThis(); | ||||||
|         res = { |         res = { | ||||||
|             json: jsonMock, |             json: jsonMock, | ||||||
|             status: statusMock, |             status: statusMock, | ||||||
|  |             sendStatus: sendStatusMock, | ||||||
|         }; |         }; | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -75,13 +79,13 @@ describe('Student controllers', () => { | ||||||
| 
 | 
 | ||||||
|         await createStudentHandler(req as Request, res as Response); |         await createStudentHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         expect(statusMock).toHaveBeenCalledWith(201); |         expect(sendStatusMock).toHaveBeenCalledWith(201); | ||||||
| 
 | 
 | ||||||
|         req = { params: { username: 'coolstudent' } }; |         req = { params: { username: 'coolstudent' } }; | ||||||
| 
 | 
 | ||||||
|         await deleteStudentHandler(req as Request, res as Response); |         await deleteStudentHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         expect(statusMock).toHaveBeenCalledWith(200); |         expect(sendStatusMock).toHaveBeenCalledWith(200); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -116,11 +120,11 @@ describe('Student controllers', () => { | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
| 
 | 
 | ||||||
|         // check is DireStraits is part of the student list
 |         // Check is DireStraits is part of the student list
 | ||||||
|         const studentUsernames = result.students.map((s: any) => s.username); |         const studentUsernames = result.students.map((s: StudentDTO) => s.username); | ||||||
|         expect(studentUsernames).toContain('DireStraits'); |         expect(studentUsernames).toContain('DireStraits'); | ||||||
| 
 | 
 | ||||||
|         // check length, +1 because of create
 |         // Check length, +1 because of create
 | ||||||
|         expect(result.students).toHaveLength(TEST_STUDENTS.length); |         expect(result.students).toHaveLength(TEST_STUDENTS.length); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -192,7 +196,7 @@ describe('Student controllers', () => { | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         // console.log('[JOIN REQUESTS]', result.requests);
 |         // Console.log('[JOIN REQUESTS]', result.requests);
 | ||||||
|         expect(result.requests.length).toBeGreaterThan(0); |         expect(result.requests.length).toBeGreaterThan(0); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -204,7 +208,7 @@ describe('Student controllers', () => { | ||||||
| 
 | 
 | ||||||
|         await createStudentRequestHandler(req as Request, res as Response); |         await createStudentRequestHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         expect(statusMock).toHaveBeenCalledWith(201); |         expect(sendStatusMock).toHaveBeenCalledWith(201); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('Create join request duplicate', async () => { |     it('Create join request duplicate', async () => { | ||||||
|  | @ -226,7 +230,7 @@ describe('Student controllers', () => { | ||||||
| 
 | 
 | ||||||
|         await deleteClassJoinRequestHandler(req as Request, res as Response); |         await deleteClassJoinRequestHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         expect(statusMock).toHaveBeenCalledWith(204); |         expect(sendStatusMock).toHaveBeenCalledWith(204); | ||||||
| 
 | 
 | ||||||
|         await expect(() => deleteClassJoinRequestHandler(req as Request, res as Response)) |         await expect(() => deleteClassJoinRequestHandler(req as Request, res as Response)) | ||||||
|             .rejects |             .rejects | ||||||
|  |  | ||||||
|  | @ -1,16 +1,17 @@ | ||||||
| import {beforeAll, beforeEach, describe, expect, it, Mock, vi} from "vitest"; | import {beforeAll, beforeEach, describe, expect, it, Mock, vi} from "vitest"; | ||||||
| import {Request, Response} from "express"; | import {Request, Response} from "express"; | ||||||
| import {setupTestApp} from "../setup-tests"; | import {setupTestApp} from "../setup-tests.js"; | ||||||
| import {NotFoundException} from "../../src/exceptions/not-found-exception"; | import {NotFoundException} from "../../src/exceptions/not-found-exception.js"; | ||||||
| import { | import { | ||||||
|     createTeacherHandler, |     createTeacherHandler, | ||||||
|     deleteTeacherHandler, |     deleteTeacherHandler, | ||||||
|     getAllTeachersHandler, getStudentJoinRequestHandler, getTeacherClassHandler, |     getAllTeachersHandler, getStudentJoinRequestHandler, getTeacherClassHandler, | ||||||
|     getTeacherHandler, getTeacherQuestionHandler, getTeacherStudentHandler, updateStudentJoinRequestHandler |     getTeacherHandler, getTeacherQuestionHandler, getTeacherStudentHandler, updateStudentJoinRequestHandler | ||||||
| } from "../../src/controllers/teachers"; | } from "../../src/controllers/teachers.js"; | ||||||
| import {BadRequestException} from "../../src/exceptions/bad-request-exception"; | import {BadRequestException} from "../../src/exceptions/bad-request-exception.js"; | ||||||
| import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception"; | import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception.js"; | ||||||
| import {getStudentRequestHandler} from "../../src/controllers/students"; | import {getStudentRequestHandler} from "../../src/controllers/students.js"; | ||||||
|  | import {TeacherDTO} from "../../src/interfaces/teacher.js"; | ||||||
| 
 | 
 | ||||||
| describe('Teacher controllers', () => { | describe('Teacher controllers', () => { | ||||||
|     let req: Partial<Request>; |     let req: Partial<Request>; | ||||||
|  | @ -18,6 +19,7 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|     let jsonMock: Mock; |     let jsonMock: Mock; | ||||||
|     let statusMock: Mock; |     let statusMock: Mock; | ||||||
|  |     let sendStatusMock: Mock; | ||||||
| 
 | 
 | ||||||
|     beforeAll(async () => { |     beforeAll(async () => { | ||||||
|         await setupTestApp(); |         await setupTestApp(); | ||||||
|  | @ -26,9 +28,11 @@ describe('Teacher controllers', () => { | ||||||
|     beforeEach(() => { |     beforeEach(() => { | ||||||
|         jsonMock = vi.fn(); |         jsonMock = vi.fn(); | ||||||
|         statusMock = vi.fn().mockReturnThis(); |         statusMock = vi.fn().mockReturnThis(); | ||||||
|  |         sendStatusMock = vi.fn().mockReturnThis(); | ||||||
|         res = { |         res = { | ||||||
|             json: jsonMock, |             json: jsonMock, | ||||||
|             status: statusMock, |             status: statusMock, | ||||||
|  |             sendStatus: sendStatusMock, | ||||||
|         }; |         }; | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -67,13 +71,13 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|         await createTeacherHandler(req as Request, res as Response); |         await createTeacherHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         expect(statusMock).toHaveBeenCalledWith(201); |         expect(sendStatusMock).toHaveBeenCalledWith(201); | ||||||
| 
 | 
 | ||||||
|         req = { params: { username: 'coolteacher' } }; |         req = { params: { username: 'coolteacher' } }; | ||||||
| 
 | 
 | ||||||
|         await deleteTeacherHandler(req as Request, res as Response); |         await deleteTeacherHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         expect(statusMock).toHaveBeenCalledWith(200); |         expect(sendStatusMock).toHaveBeenCalledWith(200); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('Create duplicate student', async () => { |     it('Create duplicate student', async () => { | ||||||
|  | @ -107,7 +111,7 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
| 
 | 
 | ||||||
|         const teacherUsernames = result.teachers.map((s: any) => s.username); |         const teacherUsernames = result.teachers.map((s: TeacherDTO) => s.username); | ||||||
|         expect(teacherUsernames).toContain('FooFighters'); |         expect(teacherUsernames).toContain('FooFighters'); | ||||||
| 
 | 
 | ||||||
|         expect(result.teachers).toHaveLength(4); |         expect(result.teachers).toHaveLength(4); | ||||||
|  | @ -133,7 +137,7 @@ describe('Teacher controllers', () => { | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() })); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() })); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         // console.log('[TEACHER CLASSES]', result);
 |         // Console.log('[TEACHER CLASSES]', result);
 | ||||||
|         expect(result.classes.length).toBeGreaterThan(0); |         expect(result.classes.length).toBeGreaterThan(0); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -148,13 +152,13 @@ describe('Teacher controllers', () => { | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ students: expect.anything() })); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ students: expect.anything() })); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         // console.log('[TEACHER STUDENTS]', result.students);
 |         // Console.log('[TEACHER STUDENTS]', result.students);
 | ||||||
|         expect(result.students.length).toBeGreaterThan(0); |         expect(result.students.length).toBeGreaterThan(0); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     /* |     /* | ||||||
| 
 | 
 | ||||||
|     it('Get teacher questions', async () => { |     It('Get teacher questions', async () => { | ||||||
|         req = { |         req = { | ||||||
|             params: { username: 'FooFighters' }, |             params: { username: 'FooFighters' }, | ||||||
|             query: { full: 'true' }, |             query: { full: 'true' }, | ||||||
|  | @ -184,7 +188,7 @@ describe('Teacher controllers', () => { | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ joinRequests: expect.anything() })); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ joinRequests: expect.anything() })); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         // console.log('[JOIN REQUESTS FOR CLASS]', result.joinRequests);
 |         // Console.log('[JOIN REQUESTS FOR CLASS]', result.joinRequests);
 | ||||||
|         expect(result.joinRequests.length).toBeGreaterThan(0); |         expect(result.joinRequests.length).toBeGreaterThan(0); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -197,7 +201,7 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|         await updateStudentJoinRequestHandler(req as Request, res as Response); |         await updateStudentJoinRequestHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         expect(statusMock).toHaveBeenCalledWith(200); |         expect(sendStatusMock).toHaveBeenCalledWith(200); | ||||||
| 
 | 
 | ||||||
|         req = { |         req = { | ||||||
|             params: { username: 'PinkFloyd' }, |             params: { username: 'PinkFloyd' }, | ||||||
|  | @ -205,8 +209,7 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|         await getStudentRequestHandler(req as Request, res as Response); |         await getStudentRequestHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const status: boolean = jsonMock.mock.lastCall?.[0].requests[0].status | ||||||
|         const status = result.requests[0].status |  | ||||||
|         expect(status).toBeTruthy; |         expect(status).toBeTruthy; | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ const controller = new TeacherController(); | ||||||
| 
 | 
 | ||||||
| describe('TeacherController', () => { | describe('TeacherController', () => { | ||||||
|     const newTeacher = { |     const newTeacher = { | ||||||
|         username: 'testteacher', |         username: 'testteacher3', | ||||||
|         firstName: 'Testy', |         firstName: 'Testy', | ||||||
|         lastName: 'McTestface', |         lastName: 'McTestface', | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl