diff --git a/client/src/__tests__/services/WebsocketService.test.tsx b/client/src/__tests__/services/WebsocketService.test.tsx index 5a98e3e..e6035af 100644 --- a/client/src/__tests__/services/WebsocketService.test.tsx +++ b/client/src/__tests__/services/WebsocketService.test.tsx @@ -63,12 +63,12 @@ describe('WebSocketService', () => { }); }); - test('endQuiz should emit end-quiz event with correct parameters', () => { + test('endQuiz should emit end-questionnaire event with correct parameters', () => { const roomName = 'testRoom'; mockSocket = WebsocketService.connect(ENV_VARIABLES.VITE_BACKEND_SOCKET_URL); WebsocketService.endQuiz(roomName); - expect(mockSocket.emit).toHaveBeenCalledWith('end-quiz', { roomName }); + expect(mockSocket.emit).toHaveBeenCalledWith('end-questionnaire', { roomName }); }); test('joinRoom should emit join-room event with correct parameters', () => { diff --git a/client/src/pages/Teacher/ManageRoom/ManageRoom.tsx b/client/src/pages/Teacher/ManageRoom/ManageRoom.tsx index 7af12f9..9ac16e5 100644 --- a/client/src/pages/Teacher/ManageRoom/ManageRoom.tsx +++ b/client/src/pages/Teacher/ManageRoom/ManageRoom.tsx @@ -28,7 +28,7 @@ const ManageRoom: React.FC = () => { const [roomName, setRoomName] = useState(''); const [socket, setSocket] = useState(null); const [students, setStudents] = useState([]); - const quizId = useParams<{ id: string }>(); + const questionnaireId = useParams<{ id: string }>(); const [quizQuestions, setQuizQuestions] = useState(); const [quiz, setQuiz] = useState(null); const [quizMode, setQuizMode] = useState<'teacher' | 'student'>('teacher'); @@ -37,14 +37,14 @@ const ManageRoom: React.FC = () => { const [quizStarted, setQuizStarted] = useState(false); useEffect(() => { - if (quizId.id) { + if (questionnaireId.id) { const fetchquiz = async () => { - const quiz = await ApiService.getQuiz(quizId.id as string); + const quiz = await ApiService.getQuiz(questionnaireId.id as string); if (!quiz) { - window.alert(`Une erreur est survenue.\n Le quiz ${quizId.id} n'a pas été trouvé\nVeuillez réessayer plus tard`) - console.error('Quiz not found for id:', quizId.id); + window.alert(`Une erreur est survenue.\n Le questionnaire ${questionnaireId.id} n'a pas été trouvé\nVeuillez réessayer plus tard`) + console.error('Questionnaire not found for id:', questionnaireId.id); navigate('/teacher/dashboard'); return; } @@ -64,12 +64,12 @@ const ManageRoom: React.FC = () => { fetchquiz(); } else { - window.alert(`Une erreur est survenue.\n Le quiz ${quizId.id} n'a pas été trouvé\nVeuillez réessayer plus tard`) - console.error('Quiz not found for id:', quizId.id); + window.alert(`Une erreur est survenue.\n Le questionnaire ${questionnaireId} n'a pas été trouvé\nVeuillez réessayer plus tard`) + console.error('Questionnaire not found for id:', questionnaireId.id); navigate('/teacher/dashboard'); return; } - }, [quizId]); + }, [questionnaireId]); const disconnectWebSocket = () => { if (socket) { diff --git a/client/src/services/ApiService.tsx b/client/src/services/ApiService.tsx index ef124b4..980d9ab 100644 --- a/client/src/services/ApiService.tsx +++ b/client/src/services/ApiService.tsx @@ -556,14 +556,14 @@ class ApiService { * @returns quiz if successful * @returns A error string if unsuccessful, */ - public async getQuiz(quizId: string): Promise { + public async getQuiz(questionnaireId: string): Promise { try { - if (!quizId) { + if (!questionnaireId) { throw new Error(`Le quizId est requis.`); } - const url: string = this.constructRequestUrl(`/quiz/get/${quizId}`); + const url: string = this.constructRequestUrl(`/questionnaire/get/${questionnaireId}`); const headers = this.constructRequestHeaders(); const result: AxiosResponse = await axios.get(url, { headers: headers }); diff --git a/server/__tests__/folders.test.js b/server/__tests__/folders.test.js index acde762..d5c0deb 100644 --- a/server/__tests__/folders.test.js +++ b/server/__tests__/folders.test.js @@ -1,12 +1,12 @@ const Folders = require('../models/folders'); const ObjectId = require('mongodb').ObjectId; -const Quizzes = require('../models/quiz'); +const Questionnaires = require('../models/questionnaires'); describe('Folders', () => { let folders; let db; let collection; - let quizzes; + let questionnaires; beforeEach(() => { jest.clearAllMocks(); // Clear any previous mock calls @@ -28,8 +28,8 @@ describe('Folders', () => { collection: jest.fn().mockReturnValue(collection), }; - quizzes = new Quizzes(db); - folders = new Folders(db, quizzes); + questionnaires = new Questionnaires(db); + folders = new Folders(db, questionnaires); }); @@ -127,8 +127,8 @@ describe('Folders', () => { it('should return the content of a folder', async () => { const folderId = '60c72b2f9b1d8b3a4c8e4d3b'; const content = [ - { title: 'Quiz 1', content: [] }, - { title: 'Quiz 2', content: [] }, + { title: 'Questionnaire 1', content: [] }, + { title: 'Questionnaire 2', content: [] }, ]; // Mock the database response @@ -166,8 +166,8 @@ describe('Folders', () => { collection.deleteOne.mockResolvedValue({ deletedCount: 1 }); - // Mock the folders.quizModel.deleteQuizzesByFolderId() - jest.spyOn(quizzes, 'deleteQuizzesByFolderId').mockResolvedValue(true); + // Mock the folders.questionnaireModel.deleteQuestionnairesByFolderId() + jest.spyOn(questionnaires, 'deleteQuestionnairesByFolderId').mockResolvedValue(true); const result = await folders.delete(folderId); @@ -263,10 +263,10 @@ describe('Folders', () => { const createSpy = jest.spyOn(folders, 'create').mockResolvedValue(new ObjectId()); // mock the folder.getContent method - jest.spyOn(folders, 'getContent').mockResolvedValue([{ title: 'Quiz 1', content: [] }]); + jest.spyOn(folders, 'getContent').mockResolvedValue([{ title: 'Questionnaire 1', content: [] }]); - // Mock the quizzes.create method - jest.spyOn(quizzes, 'create').mockResolvedValue(new ObjectId()); + // Mock the Questionnaires.create method + jest.spyOn(questionnaires, 'create').mockResolvedValue(new ObjectId()); const result = await folders.duplicate(folderId, userId); @@ -276,8 +276,8 @@ describe('Folders', () => { expect(createSpy).toHaveBeenCalledWith(duplicatedFolder.title, userId); // expect the getContent method was called expect(folders.getContent).toHaveBeenCalledWith(folderId); - // expect the quizzes.create method was called - expect(quizzes.create).toHaveBeenCalledWith('Quiz 1', [], expect.any(String), userId); + // expect the questionnaires.create method was called + expect(questionnaires.create).toHaveBeenCalledWith('Questionnaire 1', [], expect.any(String), userId); expect(result).toBeDefined(); }); @@ -333,20 +333,20 @@ describe('Folders', () => { const folderId = '60c72b2f9b1d8b3a4c8e4d3b'; const userId = '12345'; const newFolderId = new ObjectId(); - // Mock some quizzes that are in folder.content + // Mock some questionnaires that are in folder.content const sourceFolder = { title: 'Test Folder', content: [ - { title: 'Quiz 1', content: [] }, - { title: 'Quiz 2', content: [] }, + { title: 'Questionnaire 1', content: [] }, + { title: 'Questionnaire 2', content: [] }, ], }; // Mock the response from getFolderWithContent jest.spyOn(folders, 'getFolderWithContent').mockResolvedValue(sourceFolder); jest.spyOn(folders, 'create').mockResolvedValue(newFolderId); - // Mock the response from Quiz.createQuiz - jest.spyOn(quizzes, 'create').mockImplementation(() => {}); + // Mock the response from Questionnaire.createQuestionnaire + jest.spyOn(questionnaires, 'create').mockImplementation(() => {}); const result = await folders.copy(folderId, userId); @@ -384,8 +384,8 @@ describe('Folders', () => { }; const content = { content : [ - { title: 'Quiz 1', content: [] }, - { title: 'Quiz 2', content: [] }, + { title: 'Questionnaire 1', content: [] }, + { title: 'Questionnaire 2', content: [] }, ]}; // Mock the response from getFolderById diff --git a/server/__tests__/quizzes.test.js b/server/__tests__/questionnaires.test.js similarity index 52% rename from server/__tests__/quizzes.test.js rename to server/__tests__/questionnaires.test.js index 086ab7f..fca6474 100644 --- a/server/__tests__/quizzes.test.js +++ b/server/__tests__/questionnaires.test.js @@ -1,9 +1,9 @@ const { ObjectId } = require('mongodb'); -const Quizzes = require('../models/quiz'); // Adjust the path as necessary +const Questionnaires = require('../models/questionnaires'); // Adjust the path as necessary -describe('Quizzes', () => { +describe('Questionnaires', () => { let db; - let quizzes; + let questionnaires; let collection; beforeEach(() => { @@ -28,14 +28,14 @@ describe('Quizzes', () => { }), }; - // Initialize the Quiz model with the mocked db - quizzes = new Quizzes(db); + // Initialize the Questionnaire model with the mocked db + questionnaires = new Questionnaires(db); }); describe('create', () => { - it('should create a new quiz if it does not exist', async () => { - const title = 'Test Quiz'; - const content = 'This is a test quiz.'; + it('should create a new questionnaire if it does not exist', async () => { + const title = 'Test Questionnaire'; + const content = 'This is a test questionnaire.'; const folderId = '507f1f77bcf86cd799439011'; const userId = '12345'; @@ -43,7 +43,7 @@ describe('Quizzes', () => { collection.findOne.mockResolvedValue(null); collection.insertOne.mockResolvedValue({ insertedId: new ObjectId() }); - const result = await quizzes.create(title, content, folderId, userId); + const result = await questionnaires.create(title, content, folderId, userId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); @@ -59,104 +59,104 @@ describe('Quizzes', () => { expect(result).not.toBeNull(); }); - it('should throw exception if the quiz already exists', async () => { - const title = 'Test Quiz'; - const content = 'This is a test quiz.'; + it('should throw exception if the questionnaire already exists', async () => { + const title = 'Test Questionnaire'; + const content = 'This is a test questionnaire.'; const folderId = '507f1f77bcf86cd799439011'; const userId = '12345'; // Mock the database response collection.findOne.mockResolvedValue({ title }); - await expect(quizzes.create(title, content, folderId, userId)).rejects.toThrow(`Quiz already exists with title: ${title}, folderId: ${folderId}, userId: ${userId}`); + await expect(questionnaires.create(title, content, folderId, userId)).rejects.toThrow(`Questionnaire already exists with title: ${title}, folderId: ${folderId}, userId: ${userId}`); }); }); describe('getOwner', () => { - it('should return the owner of the quiz', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + it('should return the owner of the questionnaire', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; const userId = '12345'; // Mock the database response collection.findOne.mockResolvedValue({ userId }); - const result = await quizzes.getOwner(quizId); + const result = await questionnaires.getOwner(questionnaireId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); - expect(collection.findOne).toHaveBeenCalledWith({ _id: ObjectId.createFromHexString(quizId) }); + expect(collection.findOne).toHaveBeenCalledWith({ _id: ObjectId.createFromHexString(questionnaireId) }); expect(result).toBe(userId); }); }); describe('getContent', () => { - it('should return the content of the quiz', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; - const content = 'This is a test quiz.'; + it('should return the content of the questionnaire', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; + const content = 'This is a test questionnaire.'; // Mock the database response collection.findOne.mockResolvedValue({ content }); - const result = await quizzes.getContent(quizId); + const result = await questionnaires.getContent(questionnaireId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); - expect(collection.findOne).toHaveBeenCalledWith({ _id: ObjectId.createFromHexString(quizId) }); + expect(collection.findOne).toHaveBeenCalledWith({ _id: ObjectId.createFromHexString(questionnaireId) }); expect(result).toEqual({ content }); }); }); describe('delete', () => { - it('should delete the quiz', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + it('should delete the questionnaire', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; // Mock the database response collection.deleteOne.mockResolvedValue({deletedCount: 1}); - await quizzes.delete(quizId); + await questionnaires.delete(questionnaireId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); - expect(collection.deleteOne).toHaveBeenCalledWith({ _id: ObjectId.createFromHexString(quizId) }); + expect(collection.deleteOne).toHaveBeenCalledWith({ _id: ObjectId.createFromHexString(questionnaireId) }); }); - it('should return false if the quiz does not exist', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + it('should return false if the questionnaire does not exist', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; // Mock the database response collection.deleteOne.mockResolvedValue({deletedCount: 0}); - const result = await quizzes.delete(quizId); + const result = await questionnaires.delete(questionnaireId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); - expect(collection.deleteOne).toHaveBeenCalledWith({ _id: ObjectId.createFromHexString(quizId) }); + expect(collection.deleteOne).toHaveBeenCalledWith({ _id: ObjectId.createFromHexString(questionnaireId) }); expect(result).toBe(false); }); }); - // deleteQuizzesByFolderId - describe('deleteQuizzesByFolderId', () => { - it('should delete all quizzes in a folder', async () => { + // deleteQuestionnairesByFolderId + describe('deleteQuestionnairesByFolderId', () => { + it('should delete all questionnaires in a folder', async () => { const folderId = '60c72b2f9b1d8b3a4c8e4d3b'; // Mock the database response collection.deleteMany.mockResolvedValue({deletedCount: 2}); - await quizzes.deleteQuizzesByFolderId(folderId); + await questionnaires.deleteQuestionnairesByFolderId(folderId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); expect(collection.deleteMany).toHaveBeenCalledWith({ folderId }); }); - it('should return false if no quizzes are deleted', async () => { + it('should return false if no questionnaires are deleted', async () => { const folderId = '60c72b2f9b1d8b3a4c8e4d3b'; // Mock the database response collection.deleteMany.mockResolvedValue({deletedCount: 0}); - const result = await quizzes.deleteQuizzesByFolderId(folderId); + const result = await questionnaires.deleteQuestionnairesByFolderId(folderId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); @@ -167,38 +167,38 @@ describe('Quizzes', () => { // update describe('update', () => { - it('should update the title and content of the quiz', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; - const newTitle = 'Updated Quiz'; - const newContent = 'This is an updated quiz.'; + it('should update the title and content of the questionnaire', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; + const newTitle = 'Updated Questionnaire'; + const newContent = 'This is an updated questionnaire.'; // Mock the database response collection.updateOne.mockResolvedValue({modifiedCount: 1}); - await quizzes.update(quizId, newTitle, newContent); + await questionnaires.update(questionnaireId, newTitle, newContent); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); expect(collection.updateOne).toHaveBeenCalledWith( - { _id: ObjectId.createFromHexString(quizId) }, + { _id: ObjectId.createFromHexString(questionnaireId) }, { $set: { title: newTitle, content: newContent, updated_at: expect.any(Date) } } ); }); - it('should return false if the quiz does not exist', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; - const newTitle = 'Updated Quiz'; - const newContent = 'This is an updated quiz.'; + it('should return false if the questionnaire does not exist', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; + const newTitle = 'Updated Questionnaire'; + const newContent = 'This is an updated questionnaire.'; // Mock the database response collection.updateOne.mockResolvedValue({modifiedCount: 0}); - const result = await quizzes.update(quizId, newTitle, newContent); + const result = await questionnaires.update(questionnaireId, newTitle, newContent); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); expect(collection.updateOne).toHaveBeenCalledWith( - { _id: ObjectId.createFromHexString(quizId) }, + { _id: ObjectId.createFromHexString(questionnaireId) }, { $set: { title: newTitle, content: newContent, updated_at: expect.any(Date) } } ); expect(result).toBe(false); @@ -207,36 +207,36 @@ describe('Quizzes', () => { // move describe('move', () => { - it('should move the quiz to a new folder', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + it('should move the questionnaire to a new folder', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; const newFolderId = '507f1f77bcf86cd799439011'; // Mock the database response collection.updateOne.mockResolvedValue({modifiedCount: 1}); - await quizzes.move(quizId, newFolderId); + await questionnaires.move(questionnaireId, newFolderId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); expect(collection.updateOne).toHaveBeenCalledWith( - { _id: ObjectId.createFromHexString(quizId) }, + { _id: ObjectId.createFromHexString(questionnaireId) }, { $set: { folderId: newFolderId } } ); }); - it('should return false if the quiz does not exist', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + it('should return false if the questionnaire does not exist', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; const newFolderId = '507f1f77bcf86cd799439011'; // Mock the database response collection.updateOne.mockResolvedValue({modifiedCount: 0}); - const result = await quizzes.move(quizId, newFolderId); + const result = await questionnaires.move(questionnaireId, newFolderId); expect(db.connect).toHaveBeenCalled(); expect(db.getConnection).toHaveBeenCalled(); expect(collection.updateOne).toHaveBeenCalledWith( - { _id: ObjectId.createFromHexString(quizId) }, + { _id: ObjectId.createFromHexString(questionnaireId) }, { $set: { folderId: newFolderId } } ); expect(result).toBe(false); @@ -246,102 +246,102 @@ describe('Quizzes', () => { // duplicate describe('duplicate', () => { - it('should duplicate the quiz and return the new quiz ID', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + it('should duplicate the questionnaire and return the new questionnaire ID', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; const userId = '12345'; - const newQuizId = ObjectId.createFromTime(Math.floor(Date.now() / 1000)); // Corrected ObjectId creation - const sourceQuiz = { - title: 'Test Quiz', - content: 'This is a test quiz.', + const newQuestionnaireId = ObjectId.createFromTime(Math.floor(Date.now() / 1000)); // Corrected ObjectId creation + const sourceQuestionnaire = { + title: 'Test Questionnaire', + content: 'This is a test questionnaire.', }; - const createMock = jest.spyOn(quizzes, 'create').mockResolvedValue(newQuizId); + const createMock = jest.spyOn(questionnaires, 'create').mockResolvedValue(newQuestionnaireId); // mock the findOne method jest.spyOn(collection, 'findOne') - .mockResolvedValueOnce(sourceQuiz) // source quiz exists + .mockResolvedValueOnce(sourceQuestionnaire) // source questionnaire exists .mockResolvedValueOnce(null); // new name is not found - const result = await quizzes.duplicate(quizId, userId); + const result = await questionnaires.duplicate(questionnaireId, userId); - expect(result).toBe(newQuizId); + expect(result).toBe(newQuestionnaireId); // Ensure mocks were called correctly expect(createMock).toHaveBeenCalledWith( - sourceQuiz.title + ' (1)', - sourceQuiz.content, + sourceQuestionnaire.title + ' (1)', + sourceQuestionnaire.content, undefined, userId ); }); - // Add test case for quizExists (name with number in parentheses) - it('should create a new title if the quiz title already exists and ends with " (1)"', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + // Add test case for questionnaireExists (name with number in parentheses) + it('should create a new title if the questionnaire title already exists and ends with " (1)"', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; const userId = '12345'; - const newQuizId = ObjectId.createFromTime(Math.floor(Date.now() / 1000)); - const sourceQuiz = { - title: 'Test Quiz (1)', - content: 'This is a test quiz.', + const newQuestionanireId = ObjectId.createFromTime(Math.floor(Date.now() / 1000)); + const sourceQuestionnaire = { + title: 'Test Questionnaire (1)', + content: 'This is a test questionnaire.', }; - const createMock = jest.spyOn(quizzes, 'create').mockResolvedValue(newQuizId); + const createMock = jest.spyOn(questionnaires, 'create').mockResolvedValue(newQuestionanireId); // mock the findOne method jest.spyOn(collection, 'findOne') - .mockResolvedValueOnce(sourceQuiz) // source quiz exists + .mockResolvedValueOnce(sourceQuestionnaire) // source questionnaire exists .mockResolvedValueOnce(null); // new name is not found - const result = await quizzes.duplicate(quizId, userId); + const result = await questionnaires.duplicate(questionnaireId, userId); - expect(result).toBe(newQuizId); + expect(result).toBe(newQuestionanireId); // Ensure mocks were called correctly expect(createMock).toHaveBeenCalledWith( - 'Test Quiz (2)', - sourceQuiz.content, + 'Test Questionnaire (2)', + sourceQuestionnaire.content, undefined, userId ); }); // test case for duplication of "C (1)" but "C (2)" already exists, so it should create "C (3)" - it('should create a new title if the quiz title already exists and ends with " (n)" but the incremented n also exists', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + it('should create a new title if the questionnaire title already exists and ends with " (n)" but the incremented n also exists', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; const userId = '12345'; - const newQuizId = ObjectId.createFromTime(Math.floor(Date.now() / 1000)); - const sourceQuiz = { - title: 'Test Quiz (1)', - content: 'This is a test quiz.', + const newQuestionnaireId = ObjectId.createFromTime(Math.floor(Date.now() / 1000)); + const sourceQuestionnaire = { + title: 'Test Questionnaire (1)', + content: 'This is a test questionnaire.', }; - const createMock = jest.spyOn(quizzes, 'create').mockResolvedValue(newQuizId); + const createMock = jest.spyOn(questionnaires, 'create').mockResolvedValue(newQuestionnaireId); // mock the findOne method jest.spyOn(collection, 'findOne') - .mockResolvedValueOnce(sourceQuiz) // source quiz exists - .mockResolvedValueOnce({ title: 'Test Quiz (2)' }) // new name collision + .mockResolvedValueOnce(sourceQuestionnaire) // source questionnaire exists + .mockResolvedValueOnce({ title: 'Test Questionnaire (2)' }) // new name collision .mockResolvedValueOnce(null); // final new name is not found - const result = await quizzes.duplicate(quizId, userId); + const result = await questionnaires.duplicate(questionnaireId, userId); - expect(result).toBe(newQuizId); + expect(result).toBe(newQuestionnaireId); // Ensure mocks were called correctly expect(createMock).toHaveBeenCalledWith( - 'Test Quiz (3)', - sourceQuiz.content, + 'Test Questionnaire (3)', + sourceQuestionnaire.content, undefined, userId ); }); - it('should throw an error if the quiz does not exist', async () => { - const quizId = '60c72b2f9b1d8b3a4c8e4d3b'; + it('should throw an error if the questionnaire does not exist', async () => { + const questionnaireId = '60c72b2f9b1d8b3a4c8e4d3b'; const userId = '12345'; // Mock the response from getContent - jest.spyOn(quizzes, 'getContent').mockResolvedValue(null); + jest.spyOn(questionnaires, 'getContent').mockResolvedValue(null); - await expect(quizzes.duplicate(quizId, userId)).rejects.toThrow(); + await expect(questionnaires.duplicate(questionnaireId, userId)).rejects.toThrow(); }); }); }); diff --git a/server/__tests__/socket.test.js b/server/__tests__/socket.test.js index 95c404f..1417872 100644 --- a/server/__tests__/socket.test.js +++ b/server/__tests__/socket.test.js @@ -154,11 +154,11 @@ describe("websocket server", () => { }); }); - test("should end quiz", (done) => { - teacherSocket.emit("end-quiz", { + test("should end questionnaire", (done) => { + teacherSocket.emit("end-questionnaire", { roomName: "ROOM1", }); - studentSocket.on("end-quiz", () => { + studentSocket.on("end-questionnaire", () => { done(); }); }); diff --git a/server/__tests__/users.test.js b/server/__tests__/users.test.js index 2c6b4eb..f13e6e2 100644 --- a/server/__tests__/users.test.js +++ b/server/__tests__/users.test.js @@ -1,6 +1,6 @@ const Users = require('../models/users'); const bcrypt = require('bcrypt'); -const Quizzes = require('../models/quiz'); +const Questionnaires = require('../models/questionnaires'); const Folders = require('../models/folders'); const { ObjectId } = require('mongodb'); @@ -26,8 +26,8 @@ describe('Users', () => { deleteOne: jest.fn(), }; - const quizModel = new Quizzes(db); - const foldersModel = new Folders(db, quizModel); + const questionnaireModel = new Questionnaires(db); + const foldersModel = new Folders(db, questionnaireModel); users = new Users(db, foldersModel); }); diff --git a/server/app.js b/server/app.js index f8b261e..f65fd66 100644 --- a/server/app.js +++ b/server/app.js @@ -24,7 +24,7 @@ const usersController = require('./controllers/users.js'); const usersControllerInstance = new usersController(userModel); const foldersController = require('./controllers/folders.js'); const foldersControllerInstance = new foldersController(foldersModel); -const questionnaireController = require('./controllers/questionnaire.js'); +const questionnaireController = require('./controllers/questionnaires.js'); const questionnaireControllerInstance = new questionnaireController(questionnaireModel, foldersModel); const imagesController = require('./controllers/images.js'); const imagesControllerInstance = new imagesController(imageModel);