From 015f65ea9eaed7afa9ba7a6bfd051a45341cfee6 Mon Sep 17 00:00:00 2001 From: Caaf14 <cata-araya@outlook.com> Date: Tue, 16 Apr 2024 01:03:00 -0400 Subject: [PATCH] game service server tests --- .../game/services/game/game.service.spec.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/server/app/game/services/game/game.service.spec.ts b/server/app/game/services/game/game.service.spec.ts index b87e9a58..a342a917 100644 --- a/server/app/game/services/game/game.service.spec.ts +++ b/server/app/game/services/game/game.service.spec.ts @@ -96,5 +96,53 @@ describe('GameService', () => { }, ]); }); + + it('should add hidden random game when nQcm >= RANDOM_GAME_LENGTH', async () => { + const RANDOM_GAME_LENGTH = 10; + const mockQuizzes = [ + { + id: '123', + title: 'Quiz 1', + description: 'Description 1', + duration: 60, + isAvailable: true, + lastModification: new Date(0), + questions: [ + { + id: '456', + type: QuestionType.Qcm, + text: 'Question 1', + points: 10, + choices: [ + { + text: 'Choice 1', + isCorrect: true, + }, + { + text: 'Choice 2', + isCorrect: false, + }, + ], + }, + ], + } as unknown as QuizDocument, + ]; + + quizService.getAllAvailable.resolves(mockQuizzes); + questionBankService.getQcmCount.resolves(RANDOM_GAME_LENGTH + 1); + + const result = await service.getAvailableQuizzes(); + const expectedHiddenGame = service['getHiddenRandomGame'](); + + expect(result[0]).toEqual( + expect.objectContaining({ + // eslint-disable-next-line no-underscore-dangle -- mongodb + _id: expectedHiddenGame._id, + description: expectedHiddenGame.description, + duration: expectedHiddenGame.duration, + questions: expectedHiddenGame.questions, + }), + ); + }); }); }); -- GitLab