diff --git a/lesson_03/quiz/src/lesson3.test.ts b/lesson_03/quiz/src/lesson3.test.ts index fd931b893..d4de9b26c 100644 --- a/lesson_03/quiz/src/lesson3.test.ts +++ b/lesson_03/quiz/src/lesson3.test.ts @@ -80,52 +80,57 @@ describe('Lesson3Test', () => { maybeIt( 'checks multiple choice answers are configured correctly', async () => { - for (const [providerName, questions] of quizQuestionsByProvider) { - for (const question of questions) { - if (!(question instanceof MultipleChoiceQuizQuestion)) { - continue; - } - - // Assert that multiple choice questions have at least one correct answer. - const choices = question.getAnswerChoices(); - const areAnswersValid = await Promise.all( - [...choices].map(async (choice) => { - return quizConfig.checkAnswer( - providerName, - question.getQuestionNumber(), - choice, - ); - }), - ); - - expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true); + const { providerName, questions } = getQuestionsFromCurrentProvider(); + for (const question of questions) { + if (!(question instanceof MultipleChoiceQuizQuestion)) { + continue; } + + // Assert that multiple choice questions have at least one correct answer. + const choices = question.getAnswerChoices(); + const areAnswersValid = await Promise.all( + [...choices].map(async (choice) => { + return quizConfig.checkAnswer( + providerName, + question.getQuestionNumber(), + choice, + ); + }), + ); + + expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true); } }, ); maybeIt('checks for correct answers', async () => { + const { providerName, questions } = getQuestionsFromCurrentProvider(); + for (const question of questions) { + const actualAnswer = question.getAnswer(); + softExpect(actualAnswer).not.toBe(AnswerChoice.UNANSWERED); + softExpect( + await quizConfig.checkAnswer( + providerName, + question.getQuestionNumber(), + actualAnswer, + ), + ).toBe(true); + } + }); + + function getQuestionsFromCurrentProvider(): { + providerName: string; + questions: QuizQuestion[]; + } { const targetProviderName = process.env.PROVIDER_NAME?.trim() || ''; if (!quizQuestionsByProvider.has(targetProviderName)) { throw new Error(`Unknown provider name: ${targetProviderName}`); } - for (const [providerName, questions] of quizQuestionsByProvider) { - if (providerName !== process.env.PROVIDER_NAME?.trim()) { - continue; - } - for (const question of questions) { - const actualAnswer = question.getAnswer(); - softExpect(actualAnswer).not.toBe(AnswerChoice.UNANSWERED); - softExpect( - await quizConfig.checkAnswer( - providerName, - question.getQuestionNumber(), - actualAnswer, - ), - ).toBe(true); - } - } - }); + return { + providerName: targetProviderName, + questions: quizQuestionsByProvider.get(targetProviderName) || [], + }; + } });