From 7c10f2a6a618341d11b0a0616cc7e2c5e3e25d0c Mon Sep 17 00:00:00 2001 From: "Anthony D. Mays" Date: Wed, 12 Mar 2025 05:16:54 +0000 Subject: [PATCH 1/2] chore: tests that answers are actually configured correctly Signed-off-by: Anthony D. Mays --- lesson_03/quiz/src/lesson3.test.ts | 34 +++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lesson_03/quiz/src/lesson3.test.ts b/lesson_03/quiz/src/lesson3.test.ts index 7903ffe71..b1fabc5bb 100644 --- a/lesson_03/quiz/src/lesson3.test.ts +++ b/lesson_03/quiz/src/lesson3.test.ts @@ -3,6 +3,7 @@ import { beforeAll, describe, expect, it } from '@jest/globals'; import { Test, TestingModule } from '@nestjs/testing'; import { AnswerChoice, + MultipleChoiceQuizQuestion, QuizConfig, QuizQuestion, } from 'codedifferently-instructional'; @@ -76,16 +77,43 @@ describe('Lesson3Test', () => { const maybeIt = process.env.PROVIDER_NAME ? it : it.skip; + 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, + ); + }), + ); + + console.log('Checking answers for:', providerName); + expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true); + } + } + }, + ); + maybeIt('checks for correct answers', async () => { - const targetProviderName = - process.env.PROVIDER_NAME?.toLowerCase().trim() || ''; + 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?.toLowerCase().trim()) { + if (providerName !== process.env.PROVIDER_NAME?.trim()) { continue; } for (const question of questions) { From c7168c30d7baf6145ff646431912f21af8541910 Mon Sep 17 00:00:00 2001 From: "Anthony D. Mays" Date: Wed, 12 Mar 2025 05:17:54 +0000 Subject: [PATCH 2/2] chore: removes logging statement Signed-off-by: Anthony D. Mays --- lesson_03/quiz/src/lesson3.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lesson_03/quiz/src/lesson3.test.ts b/lesson_03/quiz/src/lesson3.test.ts index b1fabc5bb..fd931b893 100644 --- a/lesson_03/quiz/src/lesson3.test.ts +++ b/lesson_03/quiz/src/lesson3.test.ts @@ -98,7 +98,6 @@ describe('Lesson3Test', () => { }), ); - console.log('Checking answers for:', providerName); expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true); } }