Skip to content

Commit d7940e1

Browse files
authored
chore: tests that answers are actually configured correctly (#136)
* chore: tests that answers are actually configured correctly Signed-off-by: Anthony D. Mays <[email protected]> * chore: removes logging statement Signed-off-by: Anthony D. Mays <[email protected]> --------- Signed-off-by: Anthony D. Mays <[email protected]>
1 parent 674bb61 commit d7940e1

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

lesson_03/quiz/src/lesson3.test.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { beforeAll, describe, expect, it } from '@jest/globals';
33
import { Test, TestingModule } from '@nestjs/testing';
44
import {
55
AnswerChoice,
6+
MultipleChoiceQuizQuestion,
67
QuizConfig,
78
QuizQuestion,
89
} from 'codedifferently-instructional';
@@ -76,16 +77,42 @@ describe('Lesson3Test', () => {
7677

7778
const maybeIt = process.env.PROVIDER_NAME ? it : it.skip;
7879

80+
maybeIt(
81+
'checks multiple choice answers are configured correctly',
82+
async () => {
83+
for (const [providerName, questions] of quizQuestionsByProvider) {
84+
for (const question of questions) {
85+
if (!(question instanceof MultipleChoiceQuizQuestion)) {
86+
continue;
87+
}
88+
89+
// Assert that multiple choice questions have at least one correct answer.
90+
const choices = question.getAnswerChoices();
91+
const areAnswersValid = await Promise.all(
92+
[...choices].map(async (choice) => {
93+
return quizConfig.checkAnswer(
94+
providerName,
95+
question.getQuestionNumber(),
96+
choice,
97+
);
98+
}),
99+
);
100+
101+
expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true);
102+
}
103+
}
104+
},
105+
);
106+
79107
maybeIt('checks for correct answers', async () => {
80-
const targetProviderName =
81-
process.env.PROVIDER_NAME?.toLowerCase().trim() || '';
108+
const targetProviderName = process.env.PROVIDER_NAME?.trim() || '';
82109

83110
if (!quizQuestionsByProvider.has(targetProviderName)) {
84111
throw new Error(`Unknown provider name: ${targetProviderName}`);
85112
}
86113

87114
for (const [providerName, questions] of quizQuestionsByProvider) {
88-
if (providerName !== process.env.PROVIDER_NAME?.toLowerCase().trim()) {
115+
if (providerName !== process.env.PROVIDER_NAME?.trim()) {
89116
continue;
90117
}
91118
for (const question of questions) {

0 commit comments

Comments
 (0)