Skip to content

Commit 7c10f2a

Browse files
committed
chore: tests that answers are actually configured correctly
Signed-off-by: Anthony D. Mays <[email protected]>
1 parent 674bb61 commit 7c10f2a

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

lesson_03/quiz/src/lesson3.test.ts

Lines changed: 31 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,43 @@ 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+
console.log('Checking answers for:', providerName);
102+
expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true);
103+
}
104+
}
105+
},
106+
);
107+
79108
maybeIt('checks for correct answers', async () => {
80-
const targetProviderName =
81-
process.env.PROVIDER_NAME?.toLowerCase().trim() || '';
109+
const targetProviderName = process.env.PROVIDER_NAME?.trim() || '';
82110

83111
if (!quizQuestionsByProvider.has(targetProviderName)) {
84112
throw new Error(`Unknown provider name: ${targetProviderName}`);
85113
}
86114

87115
for (const [providerName, questions] of quizQuestionsByProvider) {
88-
if (providerName !== process.env.PROVIDER_NAME?.toLowerCase().trim()) {
116+
if (providerName !== process.env.PROVIDER_NAME?.trim()) {
89117
continue;
90118
}
91119
for (const question of questions) {

0 commit comments

Comments
 (0)