Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions lesson_03/quiz/src/lesson3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -76,16 +77,42 @@ 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,
);
}),
);

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) {
Expand Down