@@ -3,6 +3,7 @@ import { beforeAll, describe, expect, it } from '@jest/globals';
3
3
import { Test , TestingModule } from '@nestjs/testing' ;
4
4
import {
5
5
AnswerChoice ,
6
+ MultipleChoiceQuizQuestion ,
6
7
QuizConfig ,
7
8
QuizQuestion ,
8
9
} from 'codedifferently-instructional' ;
@@ -76,16 +77,43 @@ describe('Lesson3Test', () => {
76
77
77
78
const maybeIt = process . env . PROVIDER_NAME ? it : it . skip ;
78
79
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
+
79
108
maybeIt ( 'checks for correct answers' , async ( ) => {
80
- const targetProviderName =
81
- process . env . PROVIDER_NAME ?. toLowerCase ( ) . trim ( ) || '' ;
109
+ const targetProviderName = process . env . PROVIDER_NAME ?. trim ( ) || '' ;
82
110
83
111
if ( ! quizQuestionsByProvider . has ( targetProviderName ) ) {
84
112
throw new Error ( `Unknown provider name: ${ targetProviderName } ` ) ;
85
113
}
86
114
87
115
for ( const [ providerName , questions ] of quizQuestionsByProvider ) {
88
- if ( providerName !== process . env . PROVIDER_NAME ?. toLowerCase ( ) . trim ( ) ) {
116
+ if ( providerName !== process . env . PROVIDER_NAME ?. trim ( ) ) {
89
117
continue ;
90
118
}
91
119
for ( const question of questions ) {
0 commit comments