@@ -80,52 +80,57 @@ describe('Lesson3Test', () => {
8080 maybeIt (
8181 'checks multiple choice answers are configured correctly' ,
8282 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 ) ;
83+ const { providerName, questions } = getQuestionsFromCurrentProvider ( ) ;
84+ for ( const question of questions ) {
85+ if ( ! ( question instanceof MultipleChoiceQuizQuestion ) ) {
86+ continue ;
10287 }
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 ) ;
103102 }
104103 } ,
105104 ) ;
106105
107106 maybeIt ( 'checks for correct answers' , async ( ) => {
107+ const { providerName, questions } = getQuestionsFromCurrentProvider ( ) ;
108+ for ( const question of questions ) {
109+ const actualAnswer = question . getAnswer ( ) ;
110+ softExpect ( actualAnswer ) . not . toBe ( AnswerChoice . UNANSWERED ) ;
111+ softExpect (
112+ await quizConfig . checkAnswer (
113+ providerName ,
114+ question . getQuestionNumber ( ) ,
115+ actualAnswer ,
116+ ) ,
117+ ) . toBe ( true ) ;
118+ }
119+ } ) ;
120+
121+ function getQuestionsFromCurrentProvider ( ) : {
122+ providerName : string ;
123+ questions : QuizQuestion [ ] ;
124+ } {
108125 const targetProviderName = process . env . PROVIDER_NAME ?. trim ( ) || '' ;
109126
110127 if ( ! quizQuestionsByProvider . has ( targetProviderName ) ) {
111128 throw new Error ( `Unknown provider name: ${ targetProviderName } ` ) ;
112129 }
113130
114- for ( const [ providerName , questions ] of quizQuestionsByProvider ) {
115- if ( providerName !== process . env . PROVIDER_NAME ?. trim ( ) ) {
116- continue ;
117- }
118- for ( const question of questions ) {
119- const actualAnswer = question . getAnswer ( ) ;
120- softExpect ( actualAnswer ) . not . toBe ( AnswerChoice . UNANSWERED ) ;
121- softExpect (
122- await quizConfig . checkAnswer (
123- providerName ,
124- question . getQuestionNumber ( ) ,
125- actualAnswer ,
126- ) ,
127- ) . toBe ( true ) ;
128- }
129- }
130- } ) ;
131+ return {
132+ providerName : targetProviderName ,
133+ questions : quizQuestionsByProvider . get ( targetProviderName ) || [ ] ,
134+ } ;
135+ }
131136} ) ;
0 commit comments