Skip to content

Commit 3366902

Browse files
committed
chore: adjusts instructions and adds another example.
1 parent 7a595ef commit 3366902

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

lesson_03/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,21 @@ npm start
4040
```
4141
4. Make at least three questions for your quiz and _leave them unanswered_.
4242
5. To provide answers, you will need to update the [quiz.yaml][test-config-file] file in the test directory. You can copy the example in the file to get started, but you must provide your own answers. To generate an encrypted answer, use [bcrypt.online](https://bcrypt.online).
43-
6. Before attempting to submit your quiz, make sure to run the formatter on the code and run the tests to ensure that you've updated things correctly. These commands must be run from the [quiz][quiz-folder] sub-folder just like the previous assignment:
43+
6. Lastly, you'll need to modify the [quizzes.module.ts][quizzes-module] file to include your quiz.
44+
7. Before attempting to submit your quiz, make sure to run the formatter on the code and run the tests to ensure that you've updated things correctly. These commands must be run from the [quiz][quiz-folder] sub-folder just like the previous assignment:
4445
```bash
4546
npm run lint
4647
npm run test
4748
```
48-
7. Once everything passes, submit a PR.
49+
8. Once everything passes, submit a PR.
4950

5051
**Note: If you want to check that you've encoded your answers correctly, you can update you quiz with the real answers and then run the tests using the command below.
5152
```bash
52-
RUN_SKIPPED=true npm run test
53+
PROVIDER_NAME=<Your provider name here> npm run test
5354
```
5455

5556
[quizzes-folder]: ./quiz/src/quizzes/
5657
[quiz-folder]: ./quiz/
5758
[quiz-example]: ./quiz/src/quizzes/anthony_mays_quiz.ts
58-
[test-config-file]: ./quiz/quiz.yaml
59+
[test-config-file]: ./quiz/quiz.yaml
60+
[quizzes-module]: ./quiz/src/quizzes/quizzes.module.ts

lesson_03/quiz/quiz.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ quiz:
33
anthonymays:
44
- $2y$10$8eHSzy3aCu4Ry3LzO9nWCeGpofSxsNVbnF.wCfn3ZADwQ6MEtN/KK
55
- $2y$10$55EXRjF26JIgebtoH800ZOJecfefvMgHicuxf/rwTENuxiUaFQcNe
6+
anotherone:
7+
- $2y$10$8eHSzy3aCu4Ry3LzO9nWCeGpofSxsNVbnF.wCfn3ZADwQ6MEtN/KK
8+
- $2y$10$dGB0CGv7.XQC5OqfyY6iXOiJsdVyxU3ve5YE0gt4m2I8P8H13lNXa

lesson_03/quiz/src/lesson3.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { Quizzes } from './quizzes/quizzes.module.js';
1414
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
1515
const __dirname = path.dirname(__filename); // get the name of the directory
1616
const softExpect = proxy(expect);
17-
const maybeIt = process.env.RUN_SKIPPED ? it : it.skip;
1817

1918
describe('Lesson3Test', () => {
2019
let moduleFixture: TestingModule;
@@ -75,8 +74,20 @@ describe('Lesson3Test', () => {
7574
}
7675
});
7776

77+
const maybeIt = process.env.PROVIDER_NAME ? it : it.skip;
78+
7879
maybeIt('checks for correct answers', async () => {
80+
const targetProviderName =
81+
process.env.PROVIDER_NAME?.toLowerCase().trim() || '';
82+
83+
if (!quizQuestionsByProvider.has(targetProviderName)) {
84+
throw new Error(`Unknown provider name: ${targetProviderName}`);
85+
}
86+
7987
for (const [providerName, questions] of quizQuestionsByProvider) {
88+
if (providerName !== process.env.PROVIDER_NAME?.toLowerCase().trim()) {
89+
continue;
90+
}
8091
for (const question of questions) {
8192
const actualAnswer = question.getAnswer();
8293
softExpect(actualAnswer).not.toBe(AnswerChoice.UNANSWERED);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
AnswerChoice,
3+
MultipleChoiceQuizQuestion,
4+
QuizQuestion,
5+
QuizQuestionProvider,
6+
} from 'codedifferently-instructional';
7+
8+
export class AnotherQuiz implements QuizQuestionProvider {
9+
getProviderName(): string {
10+
return 'anotherone';
11+
}
12+
13+
makeQuizQuestions(): QuizQuestion[] {
14+
return [AnotherQuiz.makeQuestion0(), AnotherQuiz.makeQuestion1()];
15+
}
16+
17+
private static makeQuestion0(): QuizQuestion {
18+
return new MultipleChoiceQuizQuestion(
19+
0,
20+
'Where in the world is Carmen Sandiego?',
21+
new Map<AnswerChoice, string>([
22+
[AnswerChoice.A, 'Botzwana'],
23+
[AnswerChoice.B, 'Nigeria'],
24+
[AnswerChoice.C, 'Brazil'],
25+
[AnswerChoice.D, 'France'],
26+
]),
27+
AnswerChoice.UNANSWERED,
28+
); // Replace `UNANSWERED` with the correct answer.
29+
}
30+
31+
private static makeQuestion1(): QuizQuestion {
32+
return new MultipleChoiceQuizQuestion(
33+
1,
34+
'What is the capital of the United States?',
35+
new Map<AnswerChoice, string>([
36+
[AnswerChoice.A, 'Sacramento'],
37+
[AnswerChoice.B, 'Washington D.C.'],
38+
[AnswerChoice.C, 'Austin'],
39+
[AnswerChoice.D, 'Saratoga'],
40+
]),
41+
AnswerChoice.UNANSWERED,
42+
); // Replace `UNANSWERED` with the correct answer.
43+
}
44+
}

lesson_03/quiz/src/quizzes/quizzes.module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { Module } from '@nestjs/common';
2+
import { AnotherQuiz } from './another_quiz.js';
23
import { AnthonyMaysQuiz } from './anthony_mays_quiz.js';
34

45
export const Quizzes = Symbol.for('Quizzes');
56

7+
// Add your quiz provider here.
8+
const QUIZ_PROVIDERS = [AnthonyMaysQuiz, AnotherQuiz];
9+
610
@Module({
711
providers: [
8-
AnthonyMaysQuiz,
12+
...QUIZ_PROVIDERS,
913
{
1014
provide: Quizzes,
1115
useFactory: (...args) => [...args],
12-
inject: [AnthonyMaysQuiz],
16+
inject: QUIZ_PROVIDERS,
1317
},
1418
],
1519
})

0 commit comments

Comments
 (0)