Skip to content

Commit f5338e4

Browse files
authored
Fix NaN from missing difficulty of book (#2918)
1 parent 607b351 commit f5338e4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Book } from '@seedcompany/scripture';
2+
import { difficultyOfBook } from './book-difficulty-factor';
3+
4+
test.each([...Book])(`difficultyOfBook is defined: %s`, (book) => {
5+
expect(difficultyOfBook(book)).toBeDefined();
6+
});

src/components/scripture/book-difficulty-factor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { Book } from '@seedcompany/scripture';
22
import { BookDifficulty } from './dto';
33

44
export const difficultyFactorOfBook = (book: Book): number =>
5-
factorMap[difficultyOfBook(book)];
5+
factorMap[difficultyOfBook(book)] ?? 0;
66

7-
export const difficultyOfBook = (book: Book) => difficultyMap[book.name];
7+
export const difficultyOfBook = (book: Book): BookDifficulty =>
8+
difficultyMap[book.name];
89

910
const factorMap: Record<BookDifficulty, number> = {
1011
Easy: 0.8,
@@ -13,7 +14,7 @@ const factorMap: Record<BookDifficulty, number> = {
1314
Hardest: 1.5625,
1415
};
1516

16-
const difficultyMap: Record<string, `${BookDifficulty}`> = {
17+
const difficultyMap: Record<string, BookDifficulty> = {
1718
Genesis: 'Normal',
1819
Exodus: 'Normal',
1920
Leviticus: 'Hard',
@@ -32,7 +33,7 @@ const difficultyMap: Record<string, `${BookDifficulty}`> = {
3233
Nehemiah: 'Normal',
3334
Esther: 'Easy',
3435
Job: 'Hardest',
35-
Psalm: 'Hard',
36+
Psalms: 'Hard',
3637
Proverbs: 'Hard',
3738
Ecclesiastes: 'Hard',
3839
'Song of Solomon': 'Hard',

0 commit comments

Comments
 (0)