Skip to content

Commit

Permalink
fix: ensure undefined values are removed in cleanup
Browse files Browse the repository at this point in the history
This fixes a crasher.
  • Loading branch information
aalemayhu committed Oct 23, 2024
1 parent 7374194 commit 32eb478
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
7 changes: 7 additions & 0 deletions src/lib/parser/Deck.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Deck from './Deck';

describe('Deck', () => {
test('handles cleaning undefined notes', () => {
expect(Deck.CleanCards([undefined])).toStrictEqual([]);

Check failure on line 5 in src/lib/parser/Deck.test.ts

View workflow job for this annotation

GitHub Actions / build (20.18.0)

Type 'undefined' is not assignable to type 'Note'.
});
});
10 changes: 5 additions & 5 deletions src/lib/parser/Deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ export default class Deck {
) {
this.settings = settings;
this.name = name;
this.cards = cards;
this.cards = cards ?? [];
this.image = image;
this.style = style;
this.id = id;
console.log(`New Deck with ${this.cards.length} cards`);
}

static CleanCards(cards: Note[]) {
return cards.filter(
(note) =>
note.isValidClozeNote() ||
note.isValidInputNote() ||
note.isValidBasicNote()
note &&
(note.isValidClozeNote() ||
note.isValidInputNote() ||
note.isValidBasicNote())
);
}

Expand Down
38 changes: 19 additions & 19 deletions src/services/NotionService/BlockHandler/BlockHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const loadCards = async (
decks: [],
parentName: '',
});
return decks[0].cards;
return decks[0].cards ?? [];
};

async function findCardByName(
Expand Down Expand Up @@ -247,24 +247,24 @@ describe('BlockHandler', () => {
expect(flashcards.length).toBe(1);
});

test('Add Notion Link', async () => {
const expected =
'https://www.notion.so/Notion-API-Test-Page-3ce6b147ac8a425f836b51cc21825b85#e5201f35c72240d38e3a5d218e5d80a5';
const flashcards = await loadCards(
{
'add-notion-link': 'true',
parentBlockId: examplId,
},
examplId,
new Workspace(true, 'fs'),
new ParserRules()
);
const card = flashcards.find((f) =>
f.name.includes('1 - This is a basic card')
);
expect(card).toBeTruthy();
expect(card?.notionLink).toBe(expected);
});
test('Add Notion Link', async () => {
const expected =
'https://www.notion.so/Notion-API-Test-Page-3ce6b147ac8a425f836b51cc21825b85#e5201f35c72240d38e3a5d218e5d80a5';
const flashcards = await loadCards(
{
'add-notion-link': 'true',
parentBlockId: examplId,
},
examplId,
new Workspace(true, 'fs'),
new ParserRules()
);
const card = flashcards.find((f) =>
f.name.includes('1 - This is a basic card')
);
expect(card).toBeTruthy();
expect(card?.notionLink).toBe(expected);
});

test.todo('Maximum One Toggle Per Card');
test.todo('Use All Toggle Lists');
Expand Down

0 comments on commit 32eb478

Please sign in to comment.