diff --git a/src/lib/parser/Deck.ts b/src/lib/parser/Deck.ts index 2982d28c2..b80e8b537 100644 --- a/src/lib/parser/Deck.ts +++ b/src/lib/parser/Deck.ts @@ -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()) ); } diff --git a/src/lib/parser/experimental/FallbackParser.ts b/src/lib/parser/experimental/FallbackParser.ts index 9b5510ab5..5e8821496 100644 --- a/src/lib/parser/experimental/FallbackParser.ts +++ b/src/lib/parser/experimental/FallbackParser.ts @@ -138,12 +138,11 @@ class FallbackParser { clean = false; } - cards = Deck.CleanCards(cards); if (cards.length > 0) { decks.push( new Deck( deckName, - clean ? Deck.CleanCards(cards) : cards, + clean ? Deck.CleanCards(cards) : cards, // Do not clean csv files '', // skip cover image '', // skip style get16DigitRandomId(), diff --git a/src/services/NotionService/BlockHandler/BlockHandler.test.ts b/src/services/NotionService/BlockHandler/BlockHandler.test.ts index 52a00c94e..14ea16777 100644 --- a/src/services/NotionService/BlockHandler/BlockHandler.test.ts +++ b/src/services/NotionService/BlockHandler/BlockHandler.test.ts @@ -33,7 +33,7 @@ const loadCards = async ( decks: [], parentName: '', }); - return decks[0].cards; + return decks[0].cards ?? []; }; async function findCardByName( @@ -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');