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 427bd74
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
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
3 changes: 1 addition & 2 deletions src/lib/parser/experimental/FallbackParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
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 427bd74

Please sign in to comment.