Skip to content

Commit

Permalink
fix: get some tests passing and resolve linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Dec 29, 2022
1 parent 2c6c24f commit 1caf07a
Show file tree
Hide file tree
Showing 116 changed files with 3,995 additions and 6,501 deletions.
72 changes: 0 additions & 72 deletions src/lib/jobs/ConversionJob.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/misc/TokenHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TokenHandler {
});
}

static async GetNotionToken(owner: number) {
static async GetNotionToken(owner: string) {
if (!owner) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import path from 'path';
import os from 'os';

import * as dotenv from 'dotenv';
import CustomExporter from '../parser/CustomExporter';
import Note from '../parser/Note';
import ParserRules from '../parser/ParserRules';
import CustomExporter from '../../parser/CustomExporter';
import Note from '../../parser/Note';
import ParserRules from '../../parser/ParserRules';

import Settings from '../parser/Settings';
import Workspace from '../parser/WorkSpace';
import Settings from '../../parser/Settings';
import Workspace from '../../parser/WorkSpace';
import BlockHandler from './BlockHandler';
import { pageId as examplId } from '../../test/test-utils';
import MockNotionAPI from './_mock/MockNotionAPI';
import { getToggleBlocks } from './helpers/getToggleBlocks';
import { pageId as examplId } from '../../../test/test-utils';
import MockNotionAPI from '../_mock/MockNotionAPI';
import { getToggleBlocks } from '../helpers/getToggleBlocks';

dotenv.config({ path: 'test/.env' });
const api = new MockNotionAPI(process.env.NOTION_KEY!);
Expand Down Expand Up @@ -57,7 +57,7 @@ beforeEach(() => {

describe('BlockHandler', () => {
test('Get Notion Page', async () => {
const page = await api.getPage('3ce6b147ac8a425f836b51cc21825b85');
const page = await api.getPage('699392e9387846e3a729206a126bf787');
const title = await api.getPageTitle(page, new Settings({}));
expect(title).toBe('Notion API Test Page');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import path from 'path';
import fs from 'fs';

import {
AudioBlockObjectResponse,
BlockObjectResponse,
Expand All @@ -11,33 +8,34 @@ import {
ListBlockChildrenResponse,
} from '@notionhq/client/build/src/api-endpoints';
import axios from 'axios';
import NotionAPIWrapper from './NotionAPIWrapper';
import Note from '../parser/Note';
import Settings from '../parser/Settings';
import ParserRules from '../parser/ParserRules';
import Deck from '../parser/Deck';
import CustomExporter from '../parser/CustomExporter';
import { S3FileName, SuffixFrom } from '../misc/file';
import RenderNotionLink from './RenderNotionLink';
import TagRegistry from '../parser/TagRegistry';
import sanitizeTags from '../anki/sanitizeTags';
import BlockColumn from './blocks/lists/BlockColumn';
import getClozeDeletionCard from './helpers/getClozeDeletionCard';
import getInputCard from './helpers/getInputCard';
import getColumn from './helpers/getColumn';
import isColumnList from './helpers/isColumnList';
import isTesting from './helpers/isTesting';
import perserveNewlinesIfApplicable from './helpers/preserveNewlinesIfApplicable';
import getDeckName from '../anki/getDeckname';
import getUniqueFileName from '../misc/getUniqueFileName';
import NotionAPIWrapper from '../NotionAPIWrapper';
import Note from '../../parser/Note';
import Settings from '../../parser/Settings';
import ParserRules from '../../parser/ParserRules';
import Deck from '../../parser/Deck';
import CustomExporter from '../../parser/CustomExporter';
import { S3FileName, SuffixFrom } from '../../misc/file';
import RenderNotionLink from '../RenderNotionLink';
import TagRegistry from '../../parser/TagRegistry';
import sanitizeTags from '../../anki/sanitizeTags';
import BlockColumn from '../blocks/lists/BlockColumn';
import getClozeDeletionCard from '../helpers/getClozeDeletionCard';
import getInputCard from '../helpers/getInputCard';
import getColumn from '../helpers/getColumn';
import isColumnList from '../helpers/isColumnList';
import isTesting from '../helpers/isTesting';
import perserveNewlinesIfApplicable from '../helpers/preserveNewlinesIfApplicable';
import getDeckName from '../../anki/getDeckname';
import getUniqueFileName from '../../misc/getUniqueFileName';
import getSubDeckName from './helpers/getSubDeckName';
import { captureException } from '@sentry/node';
import { renderBack } from './helpers/renderBack';
import { getImageUrl } from './helpers/getImageUrl';
import { getAudioUrl } from './helpers/getAudioUrl';
import { getFileUrl } from './helpers/getFileUrl';
import { renderBack } from '../helpers/renderBack';
import { getImageUrl } from '../helpers/getImageUrl';
import { getAudioUrl } from '../helpers/getAudioUrl';
import { getFileUrl } from '../helpers/getFileUrl';
import { isFullBlock, isFullPage } from '@notionhq/client';
import { blockToStaticMarkup } from './helpers/blockToStaticMarkup';
import { blockToStaticMarkup } from '../helpers/blockToStaticMarkup';
import { NOTION_STYLE } from '../../../templates/helper';

interface Finder {
parentType: string;
Expand Down Expand Up @@ -310,10 +308,6 @@ class BlockHandler {
tags,
notionBaseLink
);
const NOTION_STYLE = fs.readFileSync(
path.join(__dirname, '../../templates/notion.css'),
'utf8'
);
const deck = new Deck(
getDeckName(parentName, title),
cards,
Expand Down Expand Up @@ -350,10 +344,6 @@ class BlockHandler {
tags,
undefined
);
const NOTION_STYLE = fs.readFileSync(
path.join(__dirname, '../../templates/notion.css'),
'utf8'
);
let subDeckName = getSubDeckName(sd);

decks.push(
Expand Down
12 changes: 12 additions & 0 deletions src/lib/notion/BlockHandler/helpers/getSubDeckName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import getSubDeckName from './getSubDeckName';
import { CHILD_PAGE_MOCK, HEADING_MOCK } from './mocks';

describe('getSubDeckName', () => {
it.each([
['name from title', { title: 'cool' }, 'cool'],
['child page', CHILD_PAGE_MOCK, 'Basic blocks'],
['child page', HEADING_MOCK, 'Blocks'],
])('%s', (_, input, expected) => {
expect(getSubDeckName(input)).toBe(expected);
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { BlockObjectResponse } from '@notionhq/client/build/src/api-endpoints';
import { isFullBlock } from '@notionhq/client';
import { getChildPageBlock } from '../blocks/helpers/getChildPageBlock';
import { getToggleBlock } from '../blocks/helpers/getToggleBlock';
import { richObjectToString } from '../blocks/helpers/richObjectToString';
import { getHeading } from '../blocks/helpers/getHeading';
import { getChildPageBlock } from '../../blocks/helpers/getChildPageBlock';
import { getToggleBlock } from '../../blocks/helpers/getToggleBlock';
import { richObjectToString } from '../../blocks/helpers/richObjectToString';
import { getHeading } from '../../blocks/helpers/getHeading';

const getSubDeckName = (block: BlockObjectResponse): string => {
const getSubDeckName = (
block: BlockObjectResponse | { title: string }
): string => {
let subDeckName = 'Untitled';
if ('title' in block) {
return block.title;
}

if (isFullBlock(block)) {
if (isFullBlock(block as BlockObjectResponse)) {
switch (block.type) {
case 'child_page':
return getChildPageBlock(block).title;
Expand Down
70 changes: 70 additions & 0 deletions src/lib/notion/BlockHandler/helpers/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { BlockObjectResponse } from '@notionhq/client/build/src/api-endpoints';

export const CHILD_PAGE_MOCK: BlockObjectResponse = {
object: 'block',
id: '3cc8d7cc-358a-46b4-a03a-1b18ff4f2d35',
parent: {
type: 'page_id',
page_id: 'd693054c-328f-404a-9267-d78681a75bef',
},
created_time: '2021-10-24T08:05:00.000Z',
last_edited_time: '2022-04-23T17:11:00.000Z',
created_by: {
object: 'user',
id: '1590db54-99fe-467c-a656-be319fe6ca8b',
},
last_edited_by: {
object: 'user',
id: '1590db54-99fe-467c-a656-be319fe6ca8b',
},
has_children: true,
archived: false,
type: 'child_page',
child_page: {
title: 'Basic blocks',
},
};

export const HEADING_MOCK: BlockObjectResponse = {
object: 'block',
id: '02f65a53-c1af-405f-8ba9-fa9cf6933113',
parent: {
type: 'page_id',
page_id: 'd693054c-328f-404a-9267-d78681a75bef',
},
created_time: '2021-03-20T12:54:00.000Z',
last_edited_time: '2021-03-20T12:55:00.000Z',
created_by: {
object: 'user',
id: '1590db54-99fe-467c-a656-be319fe6ca8b',
},
last_edited_by: {
object: 'user',
id: '1590db54-99fe-467c-a656-be319fe6ca8b',
},
has_children: false,
archived: false,
type: 'heading_2',
heading_2: {
rich_text: [
{
type: 'text',
text: {
content: 'Blocks',
link: null,
},
annotations: {
bold: false,
italic: false,
strikethrough: false,
underline: false,
code: false,
color: 'default',
},
plain_text: 'Blocks',
href: null,
},
],
color: 'default',
},
};
2 changes: 1 addition & 1 deletion src/lib/notion/RenderNotionLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReactDOMServer from 'react-dom/server';
import BlockHandler from './BlockHandler';
import BlockHandler from './BlockHandler/BlockHandler';

const RenderNotionLink = (
link: string,
Expand Down

This file was deleted.

Loading

0 comments on commit 1caf07a

Please sign in to comment.