Skip to content

Commit

Permalink
test: remove pre create page step
Browse files Browse the repository at this point in the history
  • Loading branch information
younho9 committed Nov 26, 2021
1 parent a041acb commit 1f52fc9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 228 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
},
"prettier": "@younho9/prettier-config",
"dependencies": {
"@narkdown/notion-utils": "0.1.0",
"@notionhq/client": "0.4.4"
},
"devDependencies": {
Expand All @@ -86,7 +87,6 @@
"@babel/preset-typescript": "7.16.0",
"@commitlint/cli": "13.2.1",
"@commitlint/config-conventional": "13.2.0",
"@narkdown/notion-faker": "0.5.1",
"@tsconfig/node12": "1.0.9",
"@types/faker": "5.5.9",
"@types/jest": "27.0.2",
Expand Down
176 changes: 17 additions & 159 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,32 @@
import process from 'node:process';
import dotenv from 'dotenv';
import {NotionFaker} from '@narkdown/notion-faker';
import {
ListBlockChildrenResponse,
ListDatabasesResponse,
ListUsersResponse,
QueryDatabaseResponse,
SearchResponse,
} from '@notionhq/client/build/src/api-endpoints';
import {extractIdFromUrl} from '@narkdown/notion-utils';
import {NarkdownClient} from '../src';

dotenv.config();

const NOTION_API_KEY = process.env.NOTION_API_KEY!;
const ENTRY_POINT_PAGE_ID = process.env.ENTRY_POINT_PAGE_ID!;
const narkdown: NarkdownClient = new NarkdownClient({auth: NOTION_API_KEY});
const notionFaker: NotionFaker = new NotionFaker();
const TIMEOUT = 1000 * 60 * 10;
const TIMEOUT = 1000 * 60 * 2;

describe('unlimited.blocks.children.list', () => {
const CHILD_COUNT = 101;
let TEST_PAGE_ID: string;
const TEST_PAGE_ID = extractIdFromUrl(
'https://narkdown.notion.site/et-tempore-iste-36d1060897c442399eb86e1f98dd31d4',
);
let response: ListBlockChildrenResponse;

beforeAll(async () => {
const {id: testPageId} = await narkdown.pages.create({
parent: {
page_id: ENTRY_POINT_PAGE_ID,
},
properties: {
title: notionFaker.page.properties.title()()(),
},
});

TEST_PAGE_ID = testPageId;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const _ of Array.from({length: CHILD_COUNT})) {
// eslint-disable-next-line no-await-in-loop
await narkdown.blocks.children.append({
block_id: TEST_PAGE_ID,
children: [
{
object: 'block',
type: 'heading_2',
heading_2: {
text: [
{
type: 'text',
text: {
content: 'Lacinato kale',
},
},
],
},
},
],
});
}

response = await narkdown.unlimited.blocks.children.list({
block_id: TEST_PAGE_ID,
});
}, TIMEOUT);

afterAll(async () => {
await narkdown.blocks.delete({
block_id: TEST_PAGE_ID,
});
}, TIMEOUT);

it(
'has properties',
async () => {
Expand All @@ -92,7 +49,7 @@ describe('unlimited.blocks.children.list', () => {
it(
'results.length is ROW_COUNT',
async () => {
expect(response.results.length).toBe(CHILD_COUNT);
expect(response.results.length).toBeGreaterThan(100);
},
TIMEOUT,
);
Expand All @@ -115,60 +72,17 @@ describe('unlimited.blocks.children.list', () => {
});

describe('unlimited.databases.query', () => {
const ROW_COUNT = 101;
let TEST_PAGE_ID: string;
let TEST_DATABASE_ID: string;
const TEST_DATABASE_ID = extractIdFromUrl(
'https://narkdown.notion.site/6b218cf027f54743ac7635fcbae61d18?v=c7e32351677e4d6b9936235d72a4def4',
);
let response: QueryDatabaseResponse;

beforeAll(async () => {
const {id: testPageId} = await narkdown.pages.create({
parent: {
page_id: ENTRY_POINT_PAGE_ID,
},
properties: {
title: notionFaker.page.properties.title()()(),
},
icon: notionFaker.icon.emoji(),
});

TEST_PAGE_ID = testPageId;

const {id: testDatabaseId} = await narkdown.databases.create({
parent: {
page_id: TEST_PAGE_ID,
},
title: notionFaker.database.title()()(),
properties: {
title: notionFaker.database.properties.title(),
},
});

TEST_DATABASE_ID = testDatabaseId;

await Promise.all(
Array.from({
length: ROW_COUNT,
}).map(async () =>
narkdown.pages.create({
parent: {database_id: TEST_DATABASE_ID},
properties: {
title: notionFaker.page.properties.title('address.cityName')()(),
},
}),
),
);

response = await narkdown.unlimited.databases.query({
database_id: TEST_DATABASE_ID,
});
}, TIMEOUT);

afterAll(async () => {
await narkdown.blocks.delete({
block_id: TEST_PAGE_ID,
});
}, TIMEOUT);

it(
'has properties',
async () => {
Expand All @@ -191,7 +105,7 @@ describe('unlimited.databases.query', () => {
it(
'results.length is ROW_COUNT',
async () => {
expect(response.results.length).toBe(ROW_COUNT);
expect(response.results.length).toBeGreaterThan(100);
},
TIMEOUT,
);
Expand Down Expand Up @@ -316,69 +230,15 @@ describe('unlimited.users.list', () => {
});

describe('unlimited.search', () => {
const ROW_COUNT = 101;
const SOME_UNIQUE_STRING_FOR_SEARCH = 'SOME_UNIQUE_STRING_FOR_SEARCH';
let TEST_PAGE_ID: string;
let TEST_DATABASE_ID: string;
let response: SearchResponse;

beforeAll(async () => {
const {id: testPageId} = await narkdown.pages.create({
parent: {
page_id: ENTRY_POINT_PAGE_ID,
},
properties: {
title: notionFaker.page.properties.title()()(),
},
icon: notionFaker.icon.emoji(),
});

TEST_PAGE_ID = testPageId;

const {id: testDatabaseId} = await narkdown.databases.create({
parent: {
page_id: TEST_PAGE_ID,
},
title: notionFaker.database.title()()(),
properties: {
title: notionFaker.database.properties.title(),
},
});

TEST_DATABASE_ID = testDatabaseId;

await Promise.all(
Array.from({
length: ROW_COUNT,
}).map(async () =>
narkdown.pages.create({
parent: {database_id: TEST_DATABASE_ID},
properties: {
title: {
title: [
{
text: {
content: SOME_UNIQUE_STRING_FOR_SEARCH,
},
},
],
},
},
}),
),
);

response = await narkdown.unlimited.search({
query: SOME_UNIQUE_STRING_FOR_SEARCH,
});
}, TIMEOUT);

afterAll(async () => {
await narkdown.blocks.delete({
block_id: TEST_PAGE_ID,
});
}, TIMEOUT);

it(
'has properties',
async () => {
Expand All @@ -398,15 +258,13 @@ describe('unlimited.search', () => {
TIMEOUT,
);

// NOTE: The current search result is not accurate.
//
// it(
// 'results.length',
// async () => {
// expect(response.results.length).toBeGreaterThan(100);
// },
// TIMEOUT,
// );
it(
'results.length',
async () => {
expect(response.results.length).toBeGreaterThan(100);
},
TIMEOUT,
);

it(
'next_cursor is null',
Expand Down
Loading

0 comments on commit 1f52fc9

Please sign in to comment.