diff --git a/package.json b/package.json index 3f2e800..313623d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typed-notion-client", - "version": "0.0.0-internal.1", + "version": "0.0.0-internal.2", "description": "Type-safe Notion API client", "main": "./dist/main.js", "module": "./dist/main.mjs", diff --git a/src/notion/notion-database.test.ts b/src/notion/notion-database.test.ts index 39a45b0..43f3331 100644 --- a/src/notion/notion-database.test.ts +++ b/src/notion/notion-database.test.ts @@ -65,4 +65,23 @@ describe('Test processQueryPredicate', () => { }, }); }); + + // test('When predicate is function, with helper function but it does not calling prop predicate, should throw error', () => { + // expect(() => + // new FakeNotionDatabase({ + // ...sharedOptions, + // propTypes: { + // Test: 'date', + // }, + // }).processQueryPredicate(() => ({ + // filter: { + // property: 'Test', + // date: { + // is_empty: true, + // }, + // }, + // })) + // ).toThrowError(`No prop type provided, please define typeProps in the constructor before calling query`); + + // }); }); diff --git a/src/notion/notion-page.ts b/src/notion/notion-page.ts index 3ebd713..06cc3f0 100644 --- a/src/notion/notion-page.ts +++ b/src/notion/notion-page.ts @@ -74,8 +74,18 @@ export class NotionPage = Recor return funcOrArgs; } const injectProps: Record = {}; - throw new Error(`Not implemented`); + for (const propName of Object.keys(this.propTypes)) { + injectProps[propName] = { + params: (params: Record) => ({ + [propName]: params, + }), + }; + } + + if (Object.keys(injectProps).length === 0) { + throw new Error(`No prop type provided, please define typeProps in the constructor before calling query`); + } - // return funcOrArgs(injectProps as ); + return funcOrArgs(injectProps as MapTypeCreatePageProperties); } } diff --git a/src/notion/notion.page.test.ts b/src/notion/notion.page.test.ts new file mode 100644 index 0000000..3b56dfe --- /dev/null +++ b/src/notion/notion.page.test.ts @@ -0,0 +1,58 @@ +import { expect, test, describe } from 'vitest'; +import { PageProperties } from './types'; +import { NotionPage } from './notion-page'; + +class FakeNotionPage> extends NotionPage { + override processCreatePredidcate = super.processCreatePredidcate; +} + +describe('Test processCreatePredidcate', () => { + test('When predicate is plain filter object', () => { + expect( + new FakeNotionPage({ notionClient: {} as any }).processCreatePredidcate({ + properties: { + Test: { + date: { + start: '2022-01-01', + }, + }, + }, + }) + ).toStrictEqual({ + properties: { + Test: { + date: { + start: '2022-01-01', + }, + }, + }, + }); + }); + + test('When predicate is function, with helper function', () => { + expect( + new FakeNotionPage({ + notionClient: {} as any, + propTypes: { + Test: 'date', + }, + }).processCreatePredidcate(prop => ({ + properties: { + ...prop['Test'].params({ + date: { + start: '2022-01-01', + }, + }), + }, + })) + ).toStrictEqual({ + properties: { + Test: { + date: { + start: '2022-01-01', + }, + }, + }, + }); + }); +});