1- import { afterEach , describe , expect , it , vi } from 'vitest'
1+ import { describe , expect , it , vi } from 'vitest'
22import { notionCreateCommentTool } from '@/tools/notion/create_comment'
33import { notionCreatePageTool , notionCreatePageV2Tool } from '@/tools/notion/create_page'
44import { notionReadTool , notionReadV2Tool } from '@/tools/notion/read'
55import { notionUpdatePageTool , notionUpdatePageV2Tool } from '@/tools/notion/update_page'
66import { notionWriteTool } from '@/tools/notion/write'
77
8+ function defined < T > ( value : T | undefined ) : T {
9+ if ( value === undefined ) throw new Error ( 'Expected the tool to define this handler' )
10+ return value
11+ }
12+
813const PAGE_TITLE = 'Project Apollo'
914
1015function pageResponse ( ) : Response {
@@ -75,14 +80,18 @@ describe('Notion rich text length limit', () => {
7580 id : notionWriteTool . id ,
7681 richText : ( ) =>
7782 paragraphRichText (
78- notionWriteTool . request . body ! ( { accessToken : 't' , pageId : 'p' , content : longText } )
83+ defined ( notionWriteTool . request . body ) ( {
84+ accessToken : 't' ,
85+ pageId : 'p' ,
86+ content : longText ,
87+ } )
7988 ) ,
8089 } ,
8190 {
8291 id : notionCreatePageTool . id ,
8392 richText : ( ) =>
8493 paragraphRichText (
85- notionCreatePageTool . request . body ! ( {
94+ defined ( notionCreatePageTool . request . body ) ( {
8695 accessToken : 't' ,
8796 parentId : 'p' ,
8897 content : longText ,
@@ -93,7 +102,7 @@ describe('Notion rich text length limit', () => {
93102 id : notionCreateCommentTool . id ,
94103 richText : ( ) =>
95104 (
96- notionCreateCommentTool . request . body ! ( {
105+ defined ( notionCreateCommentTool . request . body ) ( {
97106 accessToken : 't' ,
98107 pageId : 'p' ,
99108 content : longText ,
@@ -111,10 +120,6 @@ describe('Notion rich text length limit', () => {
111120} )
112121
113122describe ( 'Notion read page content pagination' , ( ) => {
114- afterEach ( ( ) => {
115- vi . unstubAllGlobals ( )
116- } )
117-
118123 it ( 'follows next_cursor past the first 100 blocks' , async ( ) => {
119124 const paragraph = ( text : string ) => ( {
120125 type : 'paragraph' ,
@@ -130,7 +135,7 @@ describe('Notion read page content pagination', () => {
130135 )
131136 vi . stubGlobal ( 'fetch' , fetchMock )
132137
133- const result = await notionReadV2Tool . transformResponse ! ( pageResponse ( ) , {
138+ const result = await defined ( notionReadV2Tool . transformResponse ) ( pageResponse ( ) , {
134139 accessToken : 't' ,
135140 pageId : 'page-1' ,
136141 } )
0 commit comments