|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { notionCreatePageTool, notionCreatePageV2Tool } from '@/tools/notion/create_page' |
| 6 | +import { notionReadTool, notionReadV2Tool } from '@/tools/notion/read' |
| 7 | +import { notionUpdatePageTool, notionUpdatePageV2Tool } from '@/tools/notion/update_page' |
| 8 | + |
| 9 | +const PAGE_TITLE = 'Project Apollo' |
| 10 | + |
| 11 | +function pageResponse(): Response { |
| 12 | + return Response.json({ |
| 13 | + id: 'page-1', |
| 14 | + url: 'https://www.notion.so/page-1', |
| 15 | + created_time: '2026-08-01T00:00:00.000Z', |
| 16 | + last_edited_time: '2026-08-02T00:00:00.000Z', |
| 17 | + properties: { |
| 18 | + Project: { |
| 19 | + id: 'title', |
| 20 | + type: 'title', |
| 21 | + title: [{ plain_text: PAGE_TITLE }], |
| 22 | + }, |
| 23 | + }, |
| 24 | + }) |
| 25 | +} |
| 26 | + |
| 27 | +const responseCases = [ |
| 28 | + { |
| 29 | + id: notionReadTool.id, |
| 30 | + title: async () => |
| 31 | + (await notionReadTool.transformResponse!(pageResponse())).output.metadata.title, |
| 32 | + }, |
| 33 | + { |
| 34 | + id: notionReadV2Tool.id, |
| 35 | + title: async () => (await notionReadV2Tool.transformResponse!(pageResponse())).output.title, |
| 36 | + }, |
| 37 | + { |
| 38 | + id: notionCreatePageTool.id, |
| 39 | + title: async () => |
| 40 | + (await notionCreatePageTool.transformResponse!(pageResponse())).output.metadata.title, |
| 41 | + }, |
| 42 | + { |
| 43 | + id: notionCreatePageV2Tool.id, |
| 44 | + title: async () => |
| 45 | + (await notionCreatePageV2Tool.transformResponse!(pageResponse())).output.title, |
| 46 | + }, |
| 47 | + { |
| 48 | + id: notionUpdatePageTool.id, |
| 49 | + title: async () => |
| 50 | + (await notionUpdatePageTool.transformResponse!(pageResponse())).output.metadata.title, |
| 51 | + }, |
| 52 | + { |
| 53 | + id: notionUpdatePageV2Tool.id, |
| 54 | + title: async () => |
| 55 | + (await notionUpdatePageV2Tool.transformResponse!(pageResponse())).output.title, |
| 56 | + }, |
| 57 | +] |
| 58 | + |
| 59 | +describe('Notion page title responses', () => { |
| 60 | + it.each(responseCases)('$id reads a custom-named title property', async ({ title }) => { |
| 61 | + await expect(title()).resolves.toBe(PAGE_TITLE) |
| 62 | + }) |
| 63 | +}) |
0 commit comments