diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/block/append.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/block/append.test.ts new file mode 100644 index 0000000000..2112ab3394 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/block/append.test.ts @@ -0,0 +1,444 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = { + object: 'list', + results: [ + { + object: 'block', + id: '15bfb9cb-4cf0-8162-bd53-fc201157675f', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'paragraph', + paragraph: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'new text', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'new text', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-8104-8d3f-c8ca8919e791', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'heading_1', + heading_1: { + is_toggleable: false, + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'h1', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'h1', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-814d-b4ad-f65a2c558bb9', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'heading_2', + heading_2: { + is_toggleable: false, + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'h2', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'h2', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-8135-9e43-f3f8a21e2e86', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'heading_3', + heading_3: { + is_toggleable: false, + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'h3', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'h3', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-816b-9457-efba183a957c', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'toggle', + toggle: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'toggle', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'toggle', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-814f-9928-ed87ed0d9470', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'to_do', + to_do: { + checked: false, + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'todo', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'todo', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-812d-95e9-dc8ddc3153dd', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'bulleted_list_item', + bulleted_list_item: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'bullet 1', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'bullet 1', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-8106-9a25-d3859984ce34', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'numbered_list_item', + numbered_list_item: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'point 1', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'point 1', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-81b1-a6f1-eac377c4d163', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T03:40:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'paragraph', + paragraph: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: '', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: '', + href: null, + }, + ], + }, + }, + ], + next_cursor: null, + has_more: false, + request_id: '33358f1b-fc4d-4387-8d95-43c7d03519a5', +}; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { + if (method === 'PATCH') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, block => append', () => { + const workflows = ['nodes/Notion/test/node/v2/block/append.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/block/append.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/block/append.workflow.json new file mode 100644 index 0000000000..413962cbce --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/block/append.workflow.json @@ -0,0 +1,535 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "block", + "blockId": { + "__rl": true, + "value": "https://www.notion.so/Block-Test-88188cbb303e4f44847f27d24bd7ad8e?pvs=4#90e03468f8aa457695da02ccad963040", + "mode": "url" + }, + "blockUi": { + "blockValues": [ + { + "richText": true, + "text": { + "text": [ + { + "text": "new text", + "annotationUi": {} + } + ] + } + }, + { + "type": "heading_1", + "textContent": "h1" + }, + { + "type": "heading_2", + "textContent": "h2" + }, + { + "type": "heading_3", + "textContent": "h3" + }, + { + "type": "toggle", + "textContent": "toggle" + }, + { + "type": "to_do", + "textContent": "todo" + }, + { + "type": "bulleted_list_item", + "textContent": "bullet 1" + }, + { + "type": "numbered_list_item", + "textContent": "point 1" + }, + {} + ] + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "object": "list", + "results": [ + { + "object": "block", + "id": "15bfb9cb-4cf0-8162-bd53-fc201157675f", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "paragraph", + "paragraph": { + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "new text", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "new text", + "href": null + } + ] + } + }, + { + "object": "block", + "id": "15bfb9cb-4cf0-8104-8d3f-c8ca8919e791", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "heading_1", + "heading_1": { + "is_toggleable": false, + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "h1", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "h1", + "href": null + } + ] + } + }, + { + "object": "block", + "id": "15bfb9cb-4cf0-814d-b4ad-f65a2c558bb9", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "heading_2", + "heading_2": { + "is_toggleable": false, + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "h2", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "h2", + "href": null + } + ] + } + }, + { + "object": "block", + "id": "15bfb9cb-4cf0-8135-9e43-f3f8a21e2e86", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "heading_3", + "heading_3": { + "is_toggleable": false, + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "h3", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "h3", + "href": null + } + ] + } + }, + { + "object": "block", + "id": "15bfb9cb-4cf0-816b-9457-efba183a957c", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "toggle", + "toggle": { + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "toggle", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "toggle", + "href": null + } + ] + } + }, + { + "object": "block", + "id": "15bfb9cb-4cf0-814f-9928-ed87ed0d9470", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "to_do", + "to_do": { + "checked": false, + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "todo", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "todo", + "href": null + } + ] + } + }, + { + "object": "block", + "id": "15bfb9cb-4cf0-812d-95e9-dc8ddc3153dd", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "bulleted_list_item", + "bulleted_list_item": { + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "bullet 1", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "bullet 1", + "href": null + } + ] + } + }, + { + "object": "block", + "id": "15bfb9cb-4cf0-8106-9a25-d3859984ce34", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "numbered_list_item", + "numbered_list_item": { + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "point 1", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "point 1", + "href": null + } + ] + } + }, + { + "object": "block", + "id": "15bfb9cb-4cf0-81b1-a6f1-eac377c4d163", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "created_time": "2024-12-13T03:40:00.000Z", + "last_edited_time": "2024-12-13T03:40:00.000Z", + "created_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "paragraph", + "paragraph": { + "color": "default", + "text": [ + { + "type": "text", + "text": { + "content": "", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "", + "href": null + } + ] + } + } + ], + "next_cursor": null, + "has_more": false, + "request_id": "33358f1b-fc4d-4387-8d95-43c7d03519a5" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "87575721-cf21-472f-a9f0-24aa31c8100f", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.test.ts new file mode 100644 index 0000000000..a1c858b59e --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.test.ts @@ -0,0 +1,240 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = [ + { + object: 'block', + id: 'b14bdaaf-b7e9-48c9-a7fa-1b9e1e2092ae', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2023-11-23T10:42:00.000Z', + last_edited_time: '2024-12-13T03:35:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + has_children: true, + archived: false, + in_trash: false, + type: 'toggle', + toggle: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'Drop down First', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Drop down First', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: 'de572f5d-ff5c-4c13-a879-efc20fe47db0', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2023-11-23T10:42:00.000Z', + last_edited_time: '2024-03-11T12:39:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: true, + archived: false, + in_trash: false, + type: 'bulleted_list_item', + bulleted_list_item: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'Bullet Point Second', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Bullet Point Second', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: 'c98cf981-c967-47f5-9948-4aa1be9ce9d0', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2023-11-24T04:41:00.000Z', + last_edited_time: '2024-12-13T03:35:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'heading_2', + heading_2: { + is_toggleable: false, + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'Hello World', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Hello World', + href: null, + }, + ], + }, + }, + { + object: 'block', + id: '527a0555-a486-401e-93a8-19819615c132', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2023-11-23T10:42:00.000Z', + last_edited_time: '2023-11-23T10:43:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'child_page', + child_page: { + title: 'Page Third', + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-81b1-a6f1-eac377c4d163', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T06:15:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'paragraph', + paragraph: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: '', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: '', + href: null, + }, + ], + }, + }, +]; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { + if (method === 'GET') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, block => getAll', () => { + const workflows = ['nodes/Notion/test/node/v2/block/getAll.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.workflow.json new file mode 100644 index 0000000000..9d4c041365 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.workflow.json @@ -0,0 +1,188 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "block", + "operation": "getAll", + "blockId": { + "__rl": true, + "value": "https://www.notion.so/Block-Test-88188cbb303e4f44847f27d24bd7ad8e?pvs=4#90e03468f8aa457695da02ccad963040", + "mode": "url" + }, + "returnAll": true + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "object": "block", + "parent_id": "90e03468f8aa457695da02ccad963040", + "id": "b14bdaaf-b7e9-48c9-a7fa-1b9e1e2092ae", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "last_edited_by": { + "object": "user", + "id": "88f72c1a-07ed-4bae-9fa0-231365d813d9" + }, + "has_children": true, + "archived": false, + "in_trash": false, + "type": "toggle", + "root_id": "90e03468f8aa457695da02ccad963040", + "content": "Drop down First" + } + }, + { + "json": { + "object": "block", + "parent_id": "90e03468f8aa457695da02ccad963040", + "id": "de572f5d-ff5c-4c13-a879-efc20fe47db0", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "last_edited_by": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324" + }, + "has_children": true, + "archived": false, + "in_trash": false, + "type": "bulleted_list_item", + "root_id": "90e03468f8aa457695da02ccad963040", + "content": "Bullet Point Second" + } + }, + { + "json": { + "object": "block", + "parent_id": "90e03468f8aa457695da02ccad963040", + "id": "c98cf981-c967-47f5-9948-4aa1be9ce9d0", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "last_edited_by": { + "object": "user", + "id": "88f72c1a-07ed-4bae-9fa0-231365d813d9" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "heading_2", + "root_id": "90e03468f8aa457695da02ccad963040", + "content": "Hello World" + } + }, + { + "json": { + "object": "block", + "parent_id": "90e03468f8aa457695da02ccad963040", + "id": "527a0555-a486-401e-93a8-19819615c132", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "last_edited_by": { + "object": "user", + "id": "88f72c1a-07ed-4bae-9fa0-231365d813d9" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "child_page", + "root_id": "90e03468f8aa457695da02ccad963040", + "content": "Page Third" + } + }, + { + "json": { + "object": "block", + "parent_id": "90e03468f8aa457695da02ccad963040", + "id": "15bfb9cb-4cf0-81b1-a6f1-eac377c4d163", + "parent": { + "type": "block_id", + "block_id": "90e03468-f8aa-4576-95da-02ccad963040" + }, + "last_edited_by": { + "object": "user", + "id": "88f72c1a-07ed-4bae-9fa0-231365d813d9" + }, + "has_children": false, + "archived": false, + "in_trash": false, + "type": "paragraph", + "root_id": "90e03468f8aa457695da02ccad963040", + "content": "" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "3edb0c05-7e84-4953-a6a5-86c3c6824403", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/get.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/database/get.test.ts new file mode 100644 index 0000000000..2d2dc68c27 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/get.test.ts @@ -0,0 +1,98 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = { + object: 'database', + id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + cover: null, + icon: null, + created_time: '2024-11-08T07:59:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2024-11-08T07:59:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'TEST_DB', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'TEST_DB', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Tags: { + id: '%40~Tp', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f', + public_url: null, + archived: false, + in_trash: false, + request_id: 'd22a9046-be0d-4ef5-b551-8691da552d47', +}; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { + if (method === 'GET') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, database => get', () => { + const workflows = ['nodes/Notion/test/node/v2/database/get.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/get.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/database/get.workflow.json new file mode 100644 index 0000000000..55c052683a --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/get.workflow.json @@ -0,0 +1,90 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "database", + "databaseId": { + "__rl": true, + "value": "138fb9cb-4cf0-804c-8663-d8ecdd5e692f", + "mode": "list", + "cachedResultName": "TEST_DB", + "cachedResultUrl": "https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f" + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "138fb9cb-4cf0-804c-8663-d8ecdd5e692f", + "name": "TEST_DB", + "url": "https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "9f59436f-17e7-4c9d-a550-a594bb15618f", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.test.ts new file mode 100644 index 0000000000..8c109d7d4f --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.test.ts @@ -0,0 +1,339 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = [ + { + object: 'database', + id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + cover: null, + icon: null, + created_time: '2024-11-08T07:59:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2024-11-08T07:59:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'TEST_DB', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'TEST_DB', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Tags: { + id: '%40~Tp', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f', + public_url: null, + archived: false, + in_trash: false, + }, + { + object: 'database', + id: 'f7216195-e0d4-46cd-a2d3-587a05baf472', + cover: null, + icon: null, + created_time: '2022-03-07T11:25:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2024-11-08T07:54:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'ListDatabase', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'ListDatabase', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Email: { + id: 'Fitu', + name: 'Email', + type: 'email', + email: {}, + }, + 'Last edited by': { + id: 'XZ~H', + name: 'Last edited by', + type: 'last_edited_by', + last_edited_by: {}, + }, + Tags: { + id: 'a%7BRG', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Created: { + id: 'eqq~', + name: 'Created', + type: 'created_time', + created_time: {}, + }, + Status: { + id: 'nZEQ', + name: 'Status', + type: 'status', + status: { + options: [ + { + id: '70312bf9-84d5-40e6-b1eb-d71798ee556f', + name: 'Not started', + color: 'default', + description: null, + }, + { + id: '02a6bb40-3f4b-47d6-818d-6a4129cc6091', + name: 'In progress', + color: 'gray', + description: null, + }, + { + id: 'a3c13d01-63b2-4571-8a02-8c1801649af7', + name: 'Done', + color: 'green', + description: null, + }, + ], + groups: [ + { + id: '82e2022c-001d-47ac-a8b8-243ef7fac352', + name: 'To-do', + color: 'gray', + option_ids: ['70312bf9-84d5-40e6-b1eb-d71798ee556f'], + }, + { + id: '296000d7-287e-4121-9445-98fa8f7de298', + name: 'In progress', + color: 'blue', + option_ids: ['02a6bb40-3f4b-47d6-818d-6a4129cc6091'], + }, + { + id: 'db7689ae-127d-4218-8b3c-306e59e02070', + name: 'Complete', + color: 'green', + option_ids: ['a3c13d01-63b2-4571-8a02-8c1801649af7'], + }, + ], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/f7216195e0d446cda2d3587a05baf472', + public_url: 'https://pleasant-halloumi-63e.notion.site/f7216195e0d446cda2d3587a05baf472', + archived: false, + in_trash: false, + }, + { + object: 'database', + id: 'e9c354e3-e506-4c42-83e2-d9c81a083f05', + cover: null, + icon: null, + created_time: '2022-03-07T11:05:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2023-09-29T08:00:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'n8n-trigger', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'n8n-trigger', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Total: { + id: 'A%3DdW', + name: 'Total', + type: 'formula', + formula: { + expression: + '((({{notion:block_property:n%7DI%5E:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}} + {{notion:block_property:MH~%3B:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:MwMd:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) + {{notion:block_property:fJea:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:rSrM:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}', + }, + }, + 'Total Incomes': { + id: 'MH~%3B', + name: 'Total Incomes', + type: 'number', + number: { + format: 'number', + }, + }, + 'Total Expenses': { + id: 'MwMd', + name: 'Total Expenses', + type: 'number', + number: { + format: 'number', + }, + }, + 'Created time': { + id: 'Z%3BGM', + name: 'Created time', + type: 'created_time', + created_time: {}, + }, + 'Last edited time': { + id: '%60%5ElG', + name: 'Last edited time', + type: 'last_edited_time', + last_edited_time: {}, + }, + 'Total Transfer-In': { + id: 'fJea', + name: 'Total Transfer-In', + type: 'number', + number: { + format: 'number', + }, + }, + 'Starting Balance': { + id: 'n%7DI%5E', + name: 'Starting Balance', + type: 'number', + number: { + format: 'number', + }, + }, + 'Total Transfer-Out': { + id: 'rSrM', + name: 'Total Transfer-Out', + type: 'number', + number: { + format: 'number', + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/e9c354e3e5064c4283e2d9c81a083f05', + public_url: null, + archived: false, + in_trash: false, + }, +]; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { + if (method === 'POST') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, database => getAll', () => { + const workflows = ['nodes/Notion/test/node/v2/database/getAll.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.workflow.json new file mode 100644 index 0000000000..380ef6ef93 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.workflow.json @@ -0,0 +1,99 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "database", + "operation": "getAll", + "returnAll": true + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "138fb9cb-4cf0-804c-8663-d8ecdd5e692f", + "name": "TEST_DB", + "url": "https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f" + } + }, + { + "json": { + "id": "f7216195-e0d4-46cd-a2d3-587a05baf472", + "name": "ListDatabase", + "url": "https://www.notion.so/f7216195e0d446cda2d3587a05baf472" + } + }, + { + "json": { + "id": "e9c354e3-e506-4c42-83e2-d9c81a083f05", + "name": "n8n-trigger", + "url": "https://www.notion.so/e9c354e3e5064c4283e2d9c81a083f05" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "c9094e39-7195-4d4c-9e08-928415e1902b", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/search.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/database/search.test.ts new file mode 100644 index 0000000000..16aef07885 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/search.test.ts @@ -0,0 +1,213 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = [ + { + object: 'database', + id: 'e9c354e3-e506-4c42-83e2-d9c81a083f05', + cover: null, + icon: null, + created_time: '2022-03-07T11:05:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2023-09-29T08:00:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'n8n-trigger', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'n8n-trigger', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Total: { + id: 'A%3DdW', + name: 'Total', + type: 'formula', + formula: { + expression: + '((({{notion:block_property:n%7DI%5E:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}} + {{notion:block_property:MH~%3B:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:MwMd:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) + {{notion:block_property:fJea:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:rSrM:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}', + }, + }, + 'Total Incomes': { + id: 'MH~%3B', + name: 'Total Incomes', + type: 'number', + number: { + format: 'number', + }, + }, + 'Total Expenses': { + id: 'MwMd', + name: 'Total Expenses', + type: 'number', + number: { + format: 'number', + }, + }, + 'Created time': { + id: 'Z%3BGM', + name: 'Created time', + type: 'created_time', + created_time: {}, + }, + 'Last edited time': { + id: '%60%5ElG', + name: 'Last edited time', + type: 'last_edited_time', + last_edited_time: {}, + }, + 'Total Transfer-In': { + id: 'fJea', + name: 'Total Transfer-In', + type: 'number', + number: { + format: 'number', + }, + }, + 'Starting Balance': { + id: 'n%7DI%5E', + name: 'Starting Balance', + type: 'number', + number: { + format: 'number', + }, + }, + 'Total Transfer-Out': { + id: 'rSrM', + name: 'Total Transfer-Out', + type: 'number', + number: { + format: 'number', + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/e9c354e3e5064c4283e2d9c81a083f05', + public_url: null, + archived: false, + in_trash: false, + }, + { + object: 'database', + id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + cover: null, + icon: null, + created_time: '2024-11-08T07:59:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2024-11-08T07:59:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'TEST_DB', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'TEST_DB', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Tags: { + id: '%40~Tp', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f', + public_url: null, + archived: false, + in_trash: false, + }, +]; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { + if (method === 'POST') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, database => search', () => { + const workflows = ['nodes/Notion/test/node/v2/database/search.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/search.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/database/search.workflow.json new file mode 100644 index 0000000000..b04abcc5ab --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/search.workflow.json @@ -0,0 +1,265 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "database", + "operation": "search", + "text": "t", + "limit": 2, + "simple": false, + "options": { + "sort": { + "sortValue": { + "direction": "ascending" + } + } + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "object": "database", + "id": "e9c354e3-e506-4c42-83e2-d9c81a083f05", + "cover": null, + "icon": null, + "created_time": "2022-03-07T11:05:00.000Z", + "created_by": { + "object": "user", + "id": "88f72c1a-07ed-4bae-9fa0-231365d813d9" + }, + "last_edited_by": { + "object": "user", + "id": "88f72c1a-07ed-4bae-9fa0-231365d813d9" + }, + "last_edited_time": "2023-09-29T08:00:00.000Z", + "title": [ + { + "type": "text", + "text": { + "content": "n8n-trigger", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "n8n-trigger", + "href": null + } + ], + "description": [], + "is_inline": false, + "properties": { + "Total": { + "id": "A%3DdW", + "name": "Total", + "type": "formula", + "formula": { + "expression": "((({{notion:block_property:n%7DI%5E:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}} + {{notion:block_property:MH~%3B:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:MwMd:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) + {{notion:block_property:fJea:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:rSrM:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}" + } + }, + "Total Incomes": { + "id": "MH~%3B", + "name": "Total Incomes", + "type": "number", + "number": { + "format": "number" + } + }, + "Total Expenses": { + "id": "MwMd", + "name": "Total Expenses", + "type": "number", + "number": { + "format": "number" + } + }, + "Created time": { + "id": "Z%3BGM", + "name": "Created time", + "type": "created_time", + "created_time": {} + }, + "Last edited time": { + "id": "%60%5ElG", + "name": "Last edited time", + "type": "last_edited_time", + "last_edited_time": {} + }, + "Total Transfer-In": { + "id": "fJea", + "name": "Total Transfer-In", + "type": "number", + "number": { + "format": "number" + } + }, + "Starting Balance": { + "id": "n%7DI%5E", + "name": "Starting Balance", + "type": "number", + "number": { + "format": "number" + } + }, + "Total Transfer-Out": { + "id": "rSrM", + "name": "Total Transfer-Out", + "type": "number", + "number": { + "format": "number" + } + }, + "Name": { + "id": "title", + "name": "Name", + "type": "title", + "title": {} + } + }, + "parent": { + "type": "page_id", + "page_id": "cc3d2b3c-f31a-4773-ab39-17a60c54567a" + }, + "url": "https://www.notion.so/e9c354e3e5064c4283e2d9c81a083f05", + "public_url": null, + "archived": false, + "in_trash": false + } + }, + { + "json": { + "object": "database", + "id": "138fb9cb-4cf0-804c-8663-d8ecdd5e692f", + "cover": null, + "icon": null, + "created_time": "2024-11-08T07:59:00.000Z", + "created_by": { + "object": "user", + "id": "88f72c1a-07ed-4bae-9fa0-231365d813d9" + }, + "last_edited_by": { + "object": "user", + "id": "88f72c1a-07ed-4bae-9fa0-231365d813d9" + }, + "last_edited_time": "2024-11-08T07:59:00.000Z", + "title": [ + { + "type": "text", + "text": { + "content": "TEST_DB", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "TEST_DB", + "href": null + } + ], + "description": [], + "is_inline": false, + "properties": { + "Tags": { + "id": "%40~Tp", + "name": "Tags", + "type": "multi_select", + "multi_select": { + "options": [] + } + }, + "Name": { + "id": "title", + "name": "Name", + "type": "title", + "title": {} + } + }, + "parent": { + "type": "page_id", + "page_id": "cc3d2b3c-f31a-4773-ab39-17a60c54567a" + }, + "url": "https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f", + "public_url": null, + "archived": false, + "in_trash": false + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "08dad8e3-abcc-42d1-8ad3-c026644d1280", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.test.ts new file mode 100644 index 0000000000..3920fbfa12 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.test.ts @@ -0,0 +1,114 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = { + object: 'page', + id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + created_time: '2024-12-13T04:45:00.000Z', + last_edited_time: '2024-12-13T04:45:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + cover: null, + icon: { + type: 'emoji', + emoji: '😗', + }, + parent: { + type: 'database_id', + database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + }, + archived: false, + in_trash: false, + properties: { + Tags: { + id: '%40~Tp', + type: 'multi_select', + multi_select: [], + }, + Name: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'new name 1', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'new name 1', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3', + public_url: null, + request_id: '1416702d-daa8-4f8d-9be3-c55fe52486b5', +}; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { + if (method === 'GET') { + return { + properties: { + Tags: { + id: '%40~Tp', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + }; + } + if (method === 'POST') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, databasePage => create', () => { + const workflows = ['nodes/Notion/test/node/v2/databasePage/create.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.workflow.json new file mode 100644 index 0000000000..80022b8c19 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.workflow.json @@ -0,0 +1,116 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "databasePage", + "databaseId": { + "__rl": true, + "value": "138fb9cb-4cf0-804c-8663-d8ecdd5e692f", + "mode": "list", + "cachedResultName": "TEST_DB", + "cachedResultUrl": "https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f" + }, + "title": "new page", + "propertiesUi": { + "propertyValues": [ + { + "key": "Name|title", + "title": "new name 1" + } + ] + }, + "blockUi": { + "blockValues": [ + { + "textContent": "new text" + }, + { + "type": "toggle", + "textContent": "new toggle" + } + ] + }, + "options": { + "iconType": "emoji", + "icon": "😗" + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3", + "name": "new name 1", + "url": "https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3", + "property_tags": [], + "property_name": "new name 1" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "5f4f1112-c094-44b6-bc05-005b54190852", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.test.ts new file mode 100644 index 0000000000..7092f45d0c --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.test.ts @@ -0,0 +1,94 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = { + object: 'page', + id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + created_time: '2024-12-13T04:45:00.000Z', + last_edited_time: '2024-12-13T04:45:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + cover: null, + icon: { + type: 'emoji', + emoji: '😗', + }, + parent: { + type: 'database_id', + database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + }, + archived: false, + in_trash: false, + properties: { + Tags: { + id: '%40~Tp', + type: 'multi_select', + multi_select: [], + }, + Name: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'new name 1', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'new name 1', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3', + public_url: null, + request_id: 'c01d3a3e-d9c3-4e48-8d73-077a8503c3ba', +}; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { + if (method === 'GET') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, databasePage => get', () => { + const workflows = ['nodes/Notion/test/node/v2/databasePage/get.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.workflow.json new file mode 100644 index 0000000000..7180d48521 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.workflow.json @@ -0,0 +1,91 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "databasePage", + "operation": "get", + "pageId": { + "__rl": true, + "value": "https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f?v=7bcc03614eed4c95a9e6168c040e9c58&p=15bfb9cb4cf081c7aab4c5855b8cb6c3&pm=s", + "mode": "url" + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3", + "name": "new name 1", + "url": "https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3", + "property_tags": [], + "property_name": "new name 1" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "68afba7e-c066-458c-984b-c758ef92463c", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.test.ts new file mode 100644 index 0000000000..7d465b7ca0 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.test.ts @@ -0,0 +1,95 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = [ + { + object: 'page', + id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + created_time: '2024-12-13T04:45:00.000Z', + last_edited_time: '2024-12-13T04:45:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + cover: null, + icon: { + type: 'emoji', + emoji: '😗', + }, + parent: { + type: 'database_id', + database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + }, + archived: false, + in_trash: false, + properties: { + Tags: { + id: '%40~Tp', + type: 'multi_select', + multi_select: [], + }, + Name: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'new name 1', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'new name 1', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3', + public_url: null, + }, +]; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { + if (method === 'POST') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, databasePage => getAll', () => { + const workflows = ['nodes/Notion/test/node/v2/databasePage/getAll.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.workflow.json new file mode 100644 index 0000000000..6efd1f3c07 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.workflow.json @@ -0,0 +1,114 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "databasePage", + "operation": "getAll", + "databaseId": { + "__rl": true, + "value": "138fb9cb-4cf0-804c-8663-d8ecdd5e692f", + "mode": "list", + "cachedResultName": "TEST_DB", + "cachedResultUrl": "https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f" + }, + "returnAll": true, + "filterType": "manual", + "filters": { + "conditions": [ + { + "key": "Name|title", + "condition": "contains", + "titleValue": "new" + } + ] + }, + "options": { + "sort": { + "sortValue": [ + { + "key": "Name|title", + "direction": "ascending" + } + ] + } + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3", + "name": "new name 1", + "url": "https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3", + "property_tags": [], + "property_name": "new name 1" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "c69706eb-f8e8-4fe0-b456-23e482743d1c", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.test.ts new file mode 100644 index 0000000000..a79589bede --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.test.ts @@ -0,0 +1,94 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = { + object: 'page', + id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + created_time: '2024-12-13T04:45:00.000Z', + last_edited_time: '2024-12-13T05:21:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + cover: null, + icon: { + type: 'emoji', + emoji: '😗', + }, + parent: { + type: 'database_id', + database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + }, + archived: false, + in_trash: false, + properties: { + Tags: { + id: '%40~Tp', + type: 'multi_select', + multi_select: [], + }, + Name: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'Updated Name', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Updated Name', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/Updated-Name-15bfb9cb4cf081c7aab4c5855b8cb6c3', + public_url: null, + request_id: 'a4683091-f165-4f10-92b4-a629b8b1266e', +}; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { + if (method === 'PATCH') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, databasePage => update', () => { + const workflows = ['nodes/Notion/test/node/v2/databasePage/update.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.workflow.json new file mode 100644 index 0000000000..0d9705dc22 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.workflow.json @@ -0,0 +1,100 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "databasePage", + "operation": "update", + "pageId": { + "__rl": true, + "value": "https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3", + "mode": "url" + }, + "propertiesUi": { + "propertyValues": [ + { + "key": "Name|title", + "title": "Updated Name" + } + ] + }, + "options": {} + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3", + "name": "Updated Name", + "url": "https://www.notion.so/Updated-Name-15bfb9cb4cf081c7aab4c5855b8cb6c3", + "property_tags": [], + "property_name": "Updated Name" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "ab4a62f2-5d45-456a-ac7a-97cf84e78815", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.test.ts new file mode 100644 index 0000000000..433df8fc03 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.test.ts @@ -0,0 +1,94 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = { + object: 'page', + id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + created_time: '2024-12-13T04:45:00.000Z', + last_edited_time: '2024-12-13T05:52:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + cover: null, + icon: { + type: 'emoji', + emoji: '😗', + }, + parent: { + type: 'database_id', + database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + }, + archived: true, + in_trash: true, + properties: { + Tags: { + id: '%40~Tp', + type: 'multi_select', + multi_select: [], + }, + Name: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'Updated Name', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Updated Name', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/Updated-Name-15bfb9cb4cf081c7aab4c5855b8cb6c3', + public_url: null, + request_id: 'ce91abaa-261f-43c3-9237-57c0f28af682', +}; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { + if (method === 'PATCH') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, page => archive', () => { + const workflows = ['nodes/Notion/test/node/v2/page/archive.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.workflow.json new file mode 100644 index 0000000000..1aeb758f5e --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.workflow.json @@ -0,0 +1,90 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "operation": "archive", + "pageId": { + "__rl": true, + "value": "15bfb9cb4cf081c7aab4c5855b8cb6c3", + "mode": "id" + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3", + "name": "Updated Name", + "url": "https://www.notion.so/Updated-Name-15bfb9cb4cf081c7aab4c5855b8cb6c3", + "property_tags": [], + "property_name": "Updated Name" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "aae2fbb6-0277-449a-9f26-d8d3cf53d2c4", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/create.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/page/create.test.ts new file mode 100644 index 0000000000..88b8c8018e --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/create.test.ts @@ -0,0 +1,89 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = { + object: 'page', + id: '15bfb9cb-4cf0-812b-b4bc-c85cd00727f8', + created_time: '2024-12-13T06:01:00.000Z', + last_edited_time: '2024-12-13T06:01:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + cover: null, + icon: { + type: 'emoji', + emoji: '😊', + }, + parent: { + type: 'page_id', + page_id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + }, + archived: false, + in_trash: false, + properties: { + title: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'Child page', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Child page', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/Child-page-15bfb9cb4cf0812bb4bcc85cd00727f8', + public_url: null, + request_id: 'df28ec00-4361-46af-a3b6-add18c8d1295', +}; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { + if (method === 'POST') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, page => create', () => { + const workflows = ['nodes/Notion/test/node/v2/page/create.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/create.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/page/create.workflow.json new file mode 100644 index 0000000000..ab2c6b8f62 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/create.workflow.json @@ -0,0 +1,111 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "pageId": { + "__rl": true, + "value": "15bfb9cb4cf081c7aab4c5855b8cb6c3", + "mode": "id", + "__regex": "^([0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})" + }, + "title": "Child page", + "blockUi": { + "blockValues": [ + { + "type": "heading_1", + "richText": true, + "text": { + "text": [ + { + "text": "Title", + "annotationUi": {} + } + ] + } + }, + { + "textContent": "text" + } + ] + }, + "options": { + "icon": "😊" + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "15bfb9cb-4cf0-812b-b4bc-c85cd00727f8", + "name": "Child page", + "url": "https://www.notion.so/Child-page-15bfb9cb4cf0812bb4bcc85cd00727f8" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "f8f473ad-4d37-49c4-95f3-187b3a70a6f1", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/search.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/page/search.test.ts new file mode 100644 index 0000000000..5c7cc24c70 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/search.test.ts @@ -0,0 +1,90 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = [ + { + object: 'page', + id: '15bfb9cb-4cf0-812b-b4bc-c85cd00727f8', + created_time: '2024-12-13T06:01:00.000Z', + last_edited_time: '2024-12-13T06:01:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + cover: null, + icon: { + type: 'emoji', + emoji: '😊', + }, + parent: { + type: 'page_id', + page_id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + }, + archived: false, + in_trash: false, + properties: { + title: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'Child page', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Child page', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/Child-page-15bfb9cb4cf0812bb4bcc85cd00727f8', + public_url: null, + }, +]; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { + if (method === 'POST') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, page => search', () => { + const workflows = ['nodes/Notion/test/node/v2/page/search.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/search.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/page/search.workflow.json new file mode 100644 index 0000000000..84a14c1f85 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/search.workflow.json @@ -0,0 +1,97 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "operation": "search", + "text": "child", + "returnAll": true, + "options": { + "filter": { + "filters": { + "value": "page" + } + }, + "sort": { + "sortValue": { + "direction": "ascending" + } + } + } + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "id": "15bfb9cb-4cf0-812b-b4bc-c85cd00727f8", + "name": "Child page", + "url": "https://www.notion.so/Child-page-15bfb9cb4cf0812bb4bcc85cd00727f8" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "75e271ec-4d76-4094-b283-9a3f61a0c111", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/user/get.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/user/get.test.ts new file mode 100644 index 0000000000..5ded51c592 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/user/get.test.ts @@ -0,0 +1,45 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = { + object: 'user', + id: '34a945c6-de97-4efc-90d6-6d7cc14a6583', + name: 'second', + avatar_url: null, + type: 'bot', + bot: {}, + request_id: 'ad2a00c0-fa6a-4a14-bf9a-68e1715b51a1', +}; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { + if (method === 'GET') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, user => get', () => { + const workflows = ['nodes/Notion/test/node/v2/user/get.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/user/get.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/user/get.workflow.json new file mode 100644 index 0000000000..208927f05e --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/user/get.workflow.json @@ -0,0 +1,88 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "user", + "userId": "34a945c6-de97-4efc-90d6-6d7cc14a6583" + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "object": "user", + "id": "34a945c6-de97-4efc-90d6-6d7cc14a6583", + "name": "second", + "avatar_url": null, + "type": "bot", + "bot": {}, + "request_id": "ad2a00c0-fa6a-4a14-bf9a-68e1715b51a1" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "d654cac7-21b8-4d6e-99ce-c5c980d9f49d", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.test.ts new file mode 100644 index 0000000000..ac8922f5e4 --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.test.ts @@ -0,0 +1,69 @@ +import nock from 'nock'; +import type { IHttpRequestMethods } from 'n8n-workflow'; +import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; + +const API_RESPONSE = [ + { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + name: 'n8n-test', + avatar_url: null, + type: 'bot', + bot: { + owner: { + type: 'workspace', + workspace: true, + }, + workspace_name: "Michael Kret's Notion", + }, + }, + { + object: 'user', + id: '34a945c6-de97-4efc-90d6-6d7cc14a6583', + name: 'second', + avatar_url: null, + type: 'bot', + bot: {}, + }, + { + object: 'user', + id: '2598a5de-49b3-4acd-adad-20f6b18c9fbe', + name: 'DryMerge', + avatar_url: + 'https://s3-us-west-2.amazonaws.com/public.notion-static.com/e67863a3-a867-4355-a602-c9830dbb1828/Primary_(recommended).jpg', + type: 'bot', + bot: {}, + }, +]; + +jest.mock('../../../../shared/GenericFunctions', () => { + const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); + return { + ...originalModule, + notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { + if (method === 'GET') { + return API_RESPONSE; + } + }), + }; +}); + +describe('Test NotionV2, user => getAll', () => { + const workflows = ['nodes/Notion/test/node/v2/user/getAll.workflow.json']; + const tests = workflowToTests(workflows); + + beforeAll(() => { + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.unmock('../../../../shared/GenericFunctions'); + }); + + const nodeTypes = setup(tests); + + for (const testData of tests) { + test(testData.description, async () => await equalityTest(testData, nodeTypes)); + } +}); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.workflow.json b/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.workflow.json new file mode 100644 index 0000000000..97ce5d332f --- /dev/null +++ b/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.workflow.json @@ -0,0 +1,104 @@ +{ + "name": "tests notion", + "nodes": [ + { + "parameters": {}, + "id": "4260fdbd-e92f-4712-8114-38b85f8289ea", + "name": "When clicking ‘Test workflow’", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [820, 360] + }, + { + "parameters": { + "resource": "user", + "operation": "getAll", + "limit": 2 + }, + "id": "5ab80e6a-c9c4-4cc5-9332-2fc7a3f8ae24", + "name": "Notion", + "type": "n8n-nodes-base.notion", + "typeVersion": 2.2, + "position": [1040, 360], + "credentials": { + "notionApi": { + "id": "CiZXWkDmjiZzpcL1", + "name": "Notion account" + } + } + }, + { + "parameters": {}, + "id": "a664f506-72a5-4e50-80b4-97ed2e6eb334", + "name": "No Operation, do nothing", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1260, 360] + } + ], + "pinData": { + "No Operation, do nothing": [ + { + "json": { + "object": "user", + "id": "f215e49c-4677-40c0-9adc-87440d341324", + "name": "n8n-test", + "avatar_url": null, + "type": "bot", + "bot": { + "owner": { + "type": "workspace", + "workspace": true + }, + "workspace_name": "Michael Kret's Notion" + } + } + }, + { + "json": { + "object": "user", + "id": "34a945c6-de97-4efc-90d6-6d7cc14a6583", + "name": "second", + "avatar_url": null, + "type": "bot", + "bot": {} + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Notion", + "type": "main", + "index": 0 + } + ] + ] + }, + "Notion": { + "main": [ + [ + { + "node": "No Operation, do nothing", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "702bd2aa-53d0-4c82-bbc2-a95a153953b0", + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd" + }, + "id": "Ucav6QC99JNMCkd3", + "tags": [] +} diff --git a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts index 89eab8242b..163dd20ce1 100644 --- a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts +++ b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts @@ -125,4 +125,7 @@ BQIDAQAB accessToken: 'testToken', baseUrl: 'https://api.telegram.org', }, + notionApi: { + apiKey: 'key123', + }, } as const;