refactor: Overhaul nodes-testing setup - Part 1 (no-changelog) (#14303)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-04-01 10:15:13 +02:00
committed by GitHub
parent f85b851851
commit 73e8d76e13
165 changed files with 3397 additions and 6453 deletions

View File

@@ -1,6 +1,6 @@
import type { IHttpRequestMethods } from 'n8n-workflow';
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { testWorkflows } from '@test/nodes/Helpers';
const API_RESPONSE = {
object: 'page',
@@ -61,44 +61,46 @@ const API_RESPONSE = {
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);
const nodeTypes = setup(tests);
nock('https://api.notion.com')
.get('/v1/databases/138fb9cb-4cf0-804c-8663-d8ecdd5e692f')
.reply(200, {
properties: {
Tags: {
id: '%40~Tp',
name: 'Tags',
type: 'multi_select',
multi_select: {
options: [],
},
},
Name: {
id: 'title',
name: 'Name',
type: 'title',
title: {},
},
},
})
.post('/v1/pages', {
parent: { database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f' },
properties: { Name: { title: [{ text: { content: 'new name 1' } }] } },
children: [
{
object: 'block',
type: 'paragraph',
paragraph: { text: [{ text: { content: 'new text' } }] },
},
{
object: 'block',
type: 'toggle',
toggle: { text: [{ text: { content: 'new toggle' } }] },
},
],
icon: { emoji: '😗' },
})
.reply(200, API_RESPONSE);
for (const testData of tests) {
test(testData.description, async () => await equalityTest(testData, nodeTypes));
}
const workflows = ['nodes/Notion/test/node/v2/databasePage/create.workflow.json'];
testWorkflows(workflows);
});

View File

@@ -1,6 +1,6 @@
import type { IHttpRequestMethods } from 'n8n-workflow';
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { testWorkflows } from '@test/nodes/Helpers';
const API_RESPONSE = {
object: 'page',
@@ -61,24 +61,11 @@ const API_RESPONSE = {
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);
const nodeTypes = setup(tests);
nock('https://api.notion.com')
.get('/v1/pages/15bfb9cb4cf081c7aab4c5855b8cb6c3')
.reply(200, API_RESPONSE);
for (const testData of tests) {
test(testData.description, async () => await equalityTest(testData, nodeTypes));
}
const workflows = ['nodes/Notion/test/node/v2/databasePage/get.workflow.json'];
testWorkflows(workflows);
});

View File

@@ -1,85 +1,78 @@
import type { IHttpRequestMethods } from 'n8n-workflow';
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { testWorkflows } 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: [],
const API_RESPONSE = {
results: [
{
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',
},
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,
},
],
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,
},
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;
}
}),
};
});
],
has_more: false,
};
describe('Test NotionV2, databasePage => getAll', () => {
const workflows = ['nodes/Notion/test/node/v2/databasePage/getAll.workflow.json'];
const tests = workflowToTests(workflows);
const nodeTypes = setup(tests);
nock('https://api.notion.com')
.post('/v1/databases/138fb9cb-4cf0-804c-8663-d8ecdd5e692f/query', {
filter: { or: [{ property: 'Name', title: { contains: 'new' } }] },
sorts: [{ direction: 'ascending', property: 'Name' }],
})
.reply(200, API_RESPONSE);
for (const testData of tests) {
test(testData.description, async () => await equalityTest(testData, nodeTypes));
}
const workflows = ['nodes/Notion/test/node/v2/databasePage/getAll.workflow.json'];
testWorkflows(workflows);
});

View File

@@ -1,6 +1,6 @@
import type { IHttpRequestMethods } from 'n8n-workflow';
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { testWorkflows } from '@test/nodes/Helpers';
const API_RESPONSE = {
object: 'page',
@@ -61,24 +61,13 @@ const API_RESPONSE = {
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);
const nodeTypes = setup(tests);
nock('https://api.notion.com')
.patch('/v1/pages/15bfb9cb4cf081c7aab4c5855b8cb6c3', {
properties: { Name: { title: [{ text: { content: 'Updated Name' } }] } },
})
.reply(200, API_RESPONSE);
for (const testData of tests) {
test(testData.description, async () => await equalityTest(testData, nodeTypes));
}
const workflows = ['nodes/Notion/test/node/v2/databasePage/update.workflow.json'];
testWorkflows(workflows);
});