mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor: Overhaul nodes-testing setup - Part 1 (no-changelog) (#14303)
This commit is contained in:
committed by
GitHub
parent
f85b851851
commit
73e8d76e13
@@ -1,16 +1,11 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'POST') {
|
||||
return {
|
||||
describe('Test DiscordV2, channel => create', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.post('/guilds/1168516062791340136/channels', { name: 'third', type: '0' })
|
||||
.reply(200, {
|
||||
id: '1168528323006181417',
|
||||
type: 0,
|
||||
last_message_id: null,
|
||||
@@ -23,35 +18,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
position: 3,
|
||||
permission_overwrites: [],
|
||||
nsfw: false,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
describe('Test DiscordV2, channel => create', () => {
|
||||
const workflows = ['nodes/Discord/test/v2/node/channel/create.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/guilds/1168516062791340136/channels',
|
||||
{ name: 'third', type: '0' },
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
const workflows = ['nodes/Discord/test/v2/node/channel/create.workflow.json'];
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,53 +1,12 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'DELETE') {
|
||||
return {
|
||||
id: '1168528323006181417',
|
||||
type: 0,
|
||||
last_message_id: null,
|
||||
flags: 0,
|
||||
guild_id: '1168516062791340136',
|
||||
name: 'third',
|
||||
parent_id: null,
|
||||
rate_limit_per_user: 0,
|
||||
topic: null,
|
||||
position: 3,
|
||||
permission_overwrites: [],
|
||||
nsfw: false,
|
||||
};
|
||||
}
|
||||
});
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test DiscordV2, channel => deleteChannel', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.delete('/channels/1168528323006181417')
|
||||
.reply(200, { success: true });
|
||||
|
||||
const workflows = ['nodes/Discord/test/v2/node/channel/deleteChannel.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith('DELETE', '/channels/1168528323006181417');
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -61,18 +61,7 @@
|
||||
"No Operation, do nothing": [
|
||||
{
|
||||
"json": {
|
||||
"id": "1168528323006181417",
|
||||
"type": 0,
|
||||
"last_message_id": null,
|
||||
"flags": 0,
|
||||
"guild_id": "1168516062791340136",
|
||||
"name": "third",
|
||||
"parent_id": null,
|
||||
"rate_limit_per_user": 0,
|
||||
"topic": null,
|
||||
"position": 3,
|
||||
"permission_overwrites": [],
|
||||
"nsfw": false
|
||||
"success": true
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,103 +1,28 @@
|
||||
import type { INodeTypes, IRequestOptions } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
|
||||
import * as transport from '../../../../v2/transport/helpers';
|
||||
|
||||
// TODO: use nock
|
||||
const requestApiSpy = jest.spyOn(transport, 'requestApi');
|
||||
|
||||
requestApiSpy.mockImplementation(
|
||||
async (_options: IRequestOptions, _credentialType: string, endpoint: string) => {
|
||||
if (endpoint === '/users/@me/guilds') {
|
||||
return {
|
||||
headers: {},
|
||||
body: [
|
||||
{
|
||||
id: '1168516062791340136',
|
||||
},
|
||||
],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
headers: {},
|
||||
body: {
|
||||
id: '1168516240332034067',
|
||||
type: 0,
|
||||
last_message_id: null,
|
||||
flags: 0,
|
||||
guild_id: '1168516062791340136',
|
||||
name: 'first',
|
||||
parent_id: '1168516063340789831',
|
||||
rate_limit_per_user: 0,
|
||||
topic: null,
|
||||
position: 1,
|
||||
permission_overwrites: [],
|
||||
nsfw: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test DiscordV2, channel => get', () => {
|
||||
const workflows = ['nodes/Discord/test/v2/node/channel/get.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
nock('https://discord.com/api/v10')
|
||||
.persist()
|
||||
.get('/users/@me/guilds')
|
||||
.reply(200, [{ id: '1168516062791340136' }])
|
||||
.get('/channels/1168516240332034067')
|
||||
.reply(200, {
|
||||
id: '1168516240332034067',
|
||||
type: 0,
|
||||
last_message_id: null,
|
||||
flags: 0,
|
||||
guild_id: '1168516062791340136',
|
||||
name: 'first',
|
||||
parent_id: '1168516063340789831',
|
||||
rate_limit_per_user: 0,
|
||||
topic: null,
|
||||
position: 1,
|
||||
permission_overwrites: [],
|
||||
nsfw: false,
|
||||
});
|
||||
|
||||
expect(requestApiSpy).toHaveBeenCalledTimes(3);
|
||||
expect(requestApiSpy).toHaveBeenCalledWith(
|
||||
{
|
||||
body: undefined,
|
||||
headers: {},
|
||||
json: true,
|
||||
method: 'GET',
|
||||
qs: undefined,
|
||||
url: 'https://discord.com/api/v10/users/@me/guilds',
|
||||
},
|
||||
'discordOAuth2Api',
|
||||
'/users/@me/guilds',
|
||||
);
|
||||
expect(requestApiSpy).toHaveBeenCalledWith(
|
||||
{
|
||||
body: undefined,
|
||||
headers: {},
|
||||
json: true,
|
||||
method: 'GET',
|
||||
qs: undefined,
|
||||
url: 'https://discord.com/api/v10/channels/1168516240332034067',
|
||||
},
|
||||
'discordOAuth2Api',
|
||||
'/channels/1168516240332034067',
|
||||
);
|
||||
expect(requestApiSpy).toHaveBeenCalledWith(
|
||||
{
|
||||
body: undefined,
|
||||
headers: {},
|
||||
json: true,
|
||||
method: 'GET',
|
||||
qs: undefined,
|
||||
url: 'https://discord.com/api/v10/channels/1168516240332034067',
|
||||
},
|
||||
'discordOAuth2Api',
|
||||
'/channels/1168516240332034067',
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
const workflows = ['nodes/Discord/test/v2/node/channel/get.workflow.json'];
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'GET') {
|
||||
return [
|
||||
describe('Test DiscordV2, channel => getAll', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.get('/guilds/1168516062791340136/channels')
|
||||
.reply(200, [
|
||||
{
|
||||
id: '1168516063340789831',
|
||||
type: 4,
|
||||
@@ -99,34 +94,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
permission_overwrites: [],
|
||||
nsfw: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
});
|
||||
]);
|
||||
|
||||
describe('Test DiscordV2, channel => getAll', () => {
|
||||
const workflows = ['nodes/Discord/test/v2/node/channel/getAll.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/guilds/1168516062791340136/channels',
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,60 +1,23 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string, _) => {
|
||||
if (method === 'PATCH') {
|
||||
return {
|
||||
id: '1168516240332034067',
|
||||
type: 0,
|
||||
last_message_id: null,
|
||||
flags: 0,
|
||||
guild_id: '1168516062791340136',
|
||||
name: 'first-channel',
|
||||
parent_id: '1168516063340789831',
|
||||
rate_limit_per_user: 30,
|
||||
topic: 'This is channel topic',
|
||||
position: 3,
|
||||
permission_overwrites: [],
|
||||
nsfw: true,
|
||||
};
|
||||
}
|
||||
});
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test DiscordV2, channel => update', () => {
|
||||
nock('https://discord.com/api/v10').patch('/channels/1168516240332034067').reply(200, {
|
||||
id: '1168516240332034067',
|
||||
type: 0,
|
||||
last_message_id: null,
|
||||
flags: 0,
|
||||
guild_id: '1168516062791340136',
|
||||
name: 'first-channel',
|
||||
parent_id: '1168516063340789831',
|
||||
rate_limit_per_user: 30,
|
||||
topic: 'This is channel topic',
|
||||
position: 3,
|
||||
permission_overwrites: [],
|
||||
nsfw: true,
|
||||
});
|
||||
|
||||
const workflows = ['nodes/Discord/test/v2/node/channel/update.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith('PATCH', '/channels/1168516240332034067', {
|
||||
name: 'First Channel',
|
||||
nsfw: true,
|
||||
parent_id: '1168516063340789831',
|
||||
position: 3,
|
||||
rate_limit_per_user: 30,
|
||||
topic: 'This is channel topic',
|
||||
});
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'GET') {
|
||||
return [
|
||||
describe('Test DiscordV2, member => getAll', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.get('/guilds/1168516062791340136/members?limit=2')
|
||||
.reply(200, [
|
||||
{
|
||||
user: {
|
||||
id: '470936827994570762',
|
||||
@@ -46,36 +41,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
},
|
||||
roles: ['1168518368526077992'],
|
||||
},
|
||||
];
|
||||
}
|
||||
});
|
||||
]);
|
||||
|
||||
describe('Test DiscordV2, member => getAll', () => {
|
||||
const workflows = ['nodes/Discord/test/v2/node/member/getAll.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/guilds/1168516062791340136/members',
|
||||
undefined,
|
||||
{ limit: 2 },
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,45 +1,12 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'PUT') {
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
});
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test DiscordV2, member => roleAdd', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.put('/guilds/1168516062791340136/members/470936827994570762/roles/1168772374540320890')
|
||||
.reply(200, { success: true });
|
||||
|
||||
const workflows = ['nodes/Discord/test/v2/node/member/roleAdd.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'PUT',
|
||||
'/guilds/1168516062791340136/members/470936827994570762/roles/1168772374540320890',
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,53 +1,13 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'DELETE') {
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
});
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test DiscordV2, member => roleRemove', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.persist()
|
||||
.delete(/\/guilds\/1168516062791340136\/members\/470936827994570762\/roles\/\d+/)
|
||||
.reply(200, { success: true });
|
||||
|
||||
const workflows = ['nodes/Discord/test/v2/node/member/roleRemove.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(3);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/guilds/1168516062791340136/members/470936827994570762/roles/1168773588963299428',
|
||||
);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/guilds/1168516062791340136/members/470936827994570762/roles/1168773645800308756',
|
||||
);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/guilds/1168516062791340136/members/470936827994570762/roles/1168772374540320890',
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,45 +1,12 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'DELETE') {
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
});
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test DiscordV2, message => deleteMessage', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.delete('/channels/1168516240332034067/messages/1168776343194972210')
|
||||
.reply(200, { success: true });
|
||||
|
||||
const workflows = ['nodes/Discord/test/v2/node/message/deleteMessage.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/channels/1168516240332034067/messages/1168776343194972210',
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'GET') {
|
||||
return {
|
||||
describe('Test DiscordV2, message => get', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.get('/channels/1168516240332034067/messages/1168777380144369718')
|
||||
.reply(200, {
|
||||
id: '1168777380144369718',
|
||||
channel_id: '1168516240332034067',
|
||||
author: {
|
||||
@@ -31,34 +26,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
content: 'msg 3',
|
||||
timestamp: '2023-10-31T05:04:02.260000+00:00',
|
||||
type: 0,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
describe('Test DiscordV2, message => get', () => {
|
||||
const workflows = ['nodes/Discord/test/v2/node/message/get.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/channels/1168516240332034067/messages/1168777380144369718',
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
const workflows = ['nodes/Discord/test/v2/node/message/get.workflow.json'];
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'GET') {
|
||||
return [
|
||||
describe('Test DiscordV2, message => getAll', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.get('/channels/1168516240332034067/messages?limit=1')
|
||||
.reply(200, [
|
||||
{
|
||||
id: '1168784010269433998',
|
||||
type: 0,
|
||||
@@ -54,36 +49,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
flags: 0,
|
||||
components: [],
|
||||
},
|
||||
];
|
||||
}
|
||||
});
|
||||
]);
|
||||
|
||||
describe('Test DiscordV2, message => getAll', () => {
|
||||
const workflows = ['nodes/Discord/test/v2/node/message/getAll.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/channels/1168516240332034067/messages',
|
||||
undefined,
|
||||
{ limit: 1 },
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,45 +1,12 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'PUT') {
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
});
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test DiscordV2, message => react', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.put('/channels/1168516240332034067/messages/1168777380144369718/reactions/%F0%9F%98%80/@me')
|
||||
.reply(200, { success: true });
|
||||
|
||||
const workflows = ['nodes/Discord/test/v2/node/message/react.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'PUT',
|
||||
'/channels/1168516240332034067/messages/1168777380144369718/reactions/%F0%9F%98%80/@me',
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'POST') {
|
||||
return {
|
||||
describe('Test DiscordV2, message => send', () => {
|
||||
nock('https://discord.com/api/v10')
|
||||
.post('/channels/1168516240332034067/messages', {
|
||||
content: 'msg 4',
|
||||
embeds: [
|
||||
{
|
||||
author: { name: 'Me' },
|
||||
color: 2112935,
|
||||
description: 'description',
|
||||
timestamp: '2023-10-30T22:00:00.000Z',
|
||||
title: 'Some Title',
|
||||
},
|
||||
],
|
||||
})
|
||||
.reply(200, {
|
||||
id: '1168784010269433998',
|
||||
type: 0,
|
||||
content: 'msg 4',
|
||||
@@ -53,46 +59,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
flags: 0,
|
||||
components: [],
|
||||
referenced_message: null,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
describe('Test DiscordV2, message => send', () => {
|
||||
const workflows = ['nodes/Discord/test/v2/node/message/send.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/channels/1168516240332034067/messages',
|
||||
{
|
||||
content: 'msg 4',
|
||||
embeds: [
|
||||
{
|
||||
author: { name: 'Me' },
|
||||
color: 2112935,
|
||||
description: 'description',
|
||||
timestamp: '2023-10-30T22:00:00.000Z',
|
||||
title: 'Some Title',
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
const workflows = ['nodes/Discord/test/v2/node/message/send.workflow.json'];
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
import * as transport from '../../../../v2/transport/discord.api';
|
||||
|
||||
const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');
|
||||
|
||||
discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
if (method === 'POST') {
|
||||
return {
|
||||
describe('Test DiscordV2, webhook => sendLegacy', () => {
|
||||
nock('https://discord.com')
|
||||
.post('/webhook?wait=true')
|
||||
.reply(200, {
|
||||
id: '1168768986385747999',
|
||||
type: 0,
|
||||
content: 'TEST Message',
|
||||
@@ -47,49 +42,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
|
||||
flags: 4096,
|
||||
components: [],
|
||||
webhook_id: '1153265494955135077',
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
describe('Test DiscordV2, webhook => sendLegacy', () => {
|
||||
const workflows = ['nodes/Discord/test/v2/node/webhook/sendLegacy.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(discordApiRequestSpy).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'',
|
||||
{
|
||||
content: 'TEST Message',
|
||||
embeds: [
|
||||
{
|
||||
author: { name: 'Michael' },
|
||||
color: 10930459,
|
||||
description: 'some description',
|
||||
timestamp: '2023-10-17T21:00:00.000Z',
|
||||
},
|
||||
],
|
||||
flags: 4096,
|
||||
tts: true,
|
||||
username: 'TEST_USER',
|
||||
},
|
||||
{ wait: true },
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
const workflows = ['nodes/Discord/test/v2/node/webhook/sendLegacy.workflow.json'];
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user