refactor: Overhaul nodes-testing setup - Part 3 (no-changelog) (#14967)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-04-29 17:42:21 +02:00
committed by GitHub
parent 3e43f9f8bc
commit 979f9e6327
241 changed files with 1868 additions and 2013 deletions

View File

@@ -1,8 +1,6 @@
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import type { WorkflowTestData } from 'n8n-workflow';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
import * as Helpers from '@test/nodes/Helpers';
jest.mock('otpauth', () => {
return {
TOTP: jest.fn().mockImplementation(() => {
@@ -14,15 +12,17 @@ jest.mock('otpauth', () => {
});
describe('Execute TOTP node', () => {
const testHarness = new NodeTestHarness();
const tests: WorkflowTestData[] = [
{
description: 'Generate TOTP Token',
input: {
workflowData: Helpers.readJsonFileSync('nodes/Totp/test/Totp.workflow.test.json'),
workflowData: testHarness.readWorkflowJSON('Totp.workflow.test.json'),
},
output: {
nodeData: {
TOTP: [[{ json: { token: '123456' } }]], // ignore secondsRemaining to prevent flakiness
// ignore json.secondsRemaining to prevent flakiness
TOTP: [[{ json: expect.objectContaining({ token: '123456' }) }]],
},
},
credentials: {
@@ -35,18 +35,6 @@ describe('Execute TOTP node', () => {
];
for (const testData of tests) {
// eslint-disable-next-line @typescript-eslint/no-loop-func
test(testData.description, async () => {
const { result } = await executeWorkflow(testData);
Helpers.getResultNodeData(result, testData).forEach(({ nodeName, resultData }) => {
const expected = testData.output.nodeData[nodeName][0][0].json;
const actual = resultData[0]?.[0].json;
expect(actual?.token).toEqual(expected.token);
});
expect(result.finished).toEqual(true);
});
testHarness.setupTest(testData);
}
});