mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
6cf74e412a
* ✨ Create TOTP node * ♻️ Apply feedback * ♻️ Recreate `pnpm-lock.yaml` * ♻️ Apply Giulio's feedback * 🚧 WIP node tests * ✅ Finish node test setup * ⏪ Restore test command * ⚡ linter fixes, tweaks * ♻️ Address Michael's feedback --------- Co-authored-by: Michael Kret <michael.k@radency.com>
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import * as Helpers from '../../../test/nodes/Helpers';
|
|
import { executeWorkflow } from '../../../test/nodes/ExecuteWorkflow';
|
|
import type { WorkflowTestData } from '../../../test/nodes/types';
|
|
|
|
jest.mock('otpauth', () => {
|
|
return {
|
|
TOTP: jest.fn().mockImplementation(() => {
|
|
return {
|
|
generate: jest.fn().mockReturnValue('123456'),
|
|
};
|
|
}),
|
|
};
|
|
});
|
|
|
|
describe('Execute TOTP node', () => {
|
|
const tests: WorkflowTestData[] = [
|
|
{
|
|
description: 'Generate TOTP Token',
|
|
input: {
|
|
workflowData: Helpers.readJsonFileSync('nodes/Totp/test/Totp.workflow.test.json'),
|
|
},
|
|
output: {
|
|
nodeData: {
|
|
TOTP: [[{ json: { token: '123456' } }]], // ignore secondsRemaining to prevent flakiness
|
|
},
|
|
},
|
|
},
|
|
];
|
|
|
|
const nodeTypes = Helpers.setup(tests);
|
|
|
|
for (const testData of tests) {
|
|
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
test(testData.description, async () => {
|
|
const { result } = await executeWorkflow(testData, nodeTypes);
|
|
|
|
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);
|
|
});
|
|
}
|
|
});
|