feat: Create TOTP node (#5901)

*  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>
This commit is contained in:
Iván Ovejero
2023-04-11 11:58:47 +02:00
committed by GitHub
parent 3fdc4413c2
commit 6cf74e412a
10 changed files with 370 additions and 1 deletions

View File

@@ -0,0 +1,47 @@
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);
});
}
});