refactor(Peekalink Node): Stricter typing for Peekalink api call + Tests (no-changelog) (#8125)

This PR is an example for how we can
1. improve typing and remove boilerplate code in may of our nodes
2. use nock to write effective unit tests for nodes that make external
calls

## Review / Merge checklist
- [x] PR title and summary are descriptive
- [x] Add tests
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-12-21 18:22:32 +01:00
committed by GitHub
parent 21788d9153
commit 1d2666b37c
6 changed files with 231 additions and 86 deletions

View File

@@ -1,3 +1,4 @@
import nock from 'nock';
import { WorkflowExecute } from 'n8n-core';
import type { INodeTypes, IRun, IRunExecutionData } from 'n8n-workflow';
import { createDeferredPromise, Workflow } from 'n8n-workflow';
@@ -5,6 +6,13 @@ import * as Helpers from './Helpers';
import type { WorkflowTestData } from './types';
export async function executeWorkflow(testData: WorkflowTestData, nodeTypes: INodeTypes) {
if (testData.nock) {
const { baseUrl, mocks } = testData.nock;
const agent = nock(baseUrl);
mocks.forEach(({ method, path, statusCode, responseBody }) =>
agent[method](path).reply(statusCode, responseBody),
);
}
const executionMode = testData.trigger?.mode ?? 'manual';
const workflowInstance = new Workflow({
id: 'test',