n8n/packages/nodes-base/test/nodes/Airtable/Airtable.node.test.ts
Marcus 74fc1414d7
test(Spreadsheet File Node): Unit tests (no-changelog) (#5385)
* ️test setup

* ️fix  'testData' implicitly has an 'any' type.

*  test github action file binary data reading

*  checking for output binary equality

*  writing files to different formats

*  reading spreadsheet with different options

* ️improve workflow file path replacement

* 🐛 fixing string.at() not supported in node 14.

* 🐛 trying to fix github action test error

*  fix for empty binary

*  switch for binary test

* ️test helpers now return/compare json and binary (if not empty))

*  removed commented console log

---------

Co-authored-by: Michael Kret <michael.k@radency.com>
2023-02-09 09:00:29 +01:00

60 lines
1.4 KiB
TypeScript

import { executeWorkflow } from '../ExecuteWorkflow';
import * as Helpers from '../Helpers';
import { WorkflowTestData } from '../types';
import nock from 'nock';
const records = [
{
id: 'rec2BWBoyS5QsS7pT',
createdTime: '2022-08-25T08:22:34.000Z',
fields: {
name: 'Tim',
email: 'tim@email.com',
},
},
];
describe('Execute Airtable Node', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('https://api.airtable.com/v0')
.get('/appIaXXdDqS5ORr4V/tbljyBEdYzCPF0NDh?pageSize=100')
.reply(200, { records });
});
afterEach(() => {
nock.restore();
});
const tests: Array<WorkflowTestData> = [
{
description: 'List Airtable Records',
input: {
workflowData: Helpers.readJsonFileSync('test/nodes/Airtable/workflow.json'),
},
output: {
nodeData: {
Airtable: [[...records.map((r) => ({ json: r }))]],
},
},
},
];
const nodeTypes = Helpers.setup(tests);
for (const testData of tests) {
test(testData.description, async () => {
// execute workflow
const { result } = await executeWorkflow(testData, nodeTypes);
// check if result node data matches expected test data
const resultNodeData = Helpers.getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) =>
expect(resultData).toEqual(testData.output.nodeData[nodeName]),
);
expect(result.finished).toEqual(true);
});
}
});