Skip to content

Commit

Permalink
feat(Microsoft Excel 365 Node): Overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored May 2, 2023
1 parent 25fe14b commit 5364a2d
Show file tree
Hide file tree
Showing 75 changed files with 8,053 additions and 679 deletions.
700 changes: 24 additions & 676 deletions packages/nodes-base/nodes/Microsoft/Excel/MicrosoftExcel.node.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { INodeTypes } from 'n8n-workflow';

import { getResultNodeData, setup, workflowToTests } from '../../../../../../../test/nodes/Helpers';
import type { WorkflowTestData } from '../../../../../../../test/nodes/types';
import { executeWorkflow } from '../../../../../../../test/nodes/ExecuteWorkflow';

import * as transport from '../../../../v2/transport';

import nock from 'nock';

jest.mock('../../../../v2/transport', () => {
const originalModule = jest.requireActual('../../../../v2/transport');
return {
...originalModule,
microsoftApiRequest: jest.fn(async function (method: string) {
if (method === 'POST') {
return {
style: 'TableStyleMedium2',
name: 'Table3',
showFilterButton: true,
id: '{317CA469-7D1C-4A5D-9B0B-424444BF0336}',
highlightLastColumn: false,
highlightFirstColumn: false,
legacyId: '3',
showBandedColumns: false,
showBandedRows: true,
showHeaders: true,
showTotals: false,
};
}
}),
};
});

describe('Test MicrosoftExcelV2, table => addTable', () => {
const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/addTable.workflow.json'];
const tests = workflowToTests(workflows);

beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

const nodeTypes = setup(tests);

const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
const { result } = await executeWorkflow(testData, types);

const resultNodeData = getResultNodeData(result, testData);

resultNodeData.forEach(({ nodeName, resultData }) => {
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
});

expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1);
expect(transport.microsoftApiRequest).toHaveBeenCalledWith(
'POST',
'/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{A0883CFE-D27E-4ECC-B94B-981830AAD55B}/tables/add',
{ address: 'A1:D4', hasHeaders: true },
);

expect(result.finished).toEqual(true);
};

for (const testData of tests) {
test(testData.description, async () => testNode(testData, nodeTypes));
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "My workflow 5",
"nodes": [
{
"parameters": {},
"id": "875e8784-eb59-40d8-ba45-129a5e29881c",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [380, 140]
},
{
"parameters": {
"resource": "table",
"operation": "addTable",
"workbook": {
"__rl": true,
"value": "01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I",
"mode": "list",
"cachedResultName": "ПРРО копія"
},
"worksheet": {
"__rl": true,
"value": "{A0883CFE-D27E-4ECC-B94B-981830AAD55B}",
"mode": "list",
"cachedResultName": "Sheet4"
},
"selectRange": "manual",
"range": "A1:D4"
},
"id": "0e0ac1d2-242c-486a-9287-c70307645acc",
"name": "Microsoft Excel 365",
"type": "n8n-nodes-base.microsoftExcel",
"typeVersion": 2,
"position": [860, 140],
"credentials": {
"microsoftExcelOAuth2Api": {
"id": "70",
"name": "Microsoft Excel account"
}
}
}
],
"pinData": {
"Microsoft Excel 365": [
{
"json": {
"style": "TableStyleMedium2",
"name": "Table3",
"showFilterButton": true,
"id": "{317CA469-7D1C-4A5D-9B0B-424444BF0336}",
"highlightLastColumn": false,
"highlightFirstColumn": false,
"legacyId": "3",
"showBandedColumns": false,
"showBandedRows": true,
"showHeaders": true,
"showTotals": false
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Microsoft Excel 365",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import type { INodeTypes } from 'n8n-workflow';

import { getResultNodeData, setup, workflowToTests } from '../../../../../../../test/nodes/Helpers';
import type { WorkflowTestData } from '../../../../../../../test/nodes/types';
import { executeWorkflow } from '../../../../../../../test/nodes/ExecuteWorkflow';

import * as transport from '../../../../v2/transport';

import nock from 'nock';

jest.mock('../../../../v2/transport', () => {
const originalModule = jest.requireActual('../../../../v2/transport');
return {
...originalModule,
microsoftApiRequest: jest.fn(async function (method: string, resource: string) {
if (method === 'GET') {
return {
value: [
{
name: 'id',
},
{
name: 'name',
},
{
name: 'age',
},
{
name: 'data',
},
],
};
}
if (method === 'POST' && resource.includes('createSession')) {
return {
id: 12345,
};
}
if (method === 'POST' && resource.includes('add')) {
return {
index: 3,
values: [[3, 'Donald', 99, 'data 5']],
};
}
if (method === 'POST' && resource.includes('closeSession')) {
return;
}
}),
};
});

describe('Test MicrosoftExcelV2, table => append', () => {
const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/append.workflow.json'];
const tests = workflowToTests(workflows);

beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

const nodeTypes = setup(tests);

const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
const { result } = await executeWorkflow(testData, types);

const resultNodeData = getResultNodeData(result, testData);

resultNodeData.forEach(({ nodeName, resultData }) => {
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
});

expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(4);

expect(transport.microsoftApiRequest).toHaveBeenCalledWith(
'POST',
'/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{A0883CFE-D27E-4ECC-B94B-981830AAD55B}/tables/{317CA469-7D1C-4A5D-9B0B-424444BF0336}/rows/add',
{ values: [['3', 'Donald', '99', 'data 5']] },
{},
'',
{ 'workbook-session-id': 12345 },
);

expect(result.finished).toEqual(true);
};

for (const testData of tests) {
test(testData.description, async () => testNode(testData, nodeTypes));
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"name": "My workflow 5",
"nodes": [
{
"parameters": {},
"id": "875e8784-eb59-40d8-ba45-129a5e29881c",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [380, 140]
},
{
"parameters": {
"resource": "table",
"workbook": {
"__rl": true,
"value": "01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I",
"mode": "list",
"cachedResultName": "ПРРО копія",
"cachedResultUrl": "https://5w1hb7-my.sharepoint.com/personal/michaeldevsandbox_5w1hb7_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc=%7BECC4041C-3AB6-4CF7-B079-0926470A1388%7D&file=%D0%9F%D0%A0%D0%A0%D0%9E%20%D0%BA%D0%BE%D0%BF%D1%96%D1%8F.xlsx&action=default&mobileredirect=true&DefaultItemOpen=1"
},
"worksheet": {
"__rl": true,
"value": "{A0883CFE-D27E-4ECC-B94B-981830AAD55B}",
"mode": "list",
"cachedResultName": "Sheet4",
"cachedResultUrl": "https://5w1hb7-my.sharepoint.com/personal/michaeldevsandbox_5w1hb7_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc=%7BECC4041C-3AB6-4CF7-B079-0926470A1388%7D&file=%D0%9F%D0%A0%D0%A0%D0%9E%20%D0%BA%D0%BE%D0%BF%D1%96%D1%8F.xlsx&action=default&mobileredirect=true&DefaultItemOpen=1&activeCell=Sheet4!A1"
},
"table": {
"__rl": true,
"value": "{317CA469-7D1C-4A5D-9B0B-424444BF0336}",
"mode": "list",
"cachedResultName": "Table3",
"cachedResultUrl": "https://5w1hb7-my.sharepoint.com/personal/michaeldevsandbox_5w1hb7_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc=%7BECC4041C-3AB6-4CF7-B079-0926470A1388%7D&file=%D0%9F%D0%A0%D0%A0%D0%9E%20%D0%BA%D0%BE%D0%BF%D1%96%D1%8F.xlsx&action=default&mobileredirect=true&DefaultItemOpen=1&activeCell=Sheet4!A1:D4"
},
"fieldsUi": {
"values": [
{
"column": "id",
"fieldValue": "3"
},
{
"column": "name",
"fieldValue": "Donald"
},
{
"column": "age",
"fieldValue": "99"
},
{
"column": "data",
"fieldValue": "data 5"
}
]
},
"options": {}
},
"id": "0e0ac1d2-242c-486a-9287-c70307645acc",
"name": "Microsoft Excel 365",
"type": "n8n-nodes-base.microsoftExcel",
"typeVersion": 2,
"position": [860, 140],
"credentials": {
"microsoftExcelOAuth2Api": {
"id": "70",
"name": "Microsoft Excel account"
}
}
}
],
"pinData": {
"Microsoft Excel 365": [
{
"json": {
"id": 3,
"name": "Donald",
"age": 99,
"data": "data 5"
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Microsoft Excel 365",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "b9eda2d8-e1a5-4a54-aaa9-5e81adaae909",
"id": "135",
"meta": {
"instanceId": "36203ea1ce3cef713fa25999bd9874ae26b9e4c2c3a90a365f2882a154d031d0"
},
"tags": []
}
Loading

0 comments on commit 5364a2d

Please sign in to comment.