fix(Google Sheets Node): Check for column names changes before upsert, append, update (#9649)

This commit is contained in:
Michael Kret
2024-06-20 16:19:16 +03:00
committed by GitHub
parent cdc2f9e7d3
commit 223488f190
7 changed files with 127 additions and 8 deletions

View File

@@ -1,8 +1,9 @@
import type { IExecuteFunctions, INode } from 'n8n-workflow';
import type { IExecuteFunctions, INode, ResourceMapperField } from 'n8n-workflow';
import { GoogleSheet } from '../../../v2/helpers/GoogleSheet';
import {
addRowNumber,
autoMapInputData,
checkForSchemaChanges,
prepareSheetData,
removeEmptyColumns,
removeEmptyRows,
@@ -400,3 +401,46 @@ describe('Test Google Sheets, lookupValues', () => {
]);
});
});
describe('Test Google Sheets, checkForSchemaChanges', () => {
it('should not to throw error', async () => {
const node: INode = {
id: '1',
name: 'Google Sheets',
typeVersion: 4.4,
type: 'n8n-nodes-base.googleSheets',
position: [60, 760],
parameters: {
operation: 'append',
},
};
expect(() =>
checkForSchemaChanges(node, ['id', 'name', 'data'], [
{ id: 'id' },
{ id: 'name' },
{ id: 'data' },
] as ResourceMapperField[]),
).not.toThrow();
});
it('should throw error when columns were renamed', async () => {
const node: INode = {
id: '1',
name: 'Google Sheets',
typeVersion: 4.4,
type: 'n8n-nodes-base.googleSheets',
position: [60, 760],
parameters: {
operation: 'append',
},
};
expect(() =>
checkForSchemaChanges(node, ['id', 'name', 'data'], [
{ id: 'id' },
{ id: 'name' },
{ id: 'text' },
] as ResourceMapperField[]),
).toThrow("Column names were updated after the node's setup");
});
});