diff --git a/packages/nodes-base/nodes/Google/Sheet/test/v2/node/update.test.ts b/packages/nodes-base/nodes/Google/Sheet/test/v2/node/update.test.ts index 3694c35618..77d249f609 100644 --- a/packages/nodes-base/nodes/Google/Sheet/test/v2/node/update.test.ts +++ b/packages/nodes-base/nodes/Google/Sheet/test/v2/node/update.test.ts @@ -204,9 +204,27 @@ describe('Google Sheet - Update', () => { 'USER_ENTERED', ); }); +}); + +describe('Google Sheet - Update 4.6', () => { + let mockExecuteFunctions: MockProxy; + let mockGoogleSheet: MockProxy; + + beforeEach(() => { + mockExecuteFunctions = mock(); + mockGoogleSheet = mock(); + + mockExecuteFunctions.getNode.mockReturnValueOnce(mock({ typeVersion: 4.6 })); + + mockGoogleSheet.batchUpdate.mockResolvedValueOnce([]); + }); + + afterEach(() => { + jest.resetAllMocks(); + }); describe('row_number input error', () => { - it.each([{ rowNumber: undefined }, { rowNumber: null }])( + it.each([{ rowNumber: undefined }])( 'displays a helpful error message when row_number is $rowNumber', async ({ rowNumber }) => { mockExecuteFunctions.getInputData.mockReturnValueOnce([ @@ -240,10 +258,64 @@ describe('Google Sheet - Update', () => { mockGoogleSheet.getColumnValues.mockResolvedValueOnce([]); - await expect(execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1')).rejects.toThrow( - 'Column to match on (row_number) is not defined. Since the field is used to determine the row to update, it needs to have a value set.', + await expect(execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1')).rejects.toEqual( + expect.objectContaining({ + message: 'row_number is null or undefined', + description: + "Since it's being used to determine the row to update, it cannot be null or undefined", + }), ); }, ); }); + + describe('non-row_number undefined', () => { + it.each([{ nonRowNumber: undefined }])( + 'displays a helpful error message when row_number is $rowNumber', + async ({ nonRowNumber }) => { + mockExecuteFunctions.getInputData.mockReturnValueOnce([ + { + json: { + row_number: 2, + nonRowNumber: 'name', + text: 'txt', + }, + pairedItem: { + item: 0, + input: undefined, + }, + }, + ]); + + mockExecuteFunctions.getNodeParameter.mockImplementation((parameterName: string) => { + const params: { [key: string]: string | object } = { + options: {}, + 'options.cellFormat': 'USER_ENTERED', + 'columns.matchingColumns': ['nonRowNumber'], + 'columns.value': { + nonRowNumber, + }, + dataMode: 'defineBelow', + }; + return params[parameterName]; + }); + + mockGoogleSheet.getData.mockResolvedValueOnce([['macarena'], ['boomboom']]); + + mockGoogleSheet.getColumnValues.mockResolvedValueOnce([]); + + mockGoogleSheet.prepareDataForUpdateOrUpsert.mockResolvedValueOnce({ + updateData: [], + appendData: [], + }); + + await execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1'); + + expect(mockExecuteFunctions.addExecutionHints).toHaveBeenCalledWith({ + message: 'Warning: The value of column to match is null or undefined', + location: 'outputPane', + }); + }, + ); + }); }); diff --git a/packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/update.operation.ts b/packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/update.operation.ts index 1a5b52c2ac..6b40ec152f 100644 --- a/packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/update.operation.ts +++ b/packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/update.operation.ts @@ -369,13 +369,20 @@ export async function execute( } // Setting empty values to empty string so that they are not ignored by the API Object.keys(mappingValues).forEach((key) => { - if ( - key === 'row_number' && - (mappingValues[key] === null || mappingValues[key] === undefined) - ) { - throw new UserError( - 'Column to match on (row_number) is not defined. Since the field is used to determine the row to update, it needs to have a value set.', - ); + // null and undefined values are mapped to undefined + if (key === 'row_number' && mappingValues[key] === undefined && nodeVersion >= 4.6) { + throw new UserError('row_number is null or undefined', { + description: + "Since it's being used to determine the row to update, it cannot be null or undefined", + }); + } + + // null and undefined values are mapped to undefined + if (mappingValues[key] === undefined) { + this.addExecutionHints({ + message: 'Warning: The value of column to match is null or undefined', + location: 'outputPane', + }); } if (mappingValues[key] === undefined || mappingValues[key] === null) {