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 899014a3c1c79..35d824569863d 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 @@ -12,6 +12,14 @@ describe('Google Sheet - Update', () => { beforeEach(() => { mockExecuteFunctions = mock(); mockGoogleSheet = mock(); + + mockExecuteFunctions.getNode.mockReturnValueOnce(mock({ typeVersion: 4.5 })); + + mockGoogleSheet.batchUpdate.mockResolvedValueOnce([]); + }); + + afterEach(() => { + jest.resetAllMocks(); }); it('should update by row_number and not insert it as a new column', async () => { @@ -29,7 +37,6 @@ describe('Google Sheet - Update', () => { }, ]); - mockExecuteFunctions.getNode.mockReturnValueOnce(mock({ typeVersion: 4.5 })); mockExecuteFunctions.getNodeParameter .mockReturnValueOnce('USER_ENTERED') // valueInputMode .mockReturnValueOnce({}); // options @@ -58,8 +65,6 @@ describe('Google Sheet - Update', () => { ], }); - mockGoogleSheet.batchUpdate.mockResolvedValueOnce([]); - await execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1'); expect(mockGoogleSheet.getData).toHaveBeenCalledWith('Sheet1', 'FORMATTED_VALUE'); @@ -101,4 +106,102 @@ describe('Google Sheet - Update', () => { 'USER_ENTERED', ); }); + + it('should update rows by column values with special character', async () => { + mockExecuteFunctions.getInputData.mockReturnValueOnce([ + { + json: { + row_number: 3, + name: '** δ$% " []', + text: 'δ$% " []', + }, + pairedItem: { + item: 0, + input: undefined, + }, + }, + ]); + + mockExecuteFunctions.getNodeParameter.mockImplementation((parameterName: string) => { + const params: { [key: string]: string | object } = { + options: {}, + 'options.cellFormat': 'USER_ENTERED', + 'columns.matchingColumns': ['row_number'], + 'columns.value': { + 'ha []': 'kayyyy$', + macarena: 'baile', + 'Real.1': 't&c', + '21 "': 'Σ', + }, + dataMode: 'autoMapInputData', + }; + return params[parameterName]; + }); + + mockGoogleSheet.getData.mockResolvedValueOnce([ + ['Real.1', '21 "', 'dfd', 'ha []', 'macarena'], + ['aye.2', '"book"', 'ee', 'dd', 'dance'], + ['t&c', 'Σ', 'baz', 'kayyyy$', 'baile'], + ['fudge.2', '9080', 'live', 'dog', 'brazil'], + ]); + + mockGoogleSheet.getColumnValues.mockResolvedValueOnce([]); + + mockGoogleSheet.prepareDataForUpdatingByRowNumber.mockReturnValueOnce({ + updateData: [ + { + range: 'Sheet1!B3', + values: [['** δ$% " []']], + }, + { + range: 'Sheet1!C3', + values: [['δ$% " []']], + }, + ], + }); + + await execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1'); + + expect(mockGoogleSheet.getData).toHaveBeenCalledWith('Sheet1', 'FORMATTED_VALUE'); + + expect(mockGoogleSheet.getColumnValues).toHaveBeenCalledWith({ + range: 'Sheet1!A:Z', + keyIndex: -1, + dataStartRowIndex: 1, + valueRenderMode: 'UNFORMATTED_VALUE', + sheetData: [ + ['Real.1', '21 "', 'dfd', 'ha []', 'macarena'], + ['aye.2', '"book"', 'ee', 'dd', 'dance'], + ['t&c', 'Σ', 'baz', 'kayyyy$', 'baile'], + ['fudge.2', '9080', 'live', 'dog', 'brazil'], + ], + }); + + expect(mockGoogleSheet.prepareDataForUpdatingByRowNumber).toHaveBeenCalledWith( + [ + { + '21 "': 'Σ', + 'Real.1': 't&c', + 'ha []': 'kayyyy$', + macarena: 'baile', + }, + ], + 'Sheet1!A:Z', + [['Real.1', '21 "', 'dfd', 'ha []', 'macarena']], + ); + + expect(mockGoogleSheet.batchUpdate).toHaveBeenCalledWith( + [ + { + range: 'Sheet1!B3', + values: [['** δ$% " []']], + }, + { + range: 'Sheet1!C3', + values: [['δ$% " []']], + }, + ], + 'USER_ENTERED', + ); + }); }); 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 83331ea7e5594..c457832d6e4fd 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 @@ -320,7 +320,7 @@ export async function execute( const valueToMatchOn = nodeVersion < 4 ? (this.getNodeParameter('valueToMatchOn', i, '') as string) - : (this.getNodeParameter(`columns.value[${columnsToMatchOn[0]}]`, i, '') as string); + : (this.getNodeParameter(`columns.value["${columnsToMatchOn[0]}"]`, i, '') as string); if (valueToMatchOn === '') { throw new NodeOperationError(