mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(Google Sheets Node): Accommodate special characters when updating row (#13589)
This commit is contained in:
parent
20dfaa3be6
commit
e633e91f69
|
@ -12,6 +12,14 @@ describe('Google Sheet - Update', () => {
|
|||
beforeEach(() => {
|
||||
mockExecuteFunctions = mock<IExecuteFunctions>();
|
||||
mockGoogleSheet = mock<GoogleSheet>();
|
||||
|
||||
mockExecuteFunctions.getNode.mockReturnValueOnce(mock<INode>({ 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<INode>({ 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',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue