Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Google Sheets Node): Accommodate special characters when updating row #13589

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 106 additions & 3 deletions packages/nodes-base/nodes/Google/Sheet/test/v2/node/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -29,7 +37,6 @@ describe('Google Sheet - Update', () => {
},
]);

mockExecuteFunctions.getNode.mockReturnValueOnce(mock<INode>({ typeVersion: 4.5 }));
mockExecuteFunctions.getNodeParameter
.mockReturnValueOnce('USER_ENTERED') // valueInputMode
.mockReturnValueOnce({}); // options
Expand Down Expand Up @@ -58,8 +65,6 @@ describe('Google Sheet - Update', () => {
],
});

mockGoogleSheet.batchUpdate.mockResolvedValueOnce([]);

await execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1');

expect(mockGoogleSheet.getData).toHaveBeenCalledWith('Sheet1', 'FORMATTED_VALUE');
Expand Down Expand Up @@ -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',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading