fix(Google Sheets Node): Improve error message when row_number is null or undefined (#14560)

Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
This commit is contained in:
Dana
2025-06-05 16:02:15 +02:00
committed by GitHub
parent 1587eb0742
commit 47538e17ef
2 changed files with 89 additions and 10 deletions

View File

@@ -204,9 +204,27 @@ describe('Google Sheet - Update', () => {
'USER_ENTERED',
);
});
});
describe('Google Sheet - Update 4.6', () => {
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
let mockGoogleSheet: MockProxy<GoogleSheet>;
beforeEach(() => {
mockExecuteFunctions = mock<IExecuteFunctions>();
mockGoogleSheet = mock<GoogleSheet>();
mockExecuteFunctions.getNode.mockReturnValueOnce(mock<INode>({ 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',
});
},
);
});
});

View File

@@ -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) {