mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
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:
@@ -204,9 +204,27 @@ describe('Google Sheet - Update', () => {
|
|||||||
'USER_ENTERED',
|
'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', () => {
|
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',
|
'displays a helpful error message when row_number is $rowNumber',
|
||||||
async ({ rowNumber }) => {
|
async ({ rowNumber }) => {
|
||||||
mockExecuteFunctions.getInputData.mockReturnValueOnce([
|
mockExecuteFunctions.getInputData.mockReturnValueOnce([
|
||||||
@@ -240,10 +258,64 @@ describe('Google Sheet - Update', () => {
|
|||||||
|
|
||||||
mockGoogleSheet.getColumnValues.mockResolvedValueOnce([]);
|
mockGoogleSheet.getColumnValues.mockResolvedValueOnce([]);
|
||||||
|
|
||||||
await expect(execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1')).rejects.toThrow(
|
await expect(execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1')).rejects.toEqual(
|
||||||
'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.',
|
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',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -369,13 +369,20 @@ export async function execute(
|
|||||||
}
|
}
|
||||||
// Setting empty values to empty string so that they are not ignored by the API
|
// Setting empty values to empty string so that they are not ignored by the API
|
||||||
Object.keys(mappingValues).forEach((key) => {
|
Object.keys(mappingValues).forEach((key) => {
|
||||||
if (
|
// null and undefined values are mapped to undefined
|
||||||
key === 'row_number' &&
|
if (key === 'row_number' && mappingValues[key] === undefined && nodeVersion >= 4.6) {
|
||||||
(mappingValues[key] === null || mappingValues[key] === undefined)
|
throw new UserError('row_number is null or undefined', {
|
||||||
) {
|
description:
|
||||||
throw new UserError(
|
"Since it's being used to determine the row to update, it cannot be null or undefined",
|
||||||
'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 (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) {
|
if (mappingValues[key] === undefined || mappingValues[key] === null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user