Files
alighasami 3d5eaf9445
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

106 lines
3.3 KiB
TypeScript

import type { IExecuteFunctions } from 'n8n-workflow';
import { execute } from '../../../v2/actions/sheet/clear.operation';
import type { GoogleSheet } from '../../../v2/helpers/GoogleSheet';
describe('Google Sheet - Clear', () => {
let mockExecuteFunctions: Partial<IExecuteFunctions>;
let mockSheet: Partial<GoogleSheet>;
beforeEach(() => {
mockExecuteFunctions = {
getInputData: jest.fn().mockReturnValue([{ json: {} }]),
getNodeParameter: jest.fn(),
} as Partial<IExecuteFunctions>;
mockSheet = {
clearData: jest.fn(),
getData: jest.fn().mockResolvedValue([['Header1', 'Header2']]), // Mock first-row data
updateRows: jest.fn(),
} as Partial<GoogleSheet>;
});
test('should clear the whole sheet', async () => {
mockExecuteFunctions.getNodeParameter = jest.fn((param: string) => {
if (param === 'clear') return 'wholeSheet';
return false;
}) as unknown as IExecuteFunctions['getNodeParameter'];
await execute.call(
mockExecuteFunctions as IExecuteFunctions,
mockSheet as GoogleSheet,
'Sheet1',
);
expect(mockSheet.clearData).toHaveBeenCalledWith('Sheet1');
});
test('should clear specific rows', async () => {
mockExecuteFunctions.getNodeParameter = jest.fn((param: string) => {
if (param === 'clear') return 'specificRows';
if (param === 'startIndex') return 2;
if (param === 'rowsToDelete') return 3;
return false;
}) as unknown as IExecuteFunctions['getNodeParameter'];
await execute.call(
mockExecuteFunctions as IExecuteFunctions,
mockSheet as GoogleSheet,
'Sheet1',
);
expect(mockSheet.clearData).toHaveBeenCalledWith('Sheet1!2:4');
});
test('should clear specific columns', async () => {
mockExecuteFunctions.getNodeParameter = jest.fn((param: string) => {
if (param === 'clear') return 'specificColumns';
if (param === 'startIndex') return 'B';
if (param === 'columnsToDelete') return 2;
return false;
}) as unknown as IExecuteFunctions['getNodeParameter'];
await execute.call(
mockExecuteFunctions as IExecuteFunctions,
mockSheet as GoogleSheet,
'Sheet1',
);
expect(mockSheet.clearData).toHaveBeenCalledWith('Sheet1!B:C');
});
test('should clear a specific range', async () => {
mockExecuteFunctions.getNodeParameter = jest.fn((param: string) => {
if (param === 'clear') return 'specificRange';
if (param === 'range') return 'A1:C5';
return false;
}) as unknown as IExecuteFunctions['getNodeParameter'];
await execute.call(
mockExecuteFunctions as IExecuteFunctions,
mockSheet as GoogleSheet,
'Sheet1',
);
expect(mockSheet.clearData).toHaveBeenCalledWith('Sheet1!A1:C5');
});
test('should keep the first row when clearing the whole sheet', async () => {
mockExecuteFunctions.getNodeParameter = jest.fn((param: string) => {
if (param === 'clear') return 'wholeSheet';
if (param === 'keepFirstRow') return true;
return false;
}) as unknown as IExecuteFunctions['getNodeParameter'];
await execute.call(
mockExecuteFunctions as IExecuteFunctions,
mockSheet as GoogleSheet,
'Sheet1',
);
expect(mockSheet.getData).toHaveBeenCalledWith('Sheet1!1:1', 'FORMATTED_VALUE');
expect(mockSheet.clearData).toHaveBeenCalledWith('Sheet1');
expect(mockSheet.updateRows).toHaveBeenCalledWith('Sheet1', [['Header1', 'Header2']], 'RAW', 1);
});
});