Files
n8n/packages/nodes-base/nodes/Evaluation/test/evaluationTriggerUtils.test.ts
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

103 lines
2.5 KiB
TypeScript

import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { readSheet } from '../../Google/Sheet/v2/actions/utils/readOperation';
import { GoogleSheet } from '../../Google/Sheet/v2/helpers/GoogleSheet';
import { getFilteredResults } from '../utils/evaluationTriggerUtils';
jest.mock('../../Google/Sheet/v2/actions/utils/readOperation', () => ({
readSheet: jest.fn(),
}));
describe('getFilteredResults', () => {
let mockThis: IExecuteFunctions;
let mockGoogleSheet: GoogleSheet;
beforeEach(() => {
// Mock the `this` context
mockThis = {
getNode: jest.fn().mockReturnValue({ typeVersion: 1 }),
} as unknown as IExecuteFunctions;
// Mock the GoogleSheet instance
mockGoogleSheet = new GoogleSheet('mockSpreadsheetId', mockThis);
// Reset mocks before each test
jest.clearAllMocks();
});
it('should return filtered results based on endingRow', async () => {
// Arrange
const mockOperationResult: INodeExecutionData[] = [];
const mockResult = { title: 'Sheet1', sheetId: 1 };
const startingRow = 1;
const endingRow = 3;
(readSheet as jest.Mock).mockResolvedValue([
{ json: { row_number: 1, data: 'Row 1' } },
{ json: { row_number: 2, data: 'Row 2' } },
{ json: { row_number: 3, data: 'Row 3' } },
{ json: { row_number: 4, data: 'Row 4' } },
]);
// Act
const result = await getFilteredResults.call(
mockThis,
mockOperationResult,
mockGoogleSheet,
mockResult,
startingRow,
endingRow,
);
// Assert
expect(readSheet).toHaveBeenCalledWith(
mockGoogleSheet,
'Sheet1',
0,
mockOperationResult,
1,
[],
undefined,
{
rangeDefinition: 'specifyRange',
headerRow: 1,
firstDataRow: startingRow,
includeHeadersWithEmptyCells: true,
},
);
expect(result).toEqual([
{ json: { row_number: 1, data: 'Row 1' } },
{ json: { row_number: 2, data: 'Row 2' } },
{ json: { row_number: 3, data: 'Row 3' } },
]);
});
it('should return an empty array if no rows match the filter', async () => {
// Arrange
const mockOperationResult: INodeExecutionData[] = [];
const mockResult = { title: 'Sheet1', sheetId: 1 };
const startingRow = 1;
const endingRow = 0;
(readSheet as jest.Mock).mockResolvedValue([
{ json: { row_number: 1, data: 'Row 1' } },
{ json: { row_number: 2, data: 'Row 2' } },
]);
// Act
const result = await getFilteredResults.call(
mockThis,
mockOperationResult,
mockGoogleSheet,
mockResult,
startingRow,
endingRow,
);
// Assert
expect(readSheet).toHaveBeenCalled();
expect(result).toEqual([]);
});
});