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

117 lines
3.6 KiB
TypeScript

import type { IDataObject, ILoadOptionsFunctions } from 'n8n-workflow';
import { getProjects } from '../methods/listSearch';
describe('Currents listSearch', () => {
describe('getProjects', () => {
let mockContext: Partial<ILoadOptionsFunctions>;
let mockHttpRequest: jest.Mock;
beforeEach(() => {
mockHttpRequest = jest.fn();
mockContext = {
helpers: {
httpRequestWithAuthentication: mockHttpRequest,
} as unknown as ILoadOptionsFunctions['helpers'],
};
});
it('should return projects sorted by name', async () => {
const mockProjects: IDataObject[] = [
{ projectId: 'proj2', name: 'Zebra Project' },
{ projectId: 'proj1', name: 'Alpha Project' },
{ projectId: 'proj3', name: 'Beta Project' },
];
mockHttpRequest.mockResolvedValue({ data: mockProjects });
const result = await getProjects.call(mockContext as ILoadOptionsFunctions);
expect(result.results).toEqual([
{ name: 'Alpha Project', value: 'proj1' },
{ name: 'Beta Project', value: 'proj3' },
{ name: 'Zebra Project', value: 'proj2' },
]);
});
it('should filter projects by name (case-insensitive)', async () => {
const mockProjects: IDataObject[] = [
{ projectId: 'proj1', name: 'Test Project' },
{ projectId: 'proj2', name: 'Production' },
{ projectId: 'proj3', name: 'Testing Environment' },
];
mockHttpRequest.mockResolvedValue({ data: mockProjects });
const result = await getProjects.call(mockContext as ILoadOptionsFunctions, 'test');
expect(result.results).toEqual([
{ name: 'Test Project', value: 'proj1' },
{ name: 'Testing Environment', value: 'proj3' },
]);
});
it('should filter projects by projectId (case-insensitive)', async () => {
const mockProjects: IDataObject[] = [
{ projectId: 'ABC123', name: 'Project A' },
{ projectId: 'DEF456', name: 'Project B' },
{ projectId: 'abc789', name: 'Project C' },
];
mockHttpRequest.mockResolvedValue({ data: mockProjects });
const result = await getProjects.call(mockContext as ILoadOptionsFunctions, 'abc');
expect(result.results).toEqual([
{ name: 'Project A', value: 'ABC123' },
{ name: 'Project C', value: 'abc789' },
]);
});
it('should handle empty project list', async () => {
mockHttpRequest.mockResolvedValue({ data: [] });
const result = await getProjects.call(mockContext as ILoadOptionsFunctions);
expect(result.results).toEqual([]);
});
it('should handle missing data property', async () => {
mockHttpRequest.mockResolvedValue({});
const result = await getProjects.call(mockContext as ILoadOptionsFunctions);
expect(result.results).toEqual([]);
});
it('should call API with correct parameters', async () => {
mockHttpRequest.mockResolvedValue({ data: [] });
await getProjects.call(mockContext as ILoadOptionsFunctions);
expect(mockHttpRequest).toHaveBeenCalledWith('currentsApi', {
method: 'GET',
url: 'https://api.currents.dev/v1/projects',
});
});
it('should handle projects with missing name gracefully', async () => {
const mockProjects: IDataObject[] = [
{ projectId: 'proj1', name: 'Valid Project' },
{ projectId: 'proj2' }, // missing name - should use projectId as fallback
];
mockHttpRequest.mockResolvedValue({ data: mockProjects });
const result = await getProjects.call(mockContext as ILoadOptionsFunctions);
// Should use projectId as name fallback when name is missing
expect(result.results).toEqual([
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
{ name: 'proj2', value: 'proj2' }, // projectId used as name
{ name: 'Valid Project', value: 'proj1' },
]);
});
});
});