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
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import type { ILoadOptionsFunctions } from 'n8n-workflow';
|
|
|
|
import { getUsers } from '../GenericFunctions';
|
|
|
|
describe('getUsers', () => {
|
|
const mockHighLevelApiRequest = jest.fn();
|
|
const mockGetCredentials = jest.fn();
|
|
const mockContext = {
|
|
getCredentials: mockGetCredentials,
|
|
helpers: {
|
|
httpRequestWithAuthentication: mockHighLevelApiRequest,
|
|
},
|
|
} as unknown as ILoadOptionsFunctions;
|
|
|
|
beforeEach(() => {
|
|
mockHighLevelApiRequest.mockClear();
|
|
mockGetCredentials.mockClear();
|
|
});
|
|
|
|
it('should return a list of users', async () => {
|
|
const mockUsers = [
|
|
{ id: '1', name: 'John Doe', email: 'john.doe@example.com' },
|
|
{ id: '2', name: 'Jane Smith', email: 'jane.smith@example.com' },
|
|
];
|
|
|
|
mockHighLevelApiRequest.mockResolvedValue({ users: mockUsers });
|
|
mockGetCredentials.mockResolvedValue({ oauthTokenData: { locationId: '123' } });
|
|
|
|
const response = await getUsers.call(mockContext);
|
|
|
|
expect(response).toEqual([
|
|
{ name: 'John Doe', value: '1' },
|
|
{ name: 'Jane Smith', value: '2' },
|
|
]);
|
|
});
|
|
|
|
it('should handle empty users list', async () => {
|
|
mockHighLevelApiRequest.mockResolvedValue({ users: [] });
|
|
mockGetCredentials.mockResolvedValue({ oauthTokenData: { locationId: '123' } });
|
|
|
|
const response = await getUsers.call(mockContext);
|
|
|
|
expect(response).toEqual([]);
|
|
});
|
|
});
|