Skip to content

Commit a6ad226

Browse files
committed
test: add routing and validation tests for existing-endpoint flow
1 parent 35cce5a commit a6ad226

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/cli/commands/add/__tests__/actions.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { buildGatewayTargetConfig } from '../actions.js';
22
import type { ValidatedAddGatewayTargetOptions } from '../actions.js';
3-
import { describe, expect, it } from 'vitest';
3+
import { afterEach, describe, expect, it, vi } from 'vitest';
4+
5+
const mockCreateToolFromWizard = vi.fn().mockResolvedValue({ toolName: 'test', projectPath: '/tmp' });
6+
const mockCreateExternalGatewayTarget = vi.fn().mockResolvedValue({ toolName: 'test', projectPath: '' });
7+
8+
vi.mock('../../../operations/mcp/create-mcp', () => ({
9+
createToolFromWizard: (...args: unknown[]) => mockCreateToolFromWizard(...args),
10+
createExternalGatewayTarget: (...args: unknown[]) => mockCreateExternalGatewayTarget(...args),
11+
createGatewayFromWizard: vi.fn(),
12+
}));
413

514
describe('buildGatewayTargetConfig', () => {
615
it('maps name, gateway, language correctly', () => {
@@ -66,3 +75,26 @@ describe('buildGatewayTargetConfig', () => {
6675
expect(config.outboundAuth).toBeUndefined();
6776
});
6877
});
78+
79+
// Dynamic import to pick up mocks
80+
const { handleAddGatewayTarget } = await import('../actions.js');
81+
82+
describe('handleAddGatewayTarget', () => {
83+
afterEach(() => vi.clearAllMocks());
84+
85+
it('routes existing-endpoint to createExternalGatewayTarget', async () => {
86+
const options: ValidatedAddGatewayTargetOptions = {
87+
name: 'test-tool',
88+
language: 'Other',
89+
host: 'Lambda',
90+
source: 'existing-endpoint',
91+
endpoint: 'https://example.com/mcp',
92+
gateway: 'my-gw',
93+
};
94+
95+
await handleAddGatewayTarget(options);
96+
97+
expect(mockCreateExternalGatewayTarget).toHaveBeenCalledOnce();
98+
expect(mockCreateToolFromWizard).not.toHaveBeenCalled();
99+
});
100+
});

src/cli/commands/add/__tests__/validate.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,18 @@ describe('validate', () => {
422422
expect(result.valid).toBe(false);
423423
expect(result.error).toContain('--credential-name is required');
424424
});
425+
426+
it('rejects --host with existing-endpoint', async () => {
427+
const options: AddGatewayTargetOptions = {
428+
name: 'test-tool',
429+
source: 'existing-endpoint',
430+
endpoint: 'https://example.com/mcp',
431+
host: 'Lambda',
432+
};
433+
const result = await validateAddGatewayTargetOptions(options);
434+
expect(result.valid).toBe(false);
435+
expect(result.error).toBe('--host is not applicable for existing endpoint targets');
436+
});
425437
});
426438

427439
describe('validateAddMemoryOptions', () => {

0 commit comments

Comments
 (0)