|
1 | 1 | import { buildGatewayTargetConfig } from '../actions.js'; |
2 | 2 | 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 | +})); |
4 | 13 |
|
5 | 14 | describe('buildGatewayTargetConfig', () => { |
6 | 15 | it('maps name, gateway, language correctly', () => { |
@@ -66,3 +75,26 @@ describe('buildGatewayTargetConfig', () => { |
66 | 75 | expect(config.outboundAuth).toBeUndefined(); |
67 | 76 | }); |
68 | 77 | }); |
| 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 | +}); |
0 commit comments