UNPKG

@sinch/mcp

Version:

Sinch MCP server

48 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const voice_service_helper_1 = require("../../../../src/tools/voice/utils/voice-service-helper"); const sdk_core_1 = require("@sinch/sdk-core"); const utils_1 = require("../../../../src/utils"); const mockApi = () => ({ setHostname: jest.fn(), }); jest.mock('@sinch/sdk-core', () => { const actual = jest.requireActual('@sinch/sdk-core'); return { ...actual, SinchClient: jest.fn(() => ({ voice: { callouts: mockApi(), conferences: mockApi(), }, })), }; }); describe('getVoiceService', () => { const OLD_ENV = process.env; const APPLICATION_KEY = 'test-application-key'; const TOOL_NAME = 'dummy-tool'; beforeEach(() => { jest.resetModules(); process.env = { ...OLD_ENV }; process.env.VOICE_APPLICATION_KEY = APPLICATION_KEY; process.env.VOICE_APPLICATION_SECRET = 'test-application-secret'; }); afterAll(() => { process.env = OLD_ENV; }); test('returns a configured SinchClient from getVoiceService', async () => { const client = (0, voice_service_helper_1.getVoiceClient)(TOOL_NAME); expect(client).toHaveProperty('voice'); const apis = client.voice; for (const api of Object.values(apis)) { expect(api.setHostname).toHaveBeenCalledWith(sdk_core_1.VOICE_HOSTNAME.replace('{region}', '')); expect(api.client).toBeInstanceOf(sdk_core_1.ApiFetchClient); const userAgentPlugin = api.client.apiClientOptions.requestPlugins?.find((plugin) => plugin.getName() === 'AdditionalHeadersRequest'); expect(userAgentPlugin).toBeDefined(); const expectedUserAgent = (0, utils_1.formatUserAgent)(TOOL_NAME, APPLICATION_KEY); expect((await userAgentPlugin.additionalHeaders.headers)['User-Agent']).toBe(expectedUserAgent); } }); }); //# sourceMappingURL=voice-service-helper.test.js.map