UNPKG

@sinch/mcp

Version:

Sinch MCP server

120 lines 4.95 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const mailgunHelper = __importStar(require("../../../src/tools/email/utils/mailgun-service-helper")); const types_1 = require("../../../src/types"); const list_email_templates_1 = require("../../../src/tools/email/list-email-templates"); // Mock fetch global.fetch = jest.fn(); describe('listEmailTemplatesHandler', () => { const mockCredentials = { domain: 'example.com', apiKey: 'test-api-key' }; beforeEach(() => { jest.resetAllMocks(); jest.spyOn(mailgunHelper, 'getMailgunCredentials').mockReturnValue(mockCredentials); }); it('returns formatted prompt response with templates', async () => { // Given const mockResponse = { items: [ { id: 'template1', name: 'my Template 1', description: 'The template #1', createdAt: 'Fri, 28 Mar 2025 17:42:30 UTC' }, { id: 'template2', name: 'my Template 2', description: 'The template #2', createdAt: 'Wed, 26 Mar 2025 11:11:48 UTC' } ] }; fetch.mockResolvedValue({ ok: true, json: async () => mockResponse }); // When const result = await (0, list_email_templates_1.listEmailTemplatesHandler)({}); // Then const expectedText = [ 'The following templates must be presented as an array ALL their data in 3 columns: Name, Description and Creation Date. Do not omit anything.', '', 'Found 2 Email templates for domain "example.com":', '', '| Name | Description | Creation Date |', '|------|-------------|---------------|', '| my Template 1 | The template #1 | 2025-03-28T17:42:30.000Z |', '| my Template 2 | The template #2 | 2025-03-26T11:11:48.000Z |\n' ].join('\n'); expect(result.role).toBe('assistant'); expect(result.content[0].text).toBe(expectedText); }); it('handles Mailgun API error', async () => { // Given fetch.mockResolvedValue({ ok: false, status: 403, statusText: 'Forbidden' }); // When const result = await (0, list_email_templates_1.listEmailTemplatesHandler)({}); // Then expect(result).toEqual(new types_1.PromptResponse('Mailgun API error: 403 Forbidden').promptResponse); }); it('handles JSON parse error', async () => { // Given fetch.mockResolvedValue({ ok: true, json: async () => { throw new Error('invalid json'); } }); // When const result = await (0, list_email_templates_1.listEmailTemplatesHandler)({}); // Then expect(result).toEqual(new types_1.PromptResponse('Failed to parse JSON response: Error: invalid json').promptResponse); }); it('returns early on credential fetch error', async () => { // Given jest.spyOn(mailgunHelper, 'getMailgunCredentials').mockReturnValue(new types_1.PromptResponse('Missing credentials')); // When const result = await (0, list_email_templates_1.listEmailTemplatesHandler)({}); // Then expect(result).toEqual(new types_1.PromptResponse('Missing credentials').promptResponse); }); }); //# sourceMappingURL=list-email-templates.test.js.map