UNPKG

@ibraheem4/eventbrite-mcp

Version:

An Eventbrite MCP server for interacting with Eventbrite's API

76 lines 3 kB
import { jest } from "@jest/globals"; // Mock environment variables process.env.EVENTBRITE_API_KEY = "test-api-key"; // Mock axios const mockGet = jest.fn(); jest.mock("axios", () => ({ create: jest.fn().mockReturnValue({ get: mockGet, defaults: { baseURL: "https://www.eventbriteapi.com/v3", headers: { Authorization: `Bearer test-api-key`, "Content-Type": "application/json", }, }, }), })); describe("Eventbrite API Client", () => { beforeEach(() => { // Clear all mocks before each test jest.clearAllMocks(); }); describe("getCategories", () => { it("should fetch categories successfully", async () => { // Mock the response const mockCategories = [ { id: "1", name: "Music" }, { id: "2", name: "Food & Drink" }, ]; mockGet.mockResolvedValueOnce({ data: { categories: mockCategories }, }); // Import the module dynamically to ensure mocks are applied const { default: eventbriteClient } = await import("../index.js"); // Call the method through the exported client const result = await eventbriteClient.getCategories(); // Assertions expect(mockGet).toHaveBeenCalledWith("/categories/"); expect(result).toEqual(mockCategories); }); it("should handle errors", async () => { // Mock an error response const errorMessage = "API Error"; mockGet.mockRejectedValueOnce(new Error(errorMessage)); // Import the module dynamically to ensure mocks are applied const { default: eventbriteClient } = await import("../index.js"); // Call the method and expect it to throw await expect(eventbriteClient.getCategories()).rejects.toThrow(); }); }); describe("searchEvents", () => { it("should search events successfully", async () => { // Mock the response const mockEvents = [ { id: "1", name: { text: "Concert" } }, { id: "2", name: { text: "Festival" } }, ]; mockGet.mockResolvedValueOnce({ data: { events: mockEvents, pagination: { page_count: 1 }, }, }); // Import the module dynamically to ensure mocks are applied const { default: eventbriteClient } = await import("../index.js"); // Call the method const result = await eventbriteClient.searchEvents({ q: "music" }); // Assertions expect(mockGet).toHaveBeenCalledWith("/events/search/", { params: { q: "music" }, }); expect(result.events).toEqual(mockEvents); }); }); }); //# sourceMappingURL=eventbrite-api.test.js.map