Files
galaxy/client-api/src/client.test.ts
T
Dannon Baker a9e554b887 Update openapi-fetch to 0.15.0 and align client-api dependencies
Bumped openapi-fetch from 0.10.6/0.12.0 to 0.15.0 in both client and
client-api packages. Also aligned client-api's vitest (4.0.14) and
typescript (5.7.3) versions with the main client. Updated test
assertions to match the headers object that createGalaxyApi passes.
2026-02-02 18:15:49 -05:00

69 lines
2.1 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
import { createGalaxyApi } from "./client";
// Create a mock API client for testing
const mockApiClient = {
GET: vi.fn(),
POST: vi.fn(),
PUT: vi.fn(),
DELETE: vi.fn(),
PATCH: vi.fn(),
};
// Mock createClient before importing
vi.mock("openapi-fetch", () => {
return {
default: vi.fn().mockImplementation(() => mockApiClient),
};
});
import createClient from "openapi-fetch";
describe("Galaxy API Client", () => {
beforeEach(() => {
// Reset mock function calls before each test
vi.clearAllMocks();
});
it("creates a client with the default base URL", () => {
// Set up window.location.origin for testing
const originalLocation = window.location;
delete (window as any).location;
window.location = { ...originalLocation, origin: "https://test-galaxy.org" } as any;
const api = createGalaxyApi();
expect(createClient).toHaveBeenCalledWith({ baseUrl: "https://test-galaxy.org", headers: {} });
// Restore window.location
window.location = originalLocation;
});
it("creates a client with a custom base URL", () => {
const customUrl = "https://usegalaxy.org";
const api = createGalaxyApi(customUrl);
expect(createClient).toHaveBeenCalledWith({ baseUrl: customUrl, headers: {} });
});
it("strips trailing slash from base URL", () => {
const customUrl = "https://usegalaxy.org/";
const expectedUrl = "https://usegalaxy.org";
const api = createGalaxyApi(customUrl);
expect(createClient).toHaveBeenCalledWith({ baseUrl: expectedUrl, headers: {} });
});
it("returns the configured client", () => {
const api = createGalaxyApi();
// Should have all the HTTP methods
expect(api).toEqual(mockApiClient);
expect(api).toHaveProperty("GET");
expect(api).toHaveProperty("POST");
expect(api).toHaveProperty("PUT");
expect(api).toHaveProperty("DELETE");
expect(api).toHaveProperty("PATCH");
});
});