mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-11-02 11:48:57 +08:00
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.
69 lines
2.1 KiB
TypeScript
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");
|
|
});
|
|
});
|