75 lines
2.6 KiB
JavaScript
75 lines
2.6 KiB
JavaScript
// @vitest-environment jsdom
|
|
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const { axiosMock } = vi.hoisted(() => ({
|
|
axiosMock: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("axios", () => ({
|
|
default: axiosMock,
|
|
}));
|
|
|
|
import {
|
|
clearReleaseManagerControlApiUrl,
|
|
getReleaseManagerControlApiUrl,
|
|
getReleaseSummary,
|
|
RELEASE_MANAGER_CONTROL_API_STORAGE_KEY,
|
|
releaseManagerControlApiCandidates,
|
|
setReleaseManagerControlApiUrl,
|
|
} from "@/services/superuserReleases.js";
|
|
import { __configureRequestQueueForTests, __resetRequestQueueForTests } from "@/services/requestQueue.js";
|
|
|
|
describe("superuser release manager service", () => {
|
|
beforeEach(() => {
|
|
axiosMock.mockReset();
|
|
localStorage.clear();
|
|
sessionStorage.clear();
|
|
localStorage.setItem("token", "release-token");
|
|
__resetRequestQueueForTests();
|
|
__configureRequestQueueForTests({
|
|
maxConcurrentGet: 1,
|
|
maxConcurrentOther: 1,
|
|
spacingMs: 0,
|
|
retryByStatusCode: {},
|
|
});
|
|
});
|
|
|
|
it("keeps release manager calls on the explicit control API", async () => {
|
|
setReleaseManagerControlApiUrl("https://control.example.test/");
|
|
axiosMock.mockResolvedValueOnce({ status: 200, data: { data: { channels: [] } } });
|
|
|
|
await getReleaseSummary();
|
|
|
|
expect(getReleaseManagerControlApiUrl()).toBe("https://control.example.test");
|
|
expect(axiosMock).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
url: "https://control.example.test/superuser/releases",
|
|
method: "GET",
|
|
headers: expect.objectContaining({ Authorization: "Bearer release-token" }),
|
|
})
|
|
);
|
|
});
|
|
|
|
it("falls back when the selected API does not have release manager endpoints", async () => {
|
|
localStorage.setItem(RELEASE_MANAGER_CONTROL_API_STORAGE_KEY, "https://api.truckwash.io");
|
|
axiosMock
|
|
.mockRejectedValueOnce({ response: { status: 404 } })
|
|
.mockResolvedValueOnce({ status: 200, data: { data: { channels: [] } } });
|
|
|
|
await getReleaseSummary();
|
|
|
|
expect(axiosMock.mock.calls[0][0].url).toBe("https://api.truckwash.io/superuser/releases");
|
|
expect(axiosMock.mock.calls[1][0].url).toBe("https://api.truckwash.io:4433/superuser/releases");
|
|
expect(releaseManagerControlApiCandidates()[0]).toBe("https://api.truckwash.io:4433");
|
|
});
|
|
|
|
it("can clear the explicit control API override", () => {
|
|
setReleaseManagerControlApiUrl("https://control.example.test");
|
|
clearReleaseManagerControlApiUrl();
|
|
|
|
expect(localStorage.getItem(RELEASE_MANAGER_CONTROL_API_STORAGE_KEY)).toBeNull();
|
|
expect(releaseManagerControlApiCandidates()).toContain("https://api.truckwash.io:4433");
|
|
});
|
|
});
|