mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-10-07 16:38:34 +08:00
* Move cloud transport to typescript client * docs: add issue 1648 live evidence * test: align automation cloud import with proxy client Co-authored-by: OpenHands <openhands@all-hands.dev> * fix: handle shared-client HttpError shapes at cloud call sites * chore: Remove PR-only artifacts --------- Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: hieptl <hieptl.developer@gmail.com> Co-authored-by: allhands-bot <allhands-bot@users.noreply.github.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
__resetActiveStoreForTests,
|
|
setActiveSelection,
|
|
setRegisteredBackends,
|
|
} from "#/api/backend-registry/active-store";
|
|
import type { Backend } from "#/api/backend-registry/types";
|
|
import { getCloudRepositoryBranches } from "#/api/cloud/git-service.api";
|
|
import { getFetchCall, mockJsonResponse } from "./fetch-test-utils";
|
|
|
|
const cloudBackend: Backend = {
|
|
id: "prod",
|
|
name: "Production",
|
|
host: "https://app.all-hands.dev",
|
|
apiKey: "bearer-token",
|
|
kind: "cloud",
|
|
};
|
|
|
|
const emptyBranchPage = { items: [], next_page_id: null };
|
|
const originalFetch = global.fetch;
|
|
const fetchMock = vi.fn();
|
|
|
|
beforeEach(() => {
|
|
window.localStorage.clear();
|
|
__resetActiveStoreForTests();
|
|
setRegisteredBackends([cloudBackend]);
|
|
setActiveSelection({ backendId: cloudBackend.id });
|
|
fetchMock.mockReset();
|
|
fetchMock.mockResolvedValue(mockJsonResponse(emptyBranchPage));
|
|
global.fetch = fetchMock as typeof fetch;
|
|
});
|
|
|
|
afterEach(() => {
|
|
window.localStorage.clear();
|
|
__resetActiveStoreForTests();
|
|
fetchMock.mockReset();
|
|
global.fetch = originalFetch;
|
|
});
|
|
|
|
describe("getCloudRepositoryBranches", () => {
|
|
it("includes an empty query parameter when listing all branches so the upstream schema is satisfied", async () => {
|
|
// Act
|
|
await getCloudRepositoryBranches({
|
|
provider: "github",
|
|
repository: "hieptl/hieptl",
|
|
});
|
|
|
|
// Assert
|
|
const [url, init] = getFetchCall(fetchMock);
|
|
expect(init).toMatchObject({
|
|
method: "GET",
|
|
headers: { Authorization: "Bearer bearer-token" },
|
|
});
|
|
expect(url).toMatch(/[?&]query=(&|$)/);
|
|
});
|
|
|
|
it("forwards a non-empty query parameter when searching branches", async () => {
|
|
// Act
|
|
await getCloudRepositoryBranches({
|
|
provider: "github",
|
|
repository: "hieptl/hieptl",
|
|
query: "feature/login",
|
|
});
|
|
|
|
// Assert
|
|
const [url] = getFetchCall(fetchMock);
|
|
expect(url).toContain("query=feature%2Flogin");
|
|
});
|
|
});
|