Download __tests__/api/cloud/git-service.test.ts from SaylorTwift/openhands: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/SaylorTwift/openhands/resolve/main/__tests__/api/cloud/git-service.test.ts
- Command line
-
hf download hf://SaylorTwift/openhands/__tests__/api/cloud/git-service.test.ts
-
curl -L -o git-service.test.ts https://huggingface.co/SaylorTwift/openhands/resolve/main/__tests__/api/cloud/git-service.test.ts
2.02 kB
| 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"); | |
| }); | |
| }); | |