/** * @file Pins where a workspace git call goes: the workspace's own routes, or — * for a session's worktree target — the same routes with `?session=`, which * the server resolves to that session's worktree. * @author Nguyễn Ngọc Trí Vĩ */ import { describe, it, expect, vi, afterEach } from "vitest"; import { api, gitTarget } from "../api"; afterEach(() => { vi.unstubAllGlobals(); }); function stubFetch() { const spy = vi.fn().mockResolvedValue({ ok: true, status: 200, headers: { get: () => "application/json" }, json: async () => ({}), }); vi.stubGlobal("fetch", spy); return spy; } describe("git targets", () => { it("adds session= for a worktree target and nothing for the workspace", async () => { const spy = stubFetch(); await api.lanes.changes(3, { range: "work" }); await api.lanes.changes(gitTarget(3, "s-1"), { range: "work" }); await api.lanes.gitAction(gitTarget(3, "s-1"), "stage", { paths: ["a"] }); await api.lanes.git(gitTarget(3, null)); const urls = spy.mock.calls.map((c) => String(c[0])); expect(urls[0]).toMatch(/\/lanes\/3\/git\/changes\?range=work$/); expect(urls[1]).toMatch(/\/lanes\/3\/git\/changes\?range=work&session=s-1$/); expect(urls[2]).toMatch(/\/lanes\/3\/git\/stage\?session=s-1$/); expect(urls[3]).toMatch(/\/lanes\/3\/git$/); }); });