summaryrefslogtreecommitdiffhomepage
path: root/src/features/workspaces/adapter/http.test.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-28 15:29:55 +0900
committerAdam Malczewski <[email protected]>2026-06-28 15:29:55 +0900
commitded7cc4ebf872556b4ab16bac81c1b551d8e44da (patch)
tree0f5cbed2405f83a819032a551295490b70e31d1d /src/features/workspaces/adapter/http.test.ts
parent3899ecef48325014a3bb5d6333a7a3e1fc34296a (diff)
parent60aa5dc48b6af502f88befd7d1517ab52cf6c60f (diff)
downloaddispatch-web-ded7cc4ebf872556b4ab16bac81c1b551d8e44da.tar.gz
dispatch-web-ded7cc4ebf872556b4ab16bac81c1b551d8e44da.zip
Merge branch 'feature/workspace-star' into predev
# Conflicts: # backend-handoff.md # src/features/workspaces/ui/WorkspaceCard.test.ts
Diffstat (limited to 'src/features/workspaces/adapter/http.test.ts')
-rw-r--r--src/features/workspaces/adapter/http.test.ts56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/features/workspaces/adapter/http.test.ts b/src/features/workspaces/adapter/http.test.ts
index 19e53f8..18d8939 100644
--- a/src/features/workspaces/adapter/http.test.ts
+++ b/src/features/workspaces/adapter/http.test.ts
@@ -130,4 +130,60 @@ describe("createWorkspaceHttp", () => {
const result = await http.delete("default");
expect(result).toEqual({ ok: false, error: "cannot delete default" });
});
+
+ it("star PUTs /star with no body and returns the updated workspace", async () => {
+ const ws = {
+ id: "a",
+ title: "A",
+ defaultCwd: null,
+ defaultComputerId: null,
+ starred: true,
+ createdAt: 1,
+ lastActivityAt: 2,
+ };
+ const fetchImpl = fakeFetch([{ body: ws }]);
+ const http = createWorkspaceHttp(BASE, fetchImpl);
+ const result = await http.star("a");
+ expect(result).toEqual({ ok: true, value: ws });
+ const call = (fetchImpl as unknown as ReturnType<typeof vi.fn>).mock.calls[0];
+ expect(call?.[0]).toBe(`${BASE}/workspaces/a/star`);
+ expect(call?.[1]).toEqual({ method: "PUT" });
+ });
+
+ it("unstar DELETEs /star with no body and returns the updated workspace", async () => {
+ const ws = {
+ id: "a",
+ title: "A",
+ defaultCwd: null,
+ defaultComputerId: null,
+ starred: false,
+ createdAt: 1,
+ lastActivityAt: 2,
+ };
+ const fetchImpl = fakeFetch([{ body: ws }]);
+ const http = createWorkspaceHttp(BASE, fetchImpl);
+ const result = await http.unstar("a");
+ expect(result).toEqual({ ok: true, value: ws });
+ const call = (fetchImpl as unknown as ReturnType<typeof vi.fn>).mock.calls[0];
+ expect(call?.[0]).toBe(`${BASE}/workspaces/a/star`);
+ expect(call?.[1]).toEqual({ method: "DELETE" });
+ });
+
+ it("star surfaces a 400 for an invalid slug", async () => {
+ const http = createWorkspaceHttp(
+ BASE,
+ fakeFetch([{ status: 400, body: { error: "invalid slug" } }]),
+ );
+ const result = await http.star("UPPER");
+ expect(result).toEqual({ ok: false, error: "invalid slug" });
+ });
+
+ it("unstar surfaces the backend error on failure", async () => {
+ const http = createWorkspaceHttp(
+ BASE,
+ fakeFetch([{ status: 500, body: { error: "Failed to unstar workspace" } }]),
+ );
+ const result = await http.unstar("a");
+ expect(result).toEqual({ ok: false, error: "Failed to unstar workspace" });
+ });
});