summaryrefslogtreecommitdiffhomepage
path: root/src/features/workspaces/store.test.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-10-19 13:38:57 +0900
committerAdam Malczewski <[email protected]>2026-10-19 13:38:57 +0900
commitc4397f633415a46852f0e3b49c78ab7b2d87d4c1 (patch)
tree047a5687565059422cbb38aeda8988502a66b78d /src/features/workspaces/store.test.ts
parentf6d96289470ac888670050ff64c54bbe69b973cb (diff)
downloaddispatch-web-c4397f633415a46852f0e3b49c78ab7b2d87d4c1.tar.gz
dispatch-web-c4397f633415a46852f0e3b49c78ab7b2d87d4c1.zip
feat(workspaces): block creating a workspace whose slug is archived
Diffstat (limited to 'src/features/workspaces/store.test.ts')
-rw-r--r--src/features/workspaces/store.test.ts61
1 files changed, 59 insertions, 2 deletions
diff --git a/src/features/workspaces/store.test.ts b/src/features/workspaces/store.test.ts
index a44d8a6..faec5bf 100644
--- a/src/features/workspaces/store.test.ts
+++ b/src/features/workspaces/store.test.ts
@@ -1,6 +1,7 @@
import type { Workspace, WorkspaceEntry } from "@dispatch/wire";
import { describe, expect, it, vi } from "vitest";
import type { WorkspaceResult } from "./adapter/http";
+import { archivedCreateMessage, type WorkspaceLookup } from "./logic/create";
import { createWorkspaceStore } from "./store.svelte";
function entry(overrides: Partial<WorkspaceEntry> = {}): WorkspaceEntry {
@@ -25,14 +26,23 @@ function fakeHttp(opts: {
unstar?: (id: string) => Promise<WorkspaceResult<Workspace>>;
archive?: (id: string) => Promise<WorkspaceResult<Workspace>>;
unarchive?: (id: string) => Promise<WorkspaceResult<Workspace>>;
+ get?: (id: string) => Promise<WorkspaceLookup>;
+ ensure?: (id: string) => Promise<WorkspaceResult<Workspace>>;
}) {
return {
list: vi.fn(
async (_archived?: "true" | "false" | "all"): Promise<readonly WorkspaceEntry[]> =>
opts.list ?? [],
),
- ensure: vi.fn(),
- get: vi.fn(),
+ ensure:
+ opts.ensure ??
+ vi.fn(
+ async (id: string): Promise<WorkspaceResult<Workspace>> => ({
+ ok: true,
+ value: entry({ id }),
+ }),
+ ),
+ get: vi.fn(opts.get ?? (async (): Promise<WorkspaceLookup> => ({ kind: "missing" }))),
setTitle: vi.fn(),
setDefaultCwd: vi.fn(),
setDefaultComputer: vi.fn(),
@@ -224,6 +234,53 @@ describe("createWorkspaceStore — setArchived", () => {
});
});
+describe("createWorkspaceStore — create (archived-slug gate)", () => {
+ it("refuses an archived slug with the can't-create message and never calls ensure", async () => {
+ const http = fakeHttp({
+ get: async () => ({ kind: "found", workspace: entry({ id: "old", archived: true }) }),
+ });
+ const store = createWorkspaceStore(http);
+
+ const result = await store.create("old");
+
+ expect(result).toEqual({ ok: false, error: archivedCreateMessage("old") });
+ expect(http.ensure).not.toHaveBeenCalled();
+ });
+
+ it("proceeds for an existing non-archived slug (ensure is called as before)", async () => {
+ const http = fakeHttp({
+ get: async () => ({ kind: "found", workspace: entry({ id: "taken", archived: false }) }),
+ });
+ const store = createWorkspaceStore(http);
+
+ const result = await store.create("taken");
+
+ expect(result.ok).toBe(true);
+ expect(http.ensure).toHaveBeenCalledTimes(1);
+ });
+
+ it("proceeds for a brand-new slug (404 → missing)", async () => {
+ const http = fakeHttp({ get: async () => ({ kind: "missing" }) });
+ const store = createWorkspaceStore(http);
+
+ const result = await store.create("fresh");
+
+ expect(result.ok).toBe(true);
+ expect(http.ensure).toHaveBeenCalledTimes(1);
+ });
+
+ it("refuses when the existence check itself failed, without calling ensure (§3.4)", async () => {
+ const http = fakeHttp({ get: async () => ({ kind: "failed", error: "db down" }) });
+ const store = createWorkspaceStore(http);
+
+ const result = await store.create("maybe");
+
+ expect(result.ok).toBe(false);
+ if (!result.ok) expect(result.error).toContain("Couldn't check whether");
+ expect(http.ensure).not.toHaveBeenCalled();
+ });
+});
+
describe("createWorkspaceStore — refreshArchived", () => {
it("loads the archived list via list('true') without touching the main list", async () => {
const http = fakeHttp({ list: [entry({ id: "active", archived: false })] });