feat: add dashboard and commands
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { err } from "neverthrow";
|
||||
import { InMemoryFileSystem } from "../../tests/helpers/InMemoryFileSystem";
|
||||
import { appError, AppErrorVariant } from "@/error";
|
||||
import { FsTaskRepository } from "@/storage/FsTaskRepository";
|
||||
import { saveTaskDescription } from "./saveTaskDescription";
|
||||
|
||||
describe("saveTaskDescription", () => {
|
||||
const folder = "/tasks";
|
||||
let repo: FsTaskRepository;
|
||||
|
||||
beforeEach(() => {
|
||||
repo = new FsTaskRepository(new InMemoryFileSystem(), ".task.md");
|
||||
});
|
||||
|
||||
it("updates description of an existing task", async () => {
|
||||
const created = await repo.create(folder, {
|
||||
title: "Editable",
|
||||
description: "old body",
|
||||
status: "todo",
|
||||
priority: "high",
|
||||
tags: ["keep"],
|
||||
assignee: "alice",
|
||||
});
|
||||
|
||||
const result = await saveTaskDescription(repo, {
|
||||
folderPath: folder,
|
||||
id: created.id,
|
||||
description: "new markdown body",
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
if (result.isErr()) return;
|
||||
|
||||
expect(result.value.id).toBe(created.id);
|
||||
expect(result.value.description).toBe("new markdown body");
|
||||
expect(result.value.title).toBe("Editable");
|
||||
expect(result.value.status).toBe("todo");
|
||||
expect(result.value.priority).toBe("high");
|
||||
expect(result.value.tags).toEqual(["keep"]);
|
||||
expect(result.value.assignee).toBe("alice");
|
||||
|
||||
const stored = await repo.getById(folder, created.id);
|
||||
expect(stored?.description).toBe("new markdown body");
|
||||
});
|
||||
|
||||
it("allows empty description", async () => {
|
||||
const created = await repo.create(folder, {
|
||||
title: "Clear me",
|
||||
description: "something",
|
||||
status: "todo",
|
||||
priority: "medium",
|
||||
tags: [],
|
||||
assignee: "",
|
||||
});
|
||||
|
||||
const result = await saveTaskDescription(repo, {
|
||||
folderPath: folder,
|
||||
id: created.id,
|
||||
description: "",
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
if (result.isErr()) return;
|
||||
expect(result.value.description).toBe("");
|
||||
});
|
||||
|
||||
it("returns not-found for unknown id", async () => {
|
||||
const result = await saveTaskDescription(repo, {
|
||||
folderPath: folder,
|
||||
id: "missing",
|
||||
description: "x",
|
||||
});
|
||||
expect(result).toEqual(
|
||||
err(appError(AppErrorVariant.NOT_FOUND, { id: "missing" })),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects missing folder", async () => {
|
||||
const result = await saveTaskDescription(repo, {
|
||||
folderPath: undefined,
|
||||
id: "x",
|
||||
description: "x",
|
||||
});
|
||||
expect(result).toEqual(err(appError(AppErrorVariant.NO_FOLDER)));
|
||||
});
|
||||
|
||||
it("rejects missing id", async () => {
|
||||
const result = await saveTaskDescription(repo, {
|
||||
folderPath: folder,
|
||||
id: undefined,
|
||||
description: "x",
|
||||
});
|
||||
expect(result).toEqual(err(appError(AppErrorVariant.NO_ID)));
|
||||
});
|
||||
|
||||
it("rejects missing description", async () => {
|
||||
const result = await saveTaskDescription(repo, {
|
||||
folderPath: folder,
|
||||
id: "x",
|
||||
description: undefined,
|
||||
});
|
||||
expect(result).toEqual(err(appError(AppErrorVariant.NO_DESCRIPTION)));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user