109 lines
3.0 KiB
TypeScript
109 lines
3.0 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { TASK_FILE_EXTENSION } from "@/model/taskFile";
|
|
import { err } from "neverthrow";
|
|
import { InMemoryFileSystem } from "../../tests/helpers/InMemoryFileSystem";
|
|
import { appError, AppErrorVariant } from "@/error";
|
|
import { TaskPriority } from "@/model/taskPriority";
|
|
import { TaskStatus } from "@/model/taskStatus";
|
|
import { FsTaskRepository } from "@/storage/FsTaskRepository";
|
|
import { saveTaskDescription } from "./saveTaskDescription";
|
|
|
|
describe("saveTaskDescription", () => {
|
|
const folder = "/tasks";
|
|
let repo: FsTaskRepository;
|
|
|
|
beforeEach(() => {
|
|
repo = new FsTaskRepository(new InMemoryFileSystem(), TASK_FILE_EXTENSION);
|
|
});
|
|
|
|
it("updates description of an existing task", async () => {
|
|
const created = await repo.create(folder, {
|
|
title: "Editable",
|
|
description: "old body",
|
|
status: TaskStatus.OPEN,
|
|
priority: TaskPriority.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(TaskStatus.OPEN);
|
|
expect(result.value.priority).toBe(TaskPriority.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: TaskStatus.OPEN,
|
|
priority: TaskPriority.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)));
|
|
});
|
|
});
|