Files
xboct-flow/src/commands/listLocatedTasks.test.ts
T

75 lines
2.1 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 { FsTaskRepository } from "@/storage/FsTaskRepository";
import { listLocatedTasks } from "./listLocatedTasks";
describe("listLocatedTasks", () => {
const project = "/project/tasks";
const global = "/global/tasks";
let repo: FsTaskRepository;
beforeEach(() => {
repo = new FsTaskRepository(new InMemoryFileSystem(), TASK_FILE_EXTENSION);
});
it("merges tasks from project and global with location", async () => {
const p = await repo.create(project, {
title: "Project task",
description: "",
status: "todo",
priority: "medium",
tags: [],
assignee: "",
});
const g = await repo.create(global, {
title: "Global task",
description: "",
status: "todo",
priority: "high",
tags: [],
assignee: "",
});
const result = await listLocatedTasks(repo, [
{ scope: "project", folderPath: project },
{ scope: "global", folderPath: global },
]);
expect(result.isOk()).toBe(true);
if (result.isErr()) return;
expect(result.value).toHaveLength(2);
const byId = Object.fromEntries(
result.value.map((item) => [item.task.id, item]),
);
expect(byId[p.id].task.title).toBe("Project task");
expect(byId[p.id].location).toEqual({
scope: "project",
folderPath: project,
});
expect(byId[g.id].task.title).toBe("Global task");
expect(byId[g.id].location).toEqual({
scope: "global",
folderPath: global,
});
});
it("returns empty array when folders have no tasks", async () => {
const result = await listLocatedTasks(repo, [
{ scope: "project", folderPath: project },
]);
expect(result.isOk()).toBe(true);
if (result.isErr()) return;
expect(result.value).toEqual([]);
});
it("rejects empty locations", async () => {
const result = await listLocatedTasks(repo, []);
expect(result).toEqual(err(appError(AppErrorVariant.NO_FOLDER)));
});
});