test(task): improve todo-sync tests with bun-types and inline assertions

🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim 2026-02-02 16:50:13 +09:00
parent 0ea92124a7
commit 76623454de

View File

@ -1,32 +1,4 @@
/// <reference path="../../types/bun-test.d.ts" /> /// <reference types="bun-types/test-globals" />
type TestBody = () => unknown | Promise<unknown>;
type TestDecl = (name: string, fn?: TestBody) => void;
type Hook = (fn: TestBody) => void;
type Expectation = {
toBe: (...args: unknown[]) => unknown;
toBeNull: (...args: unknown[]) => unknown;
toEqual: (...args: unknown[]) => unknown;
toHaveProperty: (...args: unknown[]) => unknown;
toMatch: (...args: unknown[]) => unknown;
toBeDefined: (...args: unknown[]) => unknown;
toContain: (...args: unknown[]) => unknown;
toBeUndefined: (...args: unknown[]) => unknown;
toHaveBeenCalled: (...args: unknown[]) => unknown;
toHaveBeenCalledTimes: (...args: unknown[]) => unknown;
toHaveBeenCalledWith: (...args: unknown[]) => unknown;
not: Expectation;
};
type Expect = (value?: unknown) => Expectation;
declare const describe: TestDecl;
declare const it: TestDecl;
declare const test: TestDecl;
declare const expect: Expect;
declare const beforeEach: Hook;
declare const afterEach: Hook;
declare const beforeAll: Hook;
declare const afterAll: Hook;
declare const vi: { fn: (...args: unknown[]) => unknown };
import type { Task } from "../../features/claude-tasks/types"; import type { Task } from "../../features/claude-tasks/types";
import { import {
syncTaskToTodo, syncTaskToTodo,
@ -255,30 +227,24 @@ describe("syncTaskTodoUpdate", () => {
{ id: "T-2", content: "Keep task", status: "pending" }, { id: "T-2", content: "Keep task", status: "pending" },
]; ];
mockCtx.client.session.todo.mockResolvedValue({ data: currentTodos }); mockCtx.client.session.todo.mockResolvedValue({ data: currentTodos });
const payload: { sessionID: string; todos: TodoInfo[] } = { let called = false;
sessionID: "",
todos: [],
};
let calls = 0;
const writer = async (input: { sessionID: string; todos: TodoInfo[] }) => { const writer = async (input: { sessionID: string; todos: TodoInfo[] }) => {
calls += 1; called = true;
payload.sessionID = input.sessionID; expect(input.sessionID).toBe("session-1");
payload.todos = input.todos; expect(input.todos.length).toBe(2);
expect(
input.todos.find((todo: TodoInfo) => todo.id === "T-1")?.content,
).toBe("Updated task");
expect(input.todos.some((todo: TodoInfo) => todo.id === "T-2")).toBe(
true,
);
}; };
// when // when
await syncTaskTodoUpdate(mockCtx, task, "session-1", writer); await syncTaskTodoUpdate(mockCtx, task, "session-1", writer);
// then // then
expect(calls).toBe(1); expect(called).toBe(true);
expect(payload.sessionID).toBe("session-1");
expect(payload.todos.length).toBe(2);
expect(
payload.todos.find((todo: TodoInfo) => todo.id === "T-1")?.content,
).toBe("Updated task");
expect(payload.todos.some((todo: TodoInfo) => todo.id === "T-2")).toBe(
true,
);
}); });
it("removes deleted task from todos", async () => { it("removes deleted task from todos", async () => {
@ -296,29 +262,23 @@ describe("syncTaskTodoUpdate", () => {
{ id: "T-2", content: "Keep task", status: "pending" }, { id: "T-2", content: "Keep task", status: "pending" },
]; ];
mockCtx.client.session.todo.mockResolvedValue(currentTodos); mockCtx.client.session.todo.mockResolvedValue(currentTodos);
const payload: { sessionID: string; todos: TodoInfo[] } = { let called = false;
sessionID: "",
todos: [],
};
let calls = 0;
const writer = async (input: { sessionID: string; todos: TodoInfo[] }) => { const writer = async (input: { sessionID: string; todos: TodoInfo[] }) => {
calls += 1; called = true;
payload.sessionID = input.sessionID; expect(input.todos.length).toBe(1);
payload.todos = input.todos; expect(input.todos.some((todo: TodoInfo) => todo.id === "T-1")).toBe(
false,
);
expect(input.todos.some((todo: TodoInfo) => todo.id === "T-2")).toBe(
true,
);
}; };
// when // when
await syncTaskTodoUpdate(mockCtx, task, "session-1", writer); await syncTaskTodoUpdate(mockCtx, task, "session-1", writer);
// then // then
expect(calls).toBe(1); expect(called).toBe(true);
expect(payload.todos.length).toBe(1);
expect(payload.todos.some((todo: TodoInfo) => todo.id === "T-1")).toBe(
false,
);
expect(payload.todos.some((todo: TodoInfo) => todo.id === "T-2")).toBe(
true,
);
}); });
}); });