import { describe, expect, it, vi } from "vitest"; import { TransitionTransaction } from "@/scene/TransitionTransaction"; describe("TransitionTransaction", () => { it("rolls back when prepare fails and never commits", async () => { const prepareError = new Error("prepare failed"); const prepare = vi.fn(async () => { throw prepareError; }); const commit = vi.fn(async () => {}); const rollback = vi.fn(async () => {}); const transaction = new TransitionTransaction({ prepare, commit, rollback, }); await expect(transaction.execute()).rejects.toThrowError("prepare failed"); expect(prepare).toHaveBeenCalledTimes(1); expect(rollback).toHaveBeenCalledTimes(1); expect(commit).not.toHaveBeenCalled(); }); it("rolls back when commit fails", async () => { const commitError = new Error("commit failed"); const prepare = vi.fn(async () => {}); const commit = vi.fn(async () => { throw commitError; }); const rollback = vi.fn(async () => {}); const transaction = new TransitionTransaction({ prepare, commit, rollback, }); await expect(transaction.execute()).rejects.toThrowError("commit failed"); expect(prepare).toHaveBeenCalledTimes(1); expect(commit).toHaveBeenCalledTimes(1); expect(rollback).toHaveBeenCalledTimes(1); }); });