// Task 168 — per-tool emit assertion for profile-delete.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { setupEmitCapture, makeMockSession } from "./_helpers/emit-capture.js";
const mockSession = makeMockSession();
vi.mock("../../lib/neo4j.js", () => ({
    getSession: () => mockSession,
}));
vi.mock("../../../../../../lib/graph-trash/dist/index.js", () => ({
    trashNode: vi.fn(),
}));
import { profileDelete } from "../profile-delete.js";
import { trashNode } from "../../../../../../lib/graph-trash/dist/index.js";
describe("profile-delete — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        vi.mocked(trashNode).mockReset();
        mockSession.run.mockReset();
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path", async () => {
        mockSession.run.mockResolvedValue({
            records: [{ get: (k) => (k === "eid" ? "4:pref:1" : undefined) }],
        });
        vi.mocked(trashNode).mockResolvedValue({
            trashed: true,
            alreadyTrashed: false,
            nodeId: "4:pref:1",
            labels: ["Preference"],
            trashedAt: "2026-05-19T00:00:00Z",
            originalKeys: {},
        });
        await profileDelete({
            accountId: "acct-1",
            userId: "user-1",
            category: "communication",
            key: "tone",
        });
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.tag).toBe("mcp:memory");
        expect(body.level).toBe("info");
        expect(body.line).toContain("profile-delete");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line when session.run throws", async () => {
        mockSession.run.mockRejectedValue(new Error("driver disconnected"));
        await expect(profileDelete({
            accountId: "acct-1",
            userId: "user-1",
            category: "communication",
            key: "tone",
        })).rejects.toThrow(/driver disconnected/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("profile-delete");
        expect(body.line).toContain("result=error");
        expect(body.line).toContain("reason=neo4j-driver-error");
    });
});
//# sourceMappingURL=profile-delete-emit.test.js.map