import { describe, expect, it, vi, beforeEach } from "vitest";
vi.mock("../../../utils/logger.js", () => ({
    logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
}));
const { sendProjectAdded, sendProjectRemoved } = await import("../project-sync.js");
function createMockClient(connected = true) {
    return {
        send: vi.fn(),
        connected,
    };
}
describe("project-sync", () => {
    beforeEach(() => {
        vi.clearAllMocks();
    });
    describe("sendProjectAdded", () => {
        it("should send project_added message with correct payload", () => {
            const client = createMockClient();
            const project = {
                projectId: "proj-123",
                name: "my-app",
                path: "/home/user/my-app",
            };
            const result = sendProjectAdded(client, project);
            expect(result).toBe(true);
            expect(client.send).toHaveBeenCalledOnce();
            const sent = vi.mocked(client.send).mock.calls[0][0];
            expect(sent.type).toBe("project_added");
            expect(sent.payload.projectId).toBe("proj-123");
            expect(sent.payload.name).toBe("my-app");
            expect(sent.payload.path).toBe("/home/user/my-app");
        });
        it("should return false when not connected", () => {
            const client = createMockClient(false);
            const project = {
                projectId: "proj-123",
                name: "my-app",
                path: "/home/user/my-app",
            };
            const result = sendProjectAdded(client, project);
            expect(result).toBe(false);
            expect(client.send).not.toHaveBeenCalled();
        });
        it("should include all required fields in payload", () => {
            const client = createMockClient();
            const project = {
                projectId: "550e8400-e29b-41d4-a716-446655440000",
                name: "api-server",
                path: "/Users/dev/projects/api-server",
            };
            sendProjectAdded(client, project);
            const sent = vi.mocked(client.send).mock.calls[0][0];
            expect(sent).toEqual({
                type: "project_added",
                payload: {
                    projectId: "550e8400-e29b-41d4-a716-446655440000",
                    name: "api-server",
                    path: "/Users/dev/projects/api-server",
                },
            });
        });
    });
    describe("sendProjectRemoved", () => {
        it("should send project_removed message with projectId", () => {
            const client = createMockClient();
            const result = sendProjectRemoved(client, "proj-456");
            expect(result).toBe(true);
            expect(client.send).toHaveBeenCalledOnce();
            const sent = vi.mocked(client.send).mock.calls[0][0];
            expect(sent.type).toBe("project_removed");
            expect(sent.payload.projectId).toBe("proj-456");
        });
        it("should return false when not connected", () => {
            const client = createMockClient(false);
            const result = sendProjectRemoved(client, "proj-456");
            expect(result).toBe(false);
            expect(client.send).not.toHaveBeenCalled();
        });
        it("should include only projectId in payload", () => {
            const client = createMockClient();
            sendProjectRemoved(client, "proj-789");
            const sent = vi.mocked(client.send).mock.calls[0][0];
            expect(sent).toEqual({
                type: "project_removed",
                payload: {
                    projectId: "proj-789",
                },
            });
        });
    });
});
//# sourceMappingURL=project-sync.test.js.map