import { describe, it, expect, vi, beforeEach } from "vitest";
vi.mock("../../../services/autostart.js", () => ({
    enableAutostart: vi.fn(),
    disableAutostart: vi.fn(),
    autostartStatus: vi.fn(),
}));
import { enableAutostart, disableAutostart, autostartStatus } from "../../../services/autostart.js";
import { enableAutostartCommand, disableAutostartCommand, autostartStatusCommand, } from "../autostart.js";
const mockEnable = vi.mocked(enableAutostart);
const mockDisable = vi.mocked(disableAutostart);
const mockStatus = vi.mocked(autostartStatus);
describe("enable-autostart command", () => {
    beforeEach(() => {
        vi.clearAllMocks();
        process.exitCode = undefined;
    });
    it("should enable autostart and show result", async () => {
        mockEnable.mockResolvedValue("Created launchd plist at /path/to/plist");
        const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => { });
        await enableAutostartCommand();
        expect(mockEnable).toHaveBeenCalledOnce();
        expect(consoleSpy).toHaveBeenCalledWith("Created launchd plist at /path/to/plist");
        expect(process.exitCode).toBeUndefined();
        consoleSpy.mockRestore();
    });
    it("should handle enable failure", async () => {
        mockEnable.mockRejectedValue(new Error("Permission denied"));
        const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => { });
        await enableAutostartCommand();
        expect(consoleSpy).toHaveBeenCalledWith("Failed to enable autostart: Permission denied");
        expect(process.exitCode).toBe(1);
        consoleSpy.mockRestore();
    });
});
describe("disable-autostart command", () => {
    beforeEach(() => {
        vi.clearAllMocks();
        process.exitCode = undefined;
    });
    it("should disable autostart and show result", async () => {
        mockDisable.mockResolvedValue("Removed launchd plist at /path/to/plist");
        const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => { });
        await disableAutostartCommand();
        expect(mockDisable).toHaveBeenCalledOnce();
        expect(consoleSpy).toHaveBeenCalledWith("Removed launchd plist at /path/to/plist");
        expect(process.exitCode).toBeUndefined();
        consoleSpy.mockRestore();
    });
    it("should handle disable failure", async () => {
        mockDisable.mockRejectedValue(new Error("File system error"));
        const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => { });
        await disableAutostartCommand();
        expect(consoleSpy).toHaveBeenCalledWith("Failed to disable autostart: File system error");
        expect(process.exitCode).toBe(1);
        consoleSpy.mockRestore();
    });
    it("should report when autostart was not configured", async () => {
        mockDisable.mockResolvedValue("Autostart was not configured (no plist found)");
        const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => { });
        await disableAutostartCommand();
        expect(consoleSpy).toHaveBeenCalledWith("Autostart was not configured (no plist found)");
        consoleSpy.mockRestore();
    });
});
describe("autostart-status command", () => {
    beforeEach(() => {
        vi.clearAllMocks();
        process.exitCode = undefined;
    });
    it("should show autostart status when enabled", async () => {
        mockStatus.mockResolvedValue("Autostart is enabled (launchd plist at /path/to/plist)");
        const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => { });
        await autostartStatusCommand();
        expect(mockStatus).toHaveBeenCalledOnce();
        expect(consoleSpy).toHaveBeenCalledWith("Autostart is enabled (launchd plist at /path/to/plist)");
        expect(process.exitCode).toBeUndefined();
        consoleSpy.mockRestore();
    });
    it("should show autostart status when not configured", async () => {
        mockStatus.mockResolvedValue("Autostart is not configured");
        const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => { });
        await autostartStatusCommand();
        expect(consoleSpy).toHaveBeenCalledWith("Autostart is not configured");
        consoleSpy.mockRestore();
    });
    it("should handle status check failure", async () => {
        mockStatus.mockRejectedValue(new Error("Unexpected error"));
        const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => { });
        await autostartStatusCommand();
        expect(consoleSpy).toHaveBeenCalledWith("Failed to check autostart status: Unexpected error");
        expect(process.exitCode).toBe(1);
        consoleSpy.mockRestore();
    });
});
//# sourceMappingURL=cli-autostart.test.js.map