import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { QueueController } from "./queue.controller";
import { QueueService } from "../../queue/queue.service";

describe("QueueController", () => {
  let controller: QueueController;
  let queueService: {
    getStats: ReturnType<typeof vi.fn>;
    pause: ReturnType<typeof vi.fn>;
    resume: ReturnType<typeof vi.fn>;
  };

  beforeEach(() => {
    queueService = {
      getStats: vi.fn(),
      pause: vi.fn(),
      resume: vi.fn(),
    };

    controller = new QueueController(queueService as unknown as QueueService);
  });

  afterEach(() => {
    vi.clearAllMocks();
  });

  it("should return queue stats", async () => {
    queueService.getStats.mockResolvedValue({
      pending: 5,
      active: 1,
      completed: 10,
      failed: 2,
      delayed: 0,
    });

    const result = await controller.getStats();

    expect(queueService.getStats).toHaveBeenCalledOnce();
    expect(result).toEqual({
      pending: 5,
      active: 1,
      completed: 10,
      failed: 2,
      delayed: 0,
    });
  });

  it("should pause queue processing", async () => {
    queueService.pause.mockResolvedValue(undefined);

    const result = await controller.pause();

    expect(queueService.pause).toHaveBeenCalledOnce();
    expect(result).toEqual({ message: "Queue processing paused" });
  });

  it("should resume queue processing", async () => {
    queueService.resume.mockResolvedValue(undefined);

    const result = await controller.resume();

    expect(queueService.resume).toHaveBeenCalledOnce();
    expect(result).toEqual({ message: "Queue processing resumed" });
  });
});
