import { describe, expect, it, vi } from 'vitest';
import type { MosaicConfig } from '@mosaicstack/config';
import { QueueService } from './queue.service.js';

const localConfig = {
  queue: { type: 'local' },
} as MosaicConfig;

describe('QueueService local tier', () => {
  it('disables BullMQ and treats queue operations as local no-ops', async () => {
    const service = new QueueService(null, localConfig);

    expect(service.isEnabled()).toBe(false);
    expect(service.getQueue('mosaic-test')).toBeNull();
    expect(service.registerWorker('mosaic-test', vi.fn())).toBeNull();

    await expect(
      service.addRepeatableJob('mosaic-test', 'local-noop', {}, '* * * * *'),
    ).resolves.toBeUndefined();
    await expect(service.removeRepeatableJobs('mosaic-test', 'local-noop')).resolves.toBe(0);
    await expect(service.getHealthStatus()).resolves.toEqual({ queues: {}, healthy: true });
    await expect(service.listJobs()).resolves.toEqual([]);
    await expect(service.retryJob('mosaic-test__1')).resolves.toEqual({
      ok: false,
      message: 'BullMQ is disabled on local tier.',
    });
    await expect(service.pauseQueue('mosaic-test')).resolves.toEqual({
      ok: false,
      message: 'BullMQ is disabled on local tier.',
    });
    await expect(service.resumeQueue('mosaic-test')).resolves.toEqual({
      ok: false,
      message: 'BullMQ is disabled on local tier.',
    });
  });
});
