/// <reference types="jest" />
import { ConfigService } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { WorkflowEventOutboxController } from './workflowEventOutbox.controller';
import { WorkflowEventOutboxService } from './workflowEventOutbox.service';

// Mock WorkflowEventOutboxService：用空对象屏蔽真实 Service 的依赖（PrismaService 等），
// 避免 NestJS 在测试模块编译时去解析 Service 的构造参数。
const mockWorkflowEventOutboxService = {};

// Mock ConfigService
const mockConfigService = {
  get: jest.fn(),
};

// Mock Logger
const mockLogger = {
  child: jest.fn().mockReturnThis(),
  info: jest.fn(),
  error: jest.fn(),
  warn: jest.fn(),
  debug: jest.fn(),
};

describe('WorkflowEventOutboxController', () => {
  let controller: WorkflowEventOutboxController;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [WorkflowEventOutboxController],
      providers: [
        {
          provide: WorkflowEventOutboxService,
          useValue: mockWorkflowEventOutboxService,
        },
        { provide: ConfigService, useValue: mockConfigService },
        { provide: WINSTON_MODULE_PROVIDER, useValue: mockLogger },
      ],
    })
      // 兜底：自动 mock 任何未显式提供的依赖
      // （例如 ACGuard 内部的 __roles_builder__ token）
      .useMocker(() => ({}))
      .compile();

    controller = module.get<WorkflowEventOutboxController>(
      WorkflowEventOutboxController,
    );
  });

  it('should be defined', () => {
    expect(controller).toBeDefined();
  });
});
