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

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

// 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('PageController', () => {
  let controller: PageController;

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

    controller = module.get<PageController>(PageController);
  });

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