import { Test } from '@nestjs/testing';
import { HealthController } from './health.controller';
import { ReadinessService } from './readiness.service';

describe('HealthController', () => {
  it('returns liveness without dependency checks', async () => {
    const readiness = { check: jest.fn() };
    const moduleRef = await Test.createTestingModule({
      controllers: [HealthController],
      providers: [{ provide: ReadinessService, useValue: readiness }],
    }).compile();

    expect(moduleRef.get(HealthController).live()).toEqual({ status: 'ok' });
    expect(readiness.check).not.toHaveBeenCalled();
  });

  it('delegates readiness to dependency checks', async () => {
    const readiness = { check: jest.fn().mockResolvedValue({ status: 'ok' }) };
    const moduleRef = await Test.createTestingModule({
      controllers: [HealthController],
      providers: [{ provide: ReadinessService, useValue: readiness }],
    }).compile();

    await expect(moduleRef.get(HealthController).ready()).resolves.toEqual({
      status: 'ok',
    });
    expect(readiness.check).toHaveBeenCalledTimes(1);
  });
});
