import { HealthService } from './health.service';

describe('HealthService', () => {
  const originalEnv = process.env;

  beforeEach(() => {
    process.env = { ...originalEnv };
  });

  afterAll(() => {
    process.env = originalEnv;
  });

  it('returns deploy version metadata from environment variables', () => {
    process.env.APP_VERSION = 'commit-123';
    process.env.APP_BUILD_TIME = '2026-07-06T13:00:00.000Z';
    process.env.APP_IMAGE_TAG = 'ghcr.io/acme/ftb/server:commit-123';

    const result = new HealthService().getVersion();

    expect(result).toEqual({
      service: 'server',
      version: 'commit-123',
      buildTime: '2026-07-06T13:00:00.000Z',
      imageTag: 'ghcr.io/acme/ftb/server:commit-123',
    });
  });

  it('uses stable fallback values when deploy metadata is not configured', () => {
    delete process.env.APP_VERSION;
    delete process.env.APP_BUILD_TIME;
    delete process.env.APP_IMAGE_TAG;

    const result = new HealthService().getVersion();

    expect(result).toEqual({
      service: 'server',
      version: 'unknown',
      buildTime: '',
      imageTag: '',
    });
  });
});
