import {
  describe,
  it,
  expect
} from 'vitest';
import { isPerfDiagEnabled } from './diagnostics.flags';

describe('isPerfDiagEnabled', () => {
  it('returns false when the flag is unset', () => {
    expect(isPerfDiagEnabled({}, false)).toBe(false);
    expect(isPerfDiagEnabled({}, true)).toBe(false);
  });

  it('returns true in development when METOYOU_PERF_DIAG is truthy', () => {
    expect(isPerfDiagEnabled({ METOYOU_PERF_DIAG: '1' }, false)).toBe(true);
    expect(isPerfDiagEnabled({ METOYOU_PERF_DIAG: 'true' }, false)).toBe(true);
    expect(isPerfDiagEnabled({ METOYOU_PERF_DIAG: 'on' }, false)).toBe(true);
  });

  it('returns false in packaged builds unless force is set', () => {
    expect(isPerfDiagEnabled({ METOYOU_PERF_DIAG: '1' }, true)).toBe(false);
    expect(isPerfDiagEnabled({
      METOYOU_PERF_DIAG: '1',
      METOYOU_PERF_DIAG_FORCE: '1'
    }, true)).toBe(true);
  });
});
