Repository: freeCodeCamp/freeCodeCamp
File: api/src/utils/env.test.ts (TypeScript)

Code before:
      await import('./env.js');
      expect(consoleWarnSpy).toHaveBeenCalledWith(
        expect.stringContaining('Warning: .env file not found')
      );
      consoleWarnSpy.mockRestore();
    });

    it('should NOT warn if .env is missing in production', async () => {
      const consoleWarnSpy = vi
        .spyOn(console, 'warn')
        .mockImplementation(() => {});

      vi.doMock('dotenv', () => ({
        config: vi.fn(() => ({ error: new Error('.env not found') }))
      }));

      setupMinimalProdEnv();

      await import('./env.js');
      expect(consoleWarnSpy).not.toHaveBeenCalled();
      consoleWarnSpy.mockRestore();
    });
  });

  describe('FCC_API_LOG_TRANSPORT Logic (MC/DC)', () => {
    it('CT1: should not throw error when FCC_API_LOG_TRANSPORT is "pretty"', async () => {
      vi.stubEnv('FCC_API_LOG_TRANSPORT', 'pretty');
      await expect(import('./env.js')).resolves.toBeDefined();
    });

    it('CT2: should not throw error when FCC_API_LOG_TRANSPORT is "default"', async () => {
      vi.stubEnv('FCC_API_LOG_TRANSPORT', 'default');
      await expect(import('./env.js')).resolves.toBeDefined();
    });

    it('CT3: should throw error when FCC_API_LOG_TRANSPORT is invalid', async () => {
      vi.stubEnv('FCC_API_LOG_TRANSPORT', 'invalid-value');
      await expect(import('./env.js')).rejects.toThrow(
        "FCC_API_LOG_TRANSPORT must be one of 'pretty' or 'default'. Found invalid-value"
      );
    });

    it('CT4: should assign "default" and pass validation when FCC_API_LOG_TRANSPORT is undefined', async () => {
      const envModule = await import('./env.js');
      expect(envModule.FCC_API_LOG_TRANSPORT).toBe('default');
    });
  });

  describe('Default Value Assignments', () => {
    it('should use the provided values from stubs', async () => {
      const envModule = await import('./env.js');

Review comment (suggestion):
```suggestion
    it('should not throw error when FCC_API_LOG_TRANSPORT is "pretty"', async () => {
```

Code after:
      await import('./env.js');
      expect(consoleWarnSpy).toHaveBeenCalledWith(
        expect.stringContaining('Warning: .env file not found')
      );
      consoleWarnSpy.mockRestore();
    });

    it('should NOT warn if .env is missing in production', async () => {
      const consoleWarnSpy = vi
        .spyOn(console, 'warn')
        .mockImplementation(() => {});

      vi.doMock('dotenv', () => ({
        config: vi.fn(() => ({ error: new Error('.env not found') }))
      }));

      setupMinimalProdEnv();

      await import('./env.js');
      expect(consoleWarnSpy).not.toHaveBeenCalled();
      consoleWarnSpy.mockRestore();
    });
  });

  describe('FCC_API_LOG_TRANSPORT Logic (MC/DC)', () => {
    it('should not throw error when FCC_API_LOG_TRANSPORT is "pretty"', async () => {
      vi.stubEnv('FCC_API_LOG_TRANSPORT', 'pretty');
      await expect(import('./env.js')).resolves.toBeDefined();
    });

    it('should not throw error when FCC_API_LOG_TRANSPORT is "default"', async () => {
      vi.stubEnv('FCC_API_LOG_TRANSPORT', 'default');
      await expect(import('./env.js')).resolves.toBeDefined();
    });

    it('should throw error when FCC_API_LOG_TRANSPORT is invalid', async () => {
      vi.stubEnv('FCC_API_LOG_TRANSPORT', 'invalid-value');
      await expect(import('./env.js')).rejects.toThrow(
        "FCC_API_LOG_TRANSPORT must be one of 'pretty' or 'default'. Found invalid-value"
      );
    });

    it('should assign "default" and pass validation when FCC_API_LOG_TRANSPORT is undefined', async () => {
      const envModule = await import('./env.js');
      expect(envModule.FCC_API_LOG_TRANSPORT).toBe('default');
    });
  });

  describe('Default Value Assignments', () => {
    it('should use the provided values from stubs', async () => {
      const envModule = await import('./env.js');