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

Code before:
        .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');
      expect(envModule.EMAIL_PROVIDER).toBe('nodemailer');
      expect(envModule.FREECODECAMP_NODE_ENV).toBe('development');
      expect(envModule.FCC_API_LOG_LEVEL).toBe('info');
      expect(envModule.DEPLOYMENT_VERSION).toBe('unknown');
    });

    it('should use default values for EMAIL_PROVIDER and LOG_LEVEL in development', async () => {
      vi.stubEnv('EMAIL_PROVIDER', undefined);
      vi.stubEnv('FCC_API_LOG_LEVEL', undefined);


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

Code after:
        .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');
      expect(envModule.EMAIL_PROVIDER).toBe('nodemailer');
      expect(envModule.FREECODECAMP_NODE_ENV).toBe('development');
      expect(envModule.FCC_API_LOG_LEVEL).toBe('info');
      expect(envModule.DEPLOYMENT_VERSION).toBe('unknown');
    });

    it('should use default values for EMAIL_PROVIDER and LOG_LEVEL in development', async () => {
      vi.stubEnv('EMAIL_PROVIDER', undefined);
      vi.stubEnv('FCC_API_LOG_LEVEL', undefined);