import { appVariant, config, requirePublicEnv, shouldShowAboutBackendUrl, type AppVariant, } from '@/core/config'; describe('requirePublicEnv', () => { it('throws when variable is missing or blank', () => { const key = 'EXPO_PUBLIC_API_URL'; const previous = process.env[key]; try { delete process.env[key]; expect(() => requirePublicEnv(key)).toThrow(/Missing EXPO_PUBLIC_API_URL/); process.env[key] = ' '; expect(() => requirePublicEnv(key)).toThrow(/Missing EXPO_PUBLIC_API_URL/); } finally { if (previous === undefined) { process.env[key] = 'http://127.0.0.1:8000'; } else { process.env[key] = previous; } } }); }); describe('config backend URLs', () => { it('loads API and WS from EXPO_PUBLIC_* (jest.setup defaults)', () => { expect(config.apiBaseUrl).toBe('http://127.0.0.1:8000'); expect(config.wsBaseUrl).toBe('ws://127.0.0.1:8000'); }); }); describe('shouldShowAboutBackendUrl', () => { it('shows backend URL for development and staging', () => { expect(shouldShowAboutBackendUrl('development')).toBe(true); expect(shouldShowAboutBackendUrl('staging')).toBe(true); }); it('hides backend URL for production when not in __DEV__', () => { if (__DEV__) { expect(shouldShowAboutBackendUrl('production')).toBe(true); } else { expect(shouldShowAboutBackendUrl('production')).toBe(false); } }); it('matches config.showAboutBackendUrl for current build', () => { expect(config.showAboutBackendUrl).toBe( shouldShowAboutBackendUrl(appVariant as AppVariant), ); }); });