Initial commit for Greenlens
This commit is contained in:
29
__tests__/utils/backendUrl.test.ts
Normal file
29
__tests__/utils/backendUrl.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getConfiguredApiBaseUrl, getConfiguredAssetBaseUrl } from '../../utils/backendUrl';
|
||||
|
||||
describe('backendUrl utilities', () => {
|
||||
const originalApiUrl = process.env.EXPO_PUBLIC_API_URL;
|
||||
const originalBackendUrl = process.env.EXPO_PUBLIC_BACKEND_URL;
|
||||
const originalPaymentServerUrl = process.env.EXPO_PUBLIC_PAYMENT_SERVER_URL;
|
||||
|
||||
afterEach(() => {
|
||||
process.env.EXPO_PUBLIC_API_URL = originalApiUrl;
|
||||
process.env.EXPO_PUBLIC_BACKEND_URL = originalBackendUrl;
|
||||
process.env.EXPO_PUBLIC_PAYMENT_SERVER_URL = originalPaymentServerUrl;
|
||||
});
|
||||
|
||||
it('prefers EXPO_PUBLIC_API_URL when present', () => {
|
||||
process.env.EXPO_PUBLIC_API_URL = 'https://api.example.com/api';
|
||||
process.env.EXPO_PUBLIC_BACKEND_URL = 'https://backend.example.com';
|
||||
|
||||
expect(getConfiguredApiBaseUrl()).toBe('https://api.example.com/api');
|
||||
expect(getConfiguredAssetBaseUrl()).toBe('https://api.example.com');
|
||||
});
|
||||
|
||||
it('falls back to EXPO_PUBLIC_BACKEND_URL and appends /api', () => {
|
||||
delete process.env.EXPO_PUBLIC_API_URL;
|
||||
process.env.EXPO_PUBLIC_BACKEND_URL = 'https://backend.example.com';
|
||||
|
||||
expect(getConfiguredApiBaseUrl()).toBe('https://backend.example.com/api');
|
||||
expect(getConfiguredAssetBaseUrl()).toBe('https://backend.example.com');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user