Files
shz-admin/tests/utils/publicUrl.test.ts

30 lines
1.1 KiB
TypeScript
Raw Normal View History

import { getDruidIndexUrl, getProductionApiBaseUrl, normalizePublicUrl } from '@/utils/publicUrl';
describe('public URL helpers', () => {
it('builds the production API base URL from the browser origin', () => {
expect(getProductionApiBaseUrl('http://39.98.44.136:6024')).toBe(
'http://39.98.44.136:6024/api/shihezi/',
);
});
it('builds the Druid index URL from the public API base URL', () => {
expect(getDruidIndexUrl('http://47.111.103.66')).toBe(
'http://47.111.103.66/api/shihezi/druid/index.html',
);
});
it('replaces an internal backend origin with the browser origin', () => {
expect(
normalizePublicUrl(
'http://127.0.0.1:9091/h5/outdoor-fair/company.html?fairId=8&companyId=93007',
'http://39.98.44.136:6024',
),
).toBe('http://39.98.44.136:6024/h5/outdoor-fair/company.html?fairId=8&companyId=93007');
});
it('keeps an already public URL unchanged', () => {
const url = 'https://jobs.example.com/h5/outdoor-fair/company.html?fairId=8&companyId=93007';
expect(normalizePublicUrl(url, 'http://39.98.44.136:6024')).toBe(url);
});
});