import { normalizeNewsContent, normalizeNewsImageUrl } from '@/utils/newsImageUrl'; describe('news image URL normalization', () => { const origin = 'http://47.111.103.66'; it('maps the backend internal host to the public API resource path', () => { expect( normalizeNewsImageUrl( 'http://127.0.0.1:9091/profile/upload/2026/07/20/news.png', undefined, origin, ), ).toBe('http://47.111.103.66/api/shihezi/profile/upload/2026/07/20/news.png'); }); it('supports the fileName returned by the upload endpoint', () => { expect(normalizeNewsImageUrl(undefined, 'profile/upload/2026/07/20/news.png', origin)).toBe( 'http://47.111.103.66/api/shihezi/profile/upload/2026/07/20/news.png', ); }); it('normalizes existing API-prefixed URLs to an absolute browser URL', () => { expect(normalizeNewsImageUrl('/api/shihezi/profile/upload/news.png', undefined, origin)).toBe( 'http://47.111.103.66/api/shihezi/profile/upload/news.png', ); }); it('uses the development proxy prefix in development builds', () => { const originalNodeEnv = process.env.NODE_ENV; process.env.NODE_ENV = 'development'; try { expect( normalizeNewsImageUrl('/profile/upload/news.png', undefined, 'http://localhost:8000'), ).toBe('http://localhost:8000/api/profile/upload/news.png'); } finally { process.env.NODE_ENV = originalNodeEnv; } }); it('rewrites only image sources in existing rich text', () => { expect( normalizeNewsContent( '
正文

',
origin,
),
).toBe(
'正文

',
);
});
});