|
| 1 | +/** |
| 2 | + * Utils Unit Tests |
| 3 | + * Tests for URL utilities |
| 4 | + */ |
| 5 | + |
| 6 | +import { describe, expect, it } from 'vitest' |
| 7 | +import { toProxyUrl } from '../url' |
| 8 | + |
| 9 | +describe('toProxyUrl', () => { |
| 10 | + it('should return original url when origin is empty', () => { |
| 11 | + expect(toProxyUrl('', 'https://example.com/image.png')).toBe('https://example.com/image.png') |
| 12 | + }) |
| 13 | + |
| 14 | + it('should proxy HuggingFace gradio file URLs', () => { |
| 15 | + const origin = 'https://example.com' |
| 16 | + const url = 'https://abc123.hf.space/gradio_api/file=image.png' |
| 17 | + expect(toProxyUrl(origin, url)).toBe( |
| 18 | + 'https://example.com/api/proxy-image?url=https%3A%2F%2Fabc123.hf.space%2Fgradio_api%2Ffile%3Dimage.png' |
| 19 | + ) |
| 20 | + }) |
| 21 | + |
| 22 | + it('should proxy via string fallback for non-URL inputs', () => { |
| 23 | + const origin = 'https://example.com' |
| 24 | + const url = 'abc123.hf.space/gradio_api/file=image.png' |
| 25 | + expect(toProxyUrl(origin, url)).toBe( |
| 26 | + 'https://example.com/api/proxy-image?url=abc123.hf.space%2Fgradio_api%2Ffile%3Dimage.png' |
| 27 | + ) |
| 28 | + }) |
| 29 | + |
| 30 | + it('should not proxy unrelated URLs', () => { |
| 31 | + expect(toProxyUrl('https://example.com', 'https://abc123.hf.space/file=image.png')).toBe( |
| 32 | + 'https://abc123.hf.space/file=image.png' |
| 33 | + ) |
| 34 | + expect(toProxyUrl('https://example.com', 'https://example.com/image.png')).toBe( |
| 35 | + 'https://example.com/image.png' |
| 36 | + ) |
| 37 | + }) |
| 38 | +}) |
0 commit comments