项目文件夹

文件
wehub-resource-sync c48612c494
CI / E2E Tests (push) Has been cancelled
CI / Lint, Typecheck & Unit Tests (push) Has been cancelled
Docs Build / Build docs site (push) Has been cancelled
Publish @openmaic packages / Build, validate & publish (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:23 +08:00

38 行
1.2 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { createProxiedFetch } from '@/lib/export/proxied-fetch';
describe('createProxiedFetch', () => {
beforeEach(() => vi.restoreAllMocks());
it('POSTs the original url to /api/proxy-media and returns the proxy response', async () => {
const spy = vi.fn(
async () =>
new Response('BYTES', { status: 200, headers: { 'content-type': 'text/javascript' } }),
);
vi.stubGlobal('fetch', spy);
const pfetch = createProxiedFetch();
const res = await pfetch('https://cdn.tailwindcss.com');
expect(spy).toHaveBeenCalledWith(
'/api/proxy-media',
expect.objectContaining({
method: 'POST',
body: JSON.stringify({ url: 'https://cdn.tailwindcss.com' }),
}),
);
expect(res.status).toBe(200);
expect(await res.text()).toBe('BYTES');
});
it('handles URL objects', async () => {
const spy = vi.fn(async () => new Response('', { status: 200 }));
vi.stubGlobal('fetch', spy);
await createProxiedFetch()(new URL('https://x/y.css'));
expect(spy).toHaveBeenCalledWith(
'/api/proxy-media',
expect.objectContaining({
body: JSON.stringify({ url: 'https://x/y.css' }),
}),
);
});
});