import { describe, expect, it } from 'vitest';
import { ImageProxyClient } from '@apify/image_proxy_client';
const IMAGE_PROXY_KEY = '2345DFGHCVBNGHJ';
const IMAGE_PROXY_DOMAIN = 'localhost:3000';
const imageProxyClient = new ImageProxyClient({
hmacKey: IMAGE_PROXY_KEY,
domain: IMAGE_PROXY_DOMAIN,
});
const TEST_IMAGE_URL = 'http://example.com/image.gif';
const TEST_IMAGE_URL_2 = 'HTTP://example.com/image.gif';
const EXPECTED_IMAGE_URL =
'https://localhost:3000/14110f5a2b817884066da289ce004803b35cfefc/' +
'687474703a2f2f6578616d706c652e636f6d2f696d6167652e676966';
const EXPECTED_IMAGE_URL_2 =
'https://localhost:3000/3bb9136ff6f149fce6770d65291f29554b372e11/' +
'485454503a2f2f6578616d706c652e636f6d2f696d6167652e676966';
const getComplicatedHtml = (imageUrl: string) => {
return (
`
` +
`` +
`
` +
`
` +
`
` +
`
` +
'
'
);
};
describe('proxy image client', () => {
it('generateUrlWithParam() works', async () => {
const testImageUrl = 'http://example.com/image.gif';
const proxyUrl = await imageProxyClient.generateUrlWithParam(testImageUrl);
expect(
'https://localhost:3000/14110f5a2b817884066da289ce004803b35cfefc/?url=http%3A%2F%2Fexample.com%2Fimage.gif',
).toBe(proxyUrl);
});
it('generateUrl() works', async () => {
const proxyUrl = await imageProxyClient.generateUrl(TEST_IMAGE_URL);
expect(EXPECTED_IMAGE_URL).toBe(proxyUrl);
});
it('updateImagesInHtml() works', async () => {
const html = (imageUrl: string) => {
return (
'