45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
import { describe, it, expect, beforeAll, afterAll, vi, beforeEach } from "vitest";
|
|
import getImage from "../api/utils/getImage.js";
|
|
import {
|
|
setup,
|
|
teardown,
|
|
invalid_urls,
|
|
real_urls,
|
|
default_options,
|
|
} from "./commons.js";
|
|
|
|
describe("getImage", () => {
|
|
beforeAll(() => setup());
|
|
afterAll(teardown);
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("should return a default image for invalid URLs", async () => {
|
|
for (const src of invalid_urls) {
|
|
const result = await getImage({
|
|
src,
|
|
...default_options,
|
|
transformConfigs: {},
|
|
});
|
|
expect(result.images[0].sources[0].srcset).toContain("default");
|
|
}
|
|
}, 20000);
|
|
|
|
it("should process and return image data for valid URLs", async () => {
|
|
|
|
for (const src of real_urls) {
|
|
const result = await getImage({
|
|
src,
|
|
...default_options,
|
|
transformConfigs: {},
|
|
});
|
|
expect(result).toHaveProperty("uuid");
|
|
expect(result).toHaveProperty("images");
|
|
expect(Array.isArray(result.images)).toBe(true);
|
|
expect(result.images.length).toBeGreaterThan(0);
|
|
}
|
|
}, 20000);
|
|
});
|