You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
1.6 KiB

import { describe, expect, it } from "vitest";
import { resolveMediaUrl } from "./http";
describe("resolveMediaUrl", () => {
it("returns null for null, undefined, or empty string", () => {
expect(resolveMediaUrl(null)).toBeNull();
expect(resolveMediaUrl(undefined)).toBeNull();
expect(resolveMediaUrl("")).toBeNull();
expect(resolveMediaUrl(" ")).toBeNull();
});
it("returns blob and data URLs unchanged for instant preview", () => {
expect(resolveMediaUrl("blob:http://localhost:3000/123-abc")).toBe(
"blob:http://localhost:3000/123-abc",
);
expect(resolveMediaUrl("data:image/jpeg;base64,xyz123==")).toBe(
"data:image/jpeg;base64,xyz123==",
);
});
it("upgrades http to https for habib.nwhco.ir to avoid mixed content blocking", () => {
expect(
resolveMediaUrl("http://habib.nwhco.ir/static/tmp/marriage/photo.jpg"),
).toBe("https://habib.nwhco.ir/static/tmp/marriage/photo.jpg");
});
it("preserves already https absolute URLs", () => {
expect(
resolveMediaUrl("https://habib.nwhco.ir/static/tmp/marriage/photo.jpg"),
).toBe("https://habib.nwhco.ir/static/tmp/marriage/photo.jpg");
expect(resolveMediaUrl("https://images.example.com/avatar.png")).toBe(
"https://images.example.com/avatar.png",
);
});
it("resolves relative paths to full https URLs without using /api/proxy", () => {
const resolved = resolveMediaUrl("/static/tmp/marriage/photo.jpg");
expect(resolved).not.toContain("/api/proxy");
expect(resolved).toMatch(/\/static\/tmp\/marriage\/photo\.jpg$/);
});
});