50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import { isValidWebPortalUrl, normalizeWebPortalUrl } from "@shared/webPortalUrl";
|
||
import { webPortalUrlSchema } from "./webPortalUrl";
|
||
|
||
describe("normalizeWebPortalUrl", () => {
|
||
it("ajoute HTTPS aux adresses de portail saisies sans protocole", () => {
|
||
expect(normalizeWebPortalUrl("www.sfr.fr/mon-espace-client")).toBe(
|
||
"https://www.sfr.fr/mon-espace-client",
|
||
);
|
||
});
|
||
|
||
it("retire les espaces sans modifier une URL HTTPS déjà valide", () => {
|
||
expect(normalizeWebPortalUrl(" https://pro.free.fr/ ")).toBe("https://pro.free.fr/");
|
||
});
|
||
|
||
it("ne transforme pas un protocole non web en URL HTTPS", () => {
|
||
expect(normalizeWebPortalUrl("ftp://example.org/factures")).toBe("ftp://example.org/factures");
|
||
});
|
||
});
|
||
|
||
describe("isValidWebPortalUrl", () => {
|
||
it("accepte exclusivement les URLs HTTP ou HTTPS avec un hôte", () => {
|
||
expect(isValidWebPortalUrl("https://espaceclient.orange.fr/")).toBe(true);
|
||
expect(isValidWebPortalUrl("http://intranet.local/factures")).toBe(true);
|
||
});
|
||
|
||
it("refuse les valeurs vides, incomplètes ou avec un protocole non web", () => {
|
||
expect(isValidWebPortalUrl("")).toBe(false);
|
||
expect(isValidWebPortalUrl("https://")).toBe(false);
|
||
expect(isValidWebPortalUrl("ftp://example.org/factures")).toBe(false);
|
||
});
|
||
});
|
||
|
||
describe("webPortalUrlSchema", () => {
|
||
it("normalise l’URL reçue par l’API avant de la persister", () => {
|
||
expect(webPortalUrlSchema.parse("espaceclient.orange.fr")).toBe(
|
||
"https://espaceclient.orange.fr",
|
||
);
|
||
});
|
||
|
||
it("retourne un message métier pour une URL de portail non HTTP(S)", () => {
|
||
const result = webPortalUrlSchema.safeParse("ftp://example.org/factures");
|
||
|
||
expect(result.success).toBe(false);
|
||
if (!result.success) {
|
||
expect(result.error.issues[0]?.message).toContain("URL HTTP(S) valide");
|
||
}
|
||
});
|
||
});
|