mirror of
https://github.com/debba/wp-media-rewind.git
synced 2026-08-03 07:29:00 +02:00
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { cleanUrl, matchesHost, normalizeHost } from "../src/utils/url.js";
|
|
|
|
test("cleanUrl strips trailing punctuation", () => {
|
|
assert.equal(cleanUrl("https://x.com/a.jpg)."), "https://x.com/a.jpg");
|
|
assert.equal(cleanUrl("https://x.com/a.jpg',"), "https://x.com/a.jpg");
|
|
assert.equal(cleanUrl("https://x.com/a.jpg"), "https://x.com/a.jpg");
|
|
});
|
|
|
|
test("cleanUrl preserves query strings", () => {
|
|
assert.equal(
|
|
cleanUrl("https://x.com/a.jpg?v=1"),
|
|
"https://x.com/a.jpg?v=1",
|
|
);
|
|
});
|
|
|
|
test("normalizeHost accepts bare hosts and full URLs", () => {
|
|
assert.equal(normalizeHost("Example.COM"), "example.com");
|
|
assert.equal(normalizeHost("https://Example.com/path"), "example.com");
|
|
assert.equal(normalizeHost("http://example.com:8080/"), "example.com:8080");
|
|
});
|
|
|
|
test("normalizeHost returns null for empty input", () => {
|
|
assert.equal(normalizeHost(undefined), null);
|
|
assert.equal(normalizeHost(""), null);
|
|
});
|
|
|
|
test("matchesHost null filter accepts everything", () => {
|
|
assert.equal(matchesHost("https://anywhere.test/x.jpg", null), true);
|
|
});
|
|
|
|
test("matchesHost compares case-insensitively", () => {
|
|
assert.equal(matchesHost("https://Example.com/x.jpg", "example.com"), true);
|
|
assert.equal(matchesHost("https://other.com/x.jpg", "example.com"), false);
|
|
});
|
|
|
|
test("matchesHost rejects malformed URLs", () => {
|
|
assert.equal(matchesHost("not a url", "example.com"), false);
|
|
});
|