Files
oembed-graphics/test/providers.test.js
Aiden Wilson 4595e782c8
All checks were successful
Build & Push Docker (latest) / verify (push) Successful in 9m26s
Build & Push Docker (latest) / build (push) Successful in 14s
initial commit
2026-05-29 22:24:09 +10:00

41 lines
1.4 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { buildOembedUrl } from "../src/oembed.js";
import { findProvider, flattenProviders, wildcardToRegExp } from "../src/providers.js";
test("wildcard provider schemes match target URLs", () => {
const regex = wildcardToRegExp("https://*.example.com/watch*");
assert.equal(regex.test("https://video.example.com/watch?v=abc"), true);
assert.equal(regex.test("https://example.org/watch?v=abc"), false);
});
test("flattens providers and finds a matching provider", () => {
const providers = flattenProviders([
{
provider_name: "Example",
provider_url: "https://example.com",
endpoints: [
{
schemes: ["https://*.example.com/watch*"],
url: "https://example.com/oembed.{format}",
},
],
},
]);
const provider = findProvider("https://video.example.com/watch?id=1", providers);
assert.equal(provider.providerName, "Example");
assert.equal(provider.endpoint, "https://example.com/oembed.json");
});
test("builds oEmbed provider request URLs", () => {
const url = buildOembedUrl("https://example.com/oembed", "https://video.example.com/watch?id=1", 1280);
assert.equal(url.searchParams.get("url"), "https://video.example.com/watch?id=1");
assert.equal(url.searchParams.get("format"), "json");
assert.equal(url.searchParams.get("maxwidth"), "1280");
});