initial commit
This commit is contained in:
40
test/providers.test.js
Normal file
40
test/providers.test.js
Normal file
@@ -0,0 +1,40 @@
|
||||
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");
|
||||
});
|
||||
Reference in New Issue
Block a user