35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import { html, stubNetwork } from "../../helpers.ts";
|
|
import { assert, assertEquals, assertFalse } from "@std/assert";
|
|
import { fetchRichContent } from "../../../services/rich-content-service.ts";
|
|
import { bandcampProvider } from "../../../remote/providers/bandcamp.ts";
|
|
|
|
Deno.test("bandcamp provider", async () => {
|
|
using _ = stubNetwork(() =>
|
|
html(`<meta property="og:title" content="Album">
|
|
<meta property="og:video" content="https://bandcamp.com/EmbeddedPlayer/album=1">`)
|
|
);
|
|
const bc = await fetchRichContent("https://artist.bandcamp.com/album/a");
|
|
assertEquals(bc?.type, "bandcamp");
|
|
assertEquals(bc?.title, "Album");
|
|
assertEquals(bc?.embedUrl, "https://bandcamp.com/EmbeddedPlayer/album=1");
|
|
});
|
|
|
|
Deno.test("bandcamp provider: bandcamp.com and its subdomains only", () => {
|
|
assert(bandcampProvider.matches("https://artist.bandcamp.com/album/x"));
|
|
assertFalse(
|
|
bandcampProvider.matches("https://bandcamp.com.evil.example/album/x"),
|
|
);
|
|
});
|
|
|
|
Deno.test("bandcamp provider: falls back like any page, embeds only Bandcamp's player", async () => {
|
|
using _ = stubNetwork(() =>
|
|
html(`<meta property="og:title" content="Album">
|
|
<meta name="description" content="An album by Artist">
|
|
<meta property="og:video" content="https://evil.example/EmbeddedPlayer/x">`)
|
|
);
|
|
const bc = await fetchRichContent("https://artist.bandcamp.com/album/b");
|
|
assertEquals(bc?.description, "An album by Artist");
|
|
assertEquals(bc?.siteName, "Bandcamp");
|
|
assertEquals(bc?.embedUrl, undefined);
|
|
});
|