All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
2.1 KiB
TypeScript
54 lines
2.1 KiB
TypeScript
import { html, stubNetwork } from "../../helpers.ts";
|
|
import { assertEquals } from "@std/assert";
|
|
import { fetchRichContent } from "../../../services/rich-content-service.ts";
|
|
|
|
const BASE = "https://example.com/articles/1";
|
|
|
|
Deno.test("generic provider: the full fallback chain", async () => {
|
|
using _ = stubNetwork(() =>
|
|
html(`<html><head>
|
|
<title>Page title</title>
|
|
<meta property="og:site_name" content="Example">
|
|
<meta property="og:title" content="OG title">
|
|
<meta property="og:image" content="https://example.com/og.jpg">
|
|
<meta name="description" content="Plain description">
|
|
<meta name="theme-color" content="rgb(0, 128, 255)">
|
|
<link rel="icon" href="/favicon-32.png" sizes="32x32">
|
|
</head></html>`)
|
|
);
|
|
const content = await fetchRichContent(BASE);
|
|
assertEquals(content, {
|
|
type: "generic",
|
|
url: BASE,
|
|
title: "OG title",
|
|
description: "Plain description",
|
|
thumbnailUrl: "https://example.com/og.jpg",
|
|
faviconUrl: "https://example.com/favicon-32.png",
|
|
accentColor: "#0080ff",
|
|
siteName: "Example",
|
|
});
|
|
});
|
|
|
|
Deno.test("generic provider: a site-wide og:url means og:title/image are ignored", async () => {
|
|
using _ = stubNetwork(() =>
|
|
html(`
|
|
<meta property="og:url" content="https://example.com/">
|
|
<meta property="og:title" content="Site name">
|
|
<meta property="og:image" content="https://example.com/site.jpg">
|
|
<meta name="twitter:title" content="Article title">
|
|
<img src="/photo.jpg">`)
|
|
);
|
|
const content = await fetchRichContent("https://www.example.com/articles/1");
|
|
assertEquals(content?.title, "Article title");
|
|
assertEquals(content?.thumbnailUrl, "https://www.example.com/photo.jpg");
|
|
assertEquals(content?.siteName, "example.com");
|
|
assertEquals(content?.faviconUrl, "https://www.example.com/favicon.ico");
|
|
});
|
|
|
|
Deno.test("generic provider: non-HTML responses carry just the URL", async () => {
|
|
using _ = stubNetwork(() =>
|
|
new Response("{}", { headers: { "content-type": "application/json" } })
|
|
);
|
|
assertEquals(await fetchRichContent(BASE), { type: "generic", url: BASE });
|
|
});
|