51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import {
|
|
createUser,
|
|
insertDump,
|
|
insertPlaylist,
|
|
stubNetwork,
|
|
test,
|
|
} from "../../helpers.ts";
|
|
import { assertEquals } from "@std/assert";
|
|
import { fetchRichContent } from "../../../services/rich-content-service.ts";
|
|
|
|
test("self provider: our own dump, user and playlist pages come from the DB", async () => {
|
|
const user = await createUser();
|
|
const dump = insertDump({
|
|
userId: user.id,
|
|
title: "Local dump",
|
|
comment: "About it",
|
|
richContent: { type: "generic", url: "x", thumbnailUrl: "https://t/x.jpg" },
|
|
});
|
|
using net = stubNetwork(() => {
|
|
throw new Error("no network for self links");
|
|
});
|
|
const content = await fetchRichContent(
|
|
`http://gerbeur.test${dump.path}`,
|
|
);
|
|
assertEquals(content?.title, "Local dump");
|
|
assertEquals(content?.description, "About it");
|
|
assertEquals(content?.thumbnailUrl, "https://t/x.jpg");
|
|
assertEquals(content?.siteName, "gerbeur");
|
|
const profile = await fetchRichContent(
|
|
`http://gerbeur.test/@${user.username}/playlists`,
|
|
);
|
|
assertEquals(profile?.title, user.username);
|
|
assertEquals(net.calls.length, 0);
|
|
});
|
|
|
|
test("self provider: a private playlist gets no preview", async () => {
|
|
const user = await createUser();
|
|
const playlist = insertPlaylist({
|
|
userId: user.id,
|
|
title: "Secret mix",
|
|
isPublic: false,
|
|
});
|
|
using _net = stubNetwork(() => {
|
|
throw new Error("no network for self links");
|
|
});
|
|
const content = await fetchRichContent(
|
|
`http://gerbeur.test${playlist.path}`,
|
|
);
|
|
assertEquals(content?.title, undefined);
|
|
});
|