1import { ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3import { resolveMobileMarkdownMediaSource } from "./markdownMediaSource";
4
5describe("mobile Markdown draft media", () => {
6 it("authorizes relative images and videos against the draft directory", () => {
7 for (const name of ["diagram.svg", "clip.mp4"]) {
8 expect(
9 resolveMobileMarkdownMediaSource(`./${name}`, {
10 threadId: undefined,
11 workspaceRoot: "/project/docs",
12 imageEmbed: true,
13 }),
14 ).toMatchObject({
15 access: "environment",
16 resource: {
17 _tag: "draft-workspace-file",
18 cwd: "/project/docs",
19 path: `/project/docs/./${name}`,
20 },
21 });
22 }
23 });
24
25 it("keeps thread authorization when a thread exists", () => {
26 const threadId = ThreadId.make("markdown-thread");
27 expect(
28 resolveMobileMarkdownMediaSource("image.png", { threadId, workspaceRoot: "/project" }),
29 ).toMatchObject({ resource: { _tag: "media-file", threadId, path: "/project/image.png" } });
30 });
31
32 it("keeps direct URLs direct and rejects unresolvable or blocked references", () => {
33 const input = { threadId: undefined, workspaceRoot: "/project" };
34 expect(resolveMobileMarkdownMediaSource("https://example.com/image.png", input)).toMatchObject({
35 access: "direct",
36 uri: "https://example.com/image.png",
37 });
38 expect(resolveMobileMarkdownMediaSource("javascript:alert(1)", input)).toBeNull();
39 expect(resolveMobileMarkdownMediaSource("image.png", { threadId: undefined })).toBeNull();
40 });
41});