From 614a8f177c9f806d8558209816b3f3b2d108d191 Mon Sep 17 00:00:00 2001
From: Elian Doran
Date: Sun, 28 Sep 2025 15:43:39 +0300
Subject: [PATCH] test(server/share): attachment links
---
.../server/src/share/content_renderer.spec.ts | 31 ++++++++++++++++---
apps/server/src/test/shaca_mocking.ts | 24 ++++++++++++++
2 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/apps/server/src/share/content_renderer.spec.ts b/apps/server/src/share/content_renderer.spec.ts
index 137d85c97..c8601fe57 100644
--- a/apps/server/src/share/content_renderer.spec.ts
+++ b/apps/server/src/share/content_renderer.spec.ts
@@ -21,14 +21,37 @@ describe("content_renderer", () => {
Welcome to Trilium Notes!
`;
- const note = buildShareNote({
- title: "Note",
- content
- });
+ const note = buildShareNote({ content });
const result = getContent(note);
expect(result.content).toStrictEqual(content);
});
+ it("handles attachment link", () => {
+ const content = trimIndentation`\
+ Test
+
+
+ 5863845791835102555.mp4
+
+
+
+ `;
+ const note = buildShareNote({
+ content,
+ attachments: [ { id: "q14s2Id7V6pp" } ]
+ });
+ const result = getContent(note);
+ expect(result.content).toStrictEqual(trimIndentation`\
+ Test
+
+
+ 5863845791835102555.mp4
+
+
+
+ `);
+ });
+
it("renders included notes", () => {
buildShareNotes([
{ id: "subnote1", content: `Foo
Bar
` },
diff --git a/apps/server/src/test/shaca_mocking.ts b/apps/server/src/test/shaca_mocking.ts
index af02394a0..8b2068a0e 100644
--- a/apps/server/src/test/shaca_mocking.ts
+++ b/apps/server/src/test/shaca_mocking.ts
@@ -1,4 +1,5 @@
import utils from "../services/utils.js";
+import SAttachment from "../share/shaca/entities/sattachment.js";
import SAttribute from "../share/shaca/entities/sattribute.js";
import SNote from "../share/shaca/entities/snote.js";
import shaca from "../share/shaca/shaca.js";
@@ -6,11 +7,19 @@ import shaca from "../share/shaca/shaca.js";
type AttributeDefinitions = { [key in `#${string}`]: string; };
type RelationDefinitions = { [key in `~${string}`]: string; };
+interface AttachementDefinition {
+ id?: string;
+ role?: string;
+ mime?: string;
+ title?: string;
+}
+
interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {
id?: string | undefined;
title?: string;
content?: string | Buffer;
children?: NoteDefinition[];
+ attachments?: AttachementDefinition[];
isProtected?: boolean;
}
@@ -60,6 +69,21 @@ export function buildShareNote(noteDef: NoteDefinition) {
};
}
+ // Handle attachments.
+ if (noteDef.attachments) {
+ for (const attachmentDef of noteDef.attachments) {
+ new SAttachment([
+ attachmentDef.id ?? utils.randomString(12),
+ note.noteId,
+ attachmentDef.role ?? "file",
+ attachmentDef.mime ?? "application/blob",
+ attachmentDef.title ?? "New attachment",
+ blobId,
+ new Date().toUTCString(), // utcDateModified
+ ]);
+ }
+ }
+
// Handle children.
if (noteDef.children) {
for (const childDef of noteDef.children) {