From 1ad8b1bf853a89c15012d655cb2ed6cd7a7fae4f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 28 Sep 2025 14:48:14 +0300 Subject: [PATCH] test(server/share): protected notes --- apps/server/src/share/content_renderer.spec.ts | 8 +++++++- apps/server/src/test/shaca_mocking.ts | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/server/src/share/content_renderer.spec.ts b/apps/server/src/share/content_renderer.spec.ts index 04f60bd71..363b74390 100644 --- a/apps/server/src/share/content_renderer.spec.ts +++ b/apps/server/src/share/content_renderer.spec.ts @@ -4,7 +4,13 @@ import { trimIndentation } from "@triliumnext/commons"; import { buildShareNote } from "../test/shaca_mocking.js"; describe("content_renderer", () => { - describe("renderText", () => { + it("Reports protected notes not being renderable", () => { + const note = buildShareNote({ isProtected: true }); + const result = getContent(note); + expect(result.content).toStrictEqual("

Protected note cannot be displayed

"); + }); + + describe("Text note", () => { it("parses simple note", () => { const content = trimIndentation`\
diff --git a/apps/server/src/test/shaca_mocking.ts b/apps/server/src/test/shaca_mocking.ts index e92411500..022ee999a 100644 --- a/apps/server/src/test/shaca_mocking.ts +++ b/apps/server/src/test/shaca_mocking.ts @@ -8,8 +8,9 @@ type RelationDefinitions = { [key in `~${string}`]: string; }; interface NoteDefinition extends AttributeDefinitions, RelationDefinitions { id?: string | undefined; - title: string; + title?: string; content?: string | Buffer; + isProtected?: boolean; } /** @@ -41,18 +42,21 @@ export function buildShareNote(noteDef: NoteDefinition) { const blobId = "foo"; const note = new SNote([ noteDef.id ?? utils.randomString(12), - noteDef.title, + noteDef.title ?? "New note", "text", "text/html", blobId, new Date().toUTCString(), // utcDateModified - false // is protected + !!noteDef.isProtected ]); shaca.notes[note.noteId] = note; // Handle content if (noteDef.content) { - note.getContent = () => noteDef.content; + note.getContent = () => { + if (noteDef.isProtected) return undefined; + return noteDef.content; + }; } // Handle labels & relations