test(server/share): protected notes

This commit is contained in:
Elian Doran 2025-09-28 14:48:14 +03:00
parent a393584a2a
commit 1ad8b1bf85
No known key found for this signature in database
2 changed files with 15 additions and 5 deletions

View File

@ -4,7 +4,13 @@ import { trimIndentation } from "@triliumnext/commons";
import { buildShareNote } from "../test/shaca_mocking.js"; import { buildShareNote } from "../test/shaca_mocking.js";
describe("content_renderer", () => { 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("<p>Protected note cannot be displayed</p>");
});
describe("Text note", () => {
it("parses simple note", () => { it("parses simple note", () => {
const content = trimIndentation`\ const content = trimIndentation`\
<figure class="image image-style-align-right image_resized" style="width:29.84%;"> <figure class="image image-style-align-right image_resized" style="width:29.84%;">

View File

@ -8,8 +8,9 @@ type RelationDefinitions = { [key in `~${string}`]: string; };
interface NoteDefinition extends AttributeDefinitions, RelationDefinitions { interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {
id?: string | undefined; id?: string | undefined;
title: string; title?: string;
content?: string | Buffer<ArrayBufferLike>; content?: string | Buffer<ArrayBufferLike>;
isProtected?: boolean;
} }
/** /**
@ -41,18 +42,21 @@ export function buildShareNote(noteDef: NoteDefinition) {
const blobId = "foo"; const blobId = "foo";
const note = new SNote([ const note = new SNote([
noteDef.id ?? utils.randomString(12), noteDef.id ?? utils.randomString(12),
noteDef.title, noteDef.title ?? "New note",
"text", "text",
"text/html", "text/html",
blobId, blobId,
new Date().toUTCString(), // utcDateModified new Date().toUTCString(), // utcDateModified
false // is protected !!noteDef.isProtected
]); ]);
shaca.notes[note.noteId] = note; shaca.notes[note.noteId] = note;
// Handle content // Handle content
if (noteDef.content) { if (noteDef.content) {
note.getContent = () => noteDef.content; note.getContent = () => {
if (noteDef.isProtected) return undefined;
return noteDef.content;
};
} }
// Handle labels & relations // Handle labels & relations