Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(etapi): port get-inherited-attribute
Elian Doran9d24ed902c37
diff --git a/_regroup/test-etapi/get-inherited-attribute.http b/_regroup/test-etapi/get-inherited-attribute.httpdeleted file mode 100644index 26e9af8545..0000000000--- a/_regroup/test-etapi/get-inherited-attribute.http+++ /dev/null@@ -1,61 +0,0 @@-POST {{triliumHost}}/etapi/create-note-Authorization: {{authToken}}-Content-Type: application/json--{- "parentNoteId": "root",- "title": "GetInheritedAttributes Test Note",- "type": "text",- "content": "Hi there!"-}--> {%- client.assert(response.status === 201);- client.global.set("parentNoteId", response.body.note.noteId);-%}--###--POST {{triliumHost}}/etapi/attributes-Authorization: {{authToken}}-Content-Type: application/json--{- "noteId": "{{parentNoteId}}",- "type": "label",- "name": "mylabel",- "value": "val",- "isInheritable": true-}--> {% client.global.set("createdAttributeId", response.body.attributeId); %}--###--POST {{triliumHost}}/etapi/create-note-Authorization: {{authToken}}-Content-Type: application/json--{- "parentNoteId": "{{parentNoteId}}",- "title": "Hello",- "type": "text",- "content": "Hi there!"-}--> {%-client.global.set("createdNoteId", response.body.note.noteId);-client.global.set("createdBranchId", response.body.branch.branchId);-%}--###--GET {{triliumHost}}/etapi/notes/{{createdNoteId}}-Authorization: {{authToken}}--> {%-client.assert(response.status === 200);-client.assert(response.body.noteId == client.global.get("createdNoteId"));-client.assert(response.body.attributes.length == 1);-client.assert(response.body.attributes[0].attributeId == client.global.get("createdAttributeId"));-%}diff --git a/apps/server/spec/etapi/get-inherited-attribute.spec.ts b/apps/server/spec/etapi/get-inherited-attribute.spec.tsnew file mode 100644index 0000000000..4456c9357a--- /dev/null+++ b/apps/server/spec/etapi/get-inherited-attribute.spec.ts@@ -0,0 +1,61 @@+import { Application } from "express";+import { beforeAll, describe, expect, it } from "vitest";+import supertest from "supertest";+import { createNote, login } from "./utils.js";+import config from "../../src/services/config.js";++let app: Application;+let token: string;++const USER = "etapi";+let parentNoteId: string;++describe("etapi/patch-note", () => {+ beforeAll(async () => {+ config.General.noAuthentication = false;+ const buildApp = (await (import("../../src/app.js"))).default;+ app = await buildApp();+ token = await login(app);++ parentNoteId = await createNote(app, token);+ });++ it("gets inherited attribute", async () => {+ // Create an inheritable attribute on the parent note.+ let response = await supertest(app)+ .post("/etapi/attributes")+ .auth("etapi", token, { "type": "basic"})+ .send({+ "noteId": parentNoteId,+ "type": "label",+ "name": "mylabel",+ "value": "val",+ "isInheritable": true+ })+ .expect(201);+ const createdAttributeId = response.body.attributeId;+ expect(createdAttributeId).toBeTruthy();++ // Create a subnote.+ response = await supertest(app)+ .post("/etapi/create-note")+ .auth("etapi", token, { "type": "basic"})+ .send({+ "parentNoteId": parentNoteId,+ "title": "Hello",+ "type": "text",+ "content": "Hi there!"+ })+ .expect(201);+ const createdNoteId = response.body.note.noteId;++ // Check the attribute is inherited.+ response = await supertest(app)+ .get(`/etapi/notes/${createdNoteId}`)+ .auth("etapi", token, { "type": "basic"})+ .expect(200);+ expect(response.body.noteId).toStrictEqual(createdNoteId);+ expect(response.body.attributes).toHaveLength(1);+ expect(response.body.attributes[0].attributeId === createdAttributeId);+ });+});