Skip to content

Build your personal knowledge base with Trilium Notes

test(etapi): port get-inherited-attribute-cloned

Elian Doran3ec29b2e21b2
diff --git a/_regroup/test-etapi/get-inherited-attribute-cloned.http b/_regroup/test-etapi/get-inherited-attribute-cloned.http
deleted file mode 100644
index eaf8d91b1d..0000000000
--- a/_regroup/test-etapi/get-inherited-attribute-cloned.http
+++ /dev/null
@@ -1,116 +0,0 @@
-POST {{triliumHost}}/etapi/create-note
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "parentNoteId": "root",
- "title": "Hello parent",
- "type": "text",
- "content": "Hi there!"
-}
-
-> {%
-client.assert(response.status === 201);
-client.global.set("parentNoteId", response.body.note.noteId);
-client.global.set("parentBranchId", response.body.branch.branchId);
-%}
-
-### Create inheritable parent attribute
-
-POST {{triliumHost}}/etapi/attributes
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "noteId": "{{parentNoteId}}",
- "type": "label",
- "name": "mylabel",
- "value": "",
- "isInheritable": true,
- "position": 10
-}
-
-> {%
-client.assert(response.status === 201);
-client.global.set("parentAttributeId", response.body.attributeId);
-%}
-
-### Create child note under root
-
-POST {{triliumHost}}/etapi/create-note
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "parentNoteId": "root",
- "title": "Hello child",
- "type": "text",
- "content": "Hi there!"
-}
-
-> {%
-client.assert(response.status === 201);
-client.global.set("childNoteId", response.body.note.noteId);
-client.global.set("childBranchId", response.body.branch.branchId);
-%}
-
-### Create child attribute
-
-POST {{triliumHost}}/etapi/attributes
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "noteId": "{{childNoteId}}",
- "type": "label",
- "name": "mylabel",
- "value": "val",
- "isInheritable": false,
- "position": 10
-}
-
-> {%
-client.assert(response.status === 201);
-client.global.set("childAttributeId", response.body.attributeId);
-%}
-
-### Clone child to parent
-
-POST {{triliumHost}}/etapi/branches
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "noteId": "{{childNoteId}}",
- "parentNoteId": "{{parentNoteId}}"
-}
-
-> {%
-client.assert(response.status === 201);
-client.assert(response.body.parentNoteId == client.global.get("parentNoteId"));
-%}
-
-###
-
-GET {{triliumHost}}/etapi/notes/{{childNoteId}}
-Authorization: {{authToken}}
-
-> {%
-
-function hasAttribute(list, attributeId) {
- for (let i = 0; i < list.length; i++) {
- if (list[i]["attributeId"] === attributeId) {
- return true;
- }
- }
- return false;
-}
-
-client.log(JSON.stringify(response.body.attributes));
-
-client.assert(response.status === 200);
-client.assert(response.body.noteId == client.global.get("childNoteId"));
-client.assert(response.body.attributes.length == 2);
-client.assert(hasAttribute(response.body.attributes, client.global.get("parentAttributeId")));
-client.assert(hasAttribute(response.body.attributes, client.global.get("childAttributeId")));
-%}
diff --git a/apps/server/spec/etapi/get-inherited-attribute-cloned.spec.ts b/apps/server/spec/etapi/get-inherited-attribute-cloned.spec.ts
new file mode 100644
index 0000000000..5d882746fa
--- /dev/null
+++ b/apps/server/spec/etapi/get-inherited-attribute-cloned.spec.ts
@@ -0,0 +1,98 @@
+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;
+
+let parentNoteId: string;
+
+describe("etapi/get-inherited-attribute-cloned", () => {
+ 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,
+ "position": 10
+ })
+ .expect(201);
+ const parentAttributeId = response.body.attributeId;
+ expect(parentAttributeId).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 childNoteId = response.body.note.noteId;
+
+ // Create child attribute
+ response = await supertest(app)
+ .post("/etapi/attributes")
+ .auth("etapi", token, { "type": "basic"})
+ .send({
+ "noteId": childNoteId,
+ "type": "label",
+ "name": "mylabel",
+ "value": "val",
+ "isInheritable": false,
+ "position": 10
+ })
+ .expect(201);
+ const childAttributeId = response.body.attributeId;
+ expect(parentAttributeId).toBeTruthy();
+
+ // Clone child to parent
+ response = await supertest(app)
+ .post("/etapi/branches")
+ .auth("etapi", token, { "type": "basic"})
+ .send({
+ noteId: childNoteId,
+ parentNoteId: parentNoteId
+ })
+ .expect(200);
+ parentNoteId = response.body.parentNoteId;
+
+ // Check attribute IDs
+ response = await supertest(app)
+ .get(`/etapi/notes/${childNoteId}`)
+ .auth("etapi", token, { "type": "basic"})
+ .expect(200);
+ expect(response.body.noteId).toStrictEqual(childNoteId);
+ expect(response.body.attributes).toHaveLength(2);
+ expect(hasAttribute(response.body.attributes, parentAttributeId));
+ expect(hasAttribute(response.body.attributes, childAttributeId));
+ });
+
+ function hasAttribute(list: object[], attributeId: string) {
+ for (let i = 0; i < list.length; i++) {
+ if (list[i]["attributeId"] === attributeId) {
+ return true;
+ }
+ }
+ return false;
+ }
+});
diff --git a/apps/server/spec/etapi/get-inherited-attribute.spec.ts b/apps/server/spec/etapi/get-inherited-attribute.spec.ts
index 4456c9357a..c0e92dde17 100644
--- a/apps/server/spec/etapi/get-inherited-attribute.spec.ts
+++ b/apps/server/spec/etapi/get-inherited-attribute.spec.ts
@@ -7,10 +7,9 @@ import config from "../../src/services/config.js";
let app: Application;
let token: string;
-const USER = "etapi";
let parentNoteId: string;
-describe("etapi/patch-note", () => {
+describe("etapi/get-inherited-attribute", () => {
beforeAll(async () => {
config.General.noAuthentication = false;
const buildApp = (await (import("../../src/app.js"))).default;