Skip to content

Build your personal knowledge base with Trilium Notes

test(etapi): port patch branch

Elian Doranee4f9b265e9b
diff --git a/_regroup/test-etapi/patch-branch.http b/_regroup/test-etapi/patch-branch.http
deleted file mode 100644
index 48116120cb..0000000000
--- a/_regroup/test-etapi/patch-branch.http
+++ /dev/null
@@ -1,66 +0,0 @@
-POST {{triliumHost}}/etapi/create-note
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "parentNoteId": "root",
- "type": "text",
- "title": "Hello",
- "content": ""
-}
-
-> {% client.global.set("createdBranchId", response.body.branch.branchId); %}
-
-###
-
-PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "prefix": "pref",
- "notePosition": 666,
- "isExpanded": true
-}
-
-###
-
-GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
-Authorization: {{authToken}}
-
-> {%
-client.assert(response.status === 200);
-client.assert(response.body.prefix === 'pref');
-client.assert(response.body.notePosition === 666);
-client.assert(response.body.isExpanded === true);
-%}
-
-###
-
-PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "parentNoteId": "root"
-}
-
-> {%
- client.assert(response.status === 400);
- client.assert(response.body.code == "PROPERTY_NOT_ALLOWED");
-%}
-
-###
-
-PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
-Authorization: {{authToken}}
-Content-Type: application/json
-
-{
- "prefix": 123
-}
-
-> {%
- client.assert(response.status === 400);
- client.assert(response.body.code == "PROPERTY_VALIDATION_ERROR");
-%}
\ No newline at end of file
diff --git a/apps/server/spec/etapi/patch-branch.spec.ts b/apps/server/spec/etapi/patch-branch.spec.ts
new file mode 100644
index 0000000000..ecca59b2d2
--- /dev/null
+++ b/apps/server/spec/etapi/patch-branch.spec.ts
@@ -0,0 +1,77 @@
+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 createdBranchId: string;
+
+describe("etapi/attachment-content", () => {
+ beforeAll(async () => {
+ config.General.noAuthentication = false;
+ const buildApp = (await (import("../../src/app.js"))).default;
+ app = await buildApp();
+ token = await login(app);
+
+ // Create a note and a branch.
+ const response = await supertest(app)
+ .post("/etapi/create-note")
+ .auth("etapi", token, { "type": "basic"})
+ .send({
+ "parentNoteId": "root",
+ "title": "Hello",
+ "type": "text",
+ "content": "",
+ })
+ .expect(201);
+
+ createdBranchId = response.body.branch.branchId;
+ });
+
+ it("can patch branch info", async () => {
+ const state = {
+ prefix: "pref",
+ notePosition: 666,
+ isExpanded: true
+ };
+
+ await supertest(app)
+ .patch(`/etapi/branches/${createdBranchId}`)
+ .auth("etapi", token, { "type": "basic"})
+ .send(state)
+ .expect(200);
+
+ const response = await supertest(app)
+ .get(`/etapi/branches/${createdBranchId}`)
+ .auth("etapi", token, { "type": "basic"})
+ .expect(200);
+ expect(response.body).toMatchObject(state);
+ });
+
+ it("rejects not allowed property", async () => {
+ const response = await supertest(app)
+ .patch(`/etapi/branches/${createdBranchId}`)
+ .auth("etapi", token, { "type": "basic"})
+ .send({
+ parentNoteId: "root"
+ })
+ .expect(400);
+ expect(response.body.code).toStrictEqual("PROPERTY_NOT_ALLOWED");
+ });
+
+ it("rejects invalid property value", async () => {
+ const response = await supertest(app)
+ .patch(`/etapi/branches/${createdBranchId}`)
+ .auth("etapi", token, { "type": "basic"})
+ .send({
+ prefix: 123
+ })
+ .expect(400);
+ expect(response.body.code).toStrictEqual("PROPERTY_VALIDATION_ERROR");
+ });
+
+});