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 delete-cloned-branch
Elian Doran9d1717ca9fa0
diff --git a/_regroup/test-etapi/delete-cloned-branch.http b/_regroup/test-etapi/delete-cloned-branch.httpdeleted file mode 100644index a87a6fa4db..0000000000--- a/_regroup/test-etapi/delete-cloned-branch.http+++ /dev/null@@ -1,87 +0,0 @@-POST {{triliumHost}}/etapi/create-note-Authorization: {{authToken}}-Content-Type: application/json--{- "parentNoteId": "root",- "title": "Hello",- "type": "text",- "content": "Hi there!"-}--> {%- client.global.set("createdNoteId", response.body.note.noteId);- client.global.set("createdBranchId", response.body.branch.branchId);-%}--### Clone to another location--POST {{triliumHost}}/etapi/branches-Authorization: {{authToken}}-Content-Type: application/json--{- "noteId": "{{createdNoteId}}",- "parentNoteId": "_hidden"-}--> {% client.global.set("clonedBranchId", response.body.branchId); %}--###--GET {{triliumHost}}/etapi/notes/{{createdNoteId}}-Authorization: {{authToken}}--> {% client.assert(response.status === 200); %}--###--GET {{triliumHost}}/etapi/branches/{{createdBranchId}}-Authorization: {{authToken}}--> {% client.assert(response.status === 200); %}--###--GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}-Authorization: {{authToken}}--> {% client.assert(response.status === 200); %}--###--DELETE {{triliumHost}}/etapi/branches/{{createdBranchId}}-Authorization: {{authToken}}--> {% client.assert(response.status === 204, "Response status is not 204"); %}--### repeat the DELETE request to test the idempotency--DELETE {{triliumHost}}/etapi/branches/{{createdBranchId}}-Authorization: {{authToken}}--> {% client.assert(response.status === 204, "Response status is not 204"); %}--###--GET {{triliumHost}}/etapi/branches/{{createdBranchId}}-Authorization: {{authToken}}--> {%- client.assert(response.status === 404, "Response status is not 404");- client.assert(response.body.code === "BRANCH_NOT_FOUND");-%}--###--GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}-Authorization: {{authToken}}--> {% client.assert(response.status === 200); %}--###--GET {{triliumHost}}/etapi/notes/{{createdNoteId}}-Authorization: {{authToken}}--> {% client.assert(response.status === 200); %}diff --git a/apps/server/spec/etapi/delete-entities.spec.ts b/apps/server/spec/etapi/delete-entities.spec.tsindex 7b8399f385..409048182f 100644--- a/apps/server/spec/etapi/delete-entities.spec.ts+++ b/apps/server/spec/etapi/delete-entities.spec.ts@@ -1,5 +1,5 @@import { Application } from "express";-import { beforeAll, describe, expect, it } from "vitest";+import { beforeAll, beforeEach, describe, expect, it } from "vitest";import supertest from "supertest";import { login } from "./utils.js";import config from "../../src/services/config.js";@@ -12,7 +12,7 @@ let createdBranchId: string;const USER = "etapi";-type EntityType = "attachments" | "attributes";+type EntityType = "attachments" | "attributes" | "branches" | "notes";describe("etapi/delete-entities", () => {beforeAll(async () => {@@ -20,7 +20,9 @@ describe("etapi/delete-entities", () => {const buildApp = (await (import("../../src/app.js"))).default;app = await buildApp();token = await login(app);+ });+ beforeEach(async () => {({ createdNoteId, createdBranchId } = await createNote());});@@ -35,6 +37,25 @@ describe("etapi/delete-entities", () => {deleteEntity("attributes", attributeId);expectNotFound("attributes", attributeId);});++ it("deletes cloned branch", async () => {+ const response = await supertest(app)+ .post("/etapi/branches")+ .auth(USER, token, { "type": "basic"})+ .send({+ noteId: createdNoteId,+ parentNoteId: "_hidden"+ });+ const clonedBranchId = response.body.branchId;+ expectFound("branches", createdBranchId);+ expectFound("branches", clonedBranchId);++ deleteEntity("branches", createdBranchId);+ expectNotFound("branches", createdBranchId);++ expectFound("branches", clonedBranchId);+ expectFound("notes", createdNoteId);+ });});async function createNote() {@@ -123,3 +144,10 @@ async function expectNotFound(entity: EntityType, id: string) {.expect(404);expect(response.body.code).toStrictEqual("ATTACHMENT_NOT_FOUND");}++async function expectFound(entity: EntityType, id: string) {+ await supertest(app)+ .get(`/etapi/${entity}/${id}`)+ .auth(USER, token, { "type": "basic"})+ .expect(200);+}