test(etapi): port delete-cloned-branch

This commit is contained in:
Elian Doran 2025-06-03 19:16:59 +03:00
parent 94fd53db05
commit 9d1717ca9f
No known key found for this signature in database
2 changed files with 30 additions and 89 deletions

View File

@ -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); %}

View File

@ -1,5 +1,5 @@
import { Application } from "express"; import { Application } from "express";
import { beforeAll, describe, expect, it } from "vitest"; import { beforeAll, beforeEach, describe, expect, it } from "vitest";
import supertest from "supertest"; import supertest from "supertest";
import { login } from "./utils.js"; import { login } from "./utils.js";
import config from "../../src/services/config.js"; import config from "../../src/services/config.js";
@ -12,7 +12,7 @@ let createdBranchId: string;
const USER = "etapi"; const USER = "etapi";
type EntityType = "attachments" | "attributes"; type EntityType = "attachments" | "attributes" | "branches" | "notes";
describe("etapi/delete-entities", () => { describe("etapi/delete-entities", () => {
beforeAll(async () => { beforeAll(async () => {
@ -20,7 +20,9 @@ describe("etapi/delete-entities", () => {
const buildApp = (await (import("../../src/app.js"))).default; const buildApp = (await (import("../../src/app.js"))).default;
app = await buildApp(); app = await buildApp();
token = await login(app); token = await login(app);
});
beforeEach(async () => {
({ createdNoteId, createdBranchId } = await createNote()); ({ createdNoteId, createdBranchId } = await createNote());
}); });
@ -35,6 +37,25 @@ describe("etapi/delete-entities", () => {
deleteEntity("attributes", attributeId); deleteEntity("attributes", attributeId);
expectNotFound("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() { async function createNote() {
@ -123,3 +144,10 @@ async function expectNotFound(entity: EntityType, id: string) {
.expect(404); .expect(404);
expect(response.body.code).toStrictEqual("ATTACHMENT_NOT_FOUND"); 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);
}