mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
test(etapi): port delete-cloned-branch
This commit is contained in:
parent
94fd53db05
commit
9d1717ca9f
@ -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); %}
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user