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
2 changed files with 30 additions and 89 deletions

View File

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