mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
test(etapi): delete-entities not running properly due to missing await
This commit is contained in:
parent
594e264eea
commit
cd310119bc
@ -28,14 +28,14 @@ describe("etapi/delete-entities", () => {
|
|||||||
|
|
||||||
it("deletes attachment", async () => {
|
it("deletes attachment", async () => {
|
||||||
const attachmentId = await createAttachment();
|
const attachmentId = await createAttachment();
|
||||||
deleteEntity("attachments", attachmentId);
|
await deleteEntity("attachments", attachmentId);
|
||||||
expectNotFound("attachments", attachmentId);
|
await expectNotFound("attachments", attachmentId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("deletes attribute", async () => {
|
it("deletes attribute", async () => {
|
||||||
const attributeId = await createAttribute();
|
const attributeId = await createAttribute();
|
||||||
deleteEntity("attributes", attributeId);
|
await deleteEntity("attributes", attributeId);
|
||||||
expectNotFound("attributes", attributeId);
|
await expectNotFound("attributes", attributeId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("deletes cloned branch", async () => {
|
it("deletes cloned branch", async () => {
|
||||||
@ -47,14 +47,14 @@ describe("etapi/delete-entities", () => {
|
|||||||
parentNoteId: "_hidden"
|
parentNoteId: "_hidden"
|
||||||
});
|
});
|
||||||
const clonedBranchId = response.body.branchId;
|
const clonedBranchId = response.body.branchId;
|
||||||
expectFound("branches", createdBranchId);
|
await expectFound("branches", createdBranchId);
|
||||||
expectFound("branches", clonedBranchId);
|
await expectFound("branches", clonedBranchId);
|
||||||
|
|
||||||
deleteEntity("branches", createdBranchId);
|
await deleteEntity("branches", createdBranchId);
|
||||||
expectNotFound("branches", createdBranchId);
|
await expectNotFound("branches", createdBranchId);
|
||||||
|
|
||||||
expectFound("branches", clonedBranchId);
|
await expectFound("branches", clonedBranchId);
|
||||||
expectFound("notes", createdNoteId);
|
await expectFound("notes", createdNoteId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("deletes note with all branches", async () => {
|
it("deletes note with all branches", async () => {
|
||||||
@ -69,16 +69,16 @@ describe("etapi/delete-entities", () => {
|
|||||||
});
|
});
|
||||||
const clonedBranchId = response.body.branchId;
|
const clonedBranchId = response.body.branchId;
|
||||||
|
|
||||||
expectFound("notes", createdNoteId);
|
await expectFound("notes", createdNoteId);
|
||||||
expectFound("branches", createdBranchId);
|
await expectFound("branches", createdBranchId);
|
||||||
expectFound("branches", clonedBranchId);
|
await expectFound("branches", clonedBranchId);
|
||||||
expectFound("attributes", attributeId);
|
await expectFound("attributes", attributeId);
|
||||||
deleteEntity("notes", createdNoteId);
|
await deleteEntity("notes", createdNoteId);
|
||||||
|
|
||||||
expectNotFound("branches", createdBranchId);
|
await expectNotFound("branches", createdBranchId);
|
||||||
expectNotFound("branches", clonedBranchId);
|
await expectNotFound("branches", clonedBranchId);
|
||||||
expectNotFound("notes", createdNoteId);
|
await expectNotFound("notes", createdNoteId);
|
||||||
expectNotFound("attributes", attributeId);
|
await expectNotFound("attributes", attributeId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -161,12 +161,20 @@ async function deleteEntity(entity: EntityType, id: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MISSING_ENTITY_ERROR_CODES: Record<EntityType, string> = {
|
||||||
|
attachments: "ATTACHMENT_NOT_FOUND",
|
||||||
|
attributes: "ATTRIBUTE_NOT_FOUND",
|
||||||
|
branches: "BRANCH_NOT_FOUND",
|
||||||
|
notes: "NOTE_NOT_FOUND"
|
||||||
|
}
|
||||||
|
|
||||||
async function expectNotFound(entity: EntityType, id: string) {
|
async function expectNotFound(entity: EntityType, id: string) {
|
||||||
const response = await supertest(app)
|
const response = await supertest(app)
|
||||||
.get(`/etapi/${entity}/${id}`)
|
.get(`/etapi/${entity}/${id}`)
|
||||||
.auth(USER, token, { "type": "basic"})
|
.auth(USER, token, { "type": "basic"})
|
||||||
.expect(404);
|
.expect(404);
|
||||||
expect(response.body.code).toStrictEqual("ATTACHMENT_NOT_FOUND");
|
|
||||||
|
expect(response.body.code).toStrictEqual(MISSING_ENTITY_ERROR_CODES[entity]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function expectFound(entity: EntityType, id: string) {
|
async function expectFound(entity: EntityType, id: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user