mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
test(etapi): port delete-attribute
This commit is contained in:
@@ -12,7 +12,9 @@ let createdBranchId: string;
|
||||
|
||||
const USER = "etapi";
|
||||
|
||||
describe("etapi/create-entities", () => {
|
||||
type EntityType = "attachments" | "attributes";
|
||||
|
||||
describe("etapi/delete-entities", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
@@ -22,18 +24,16 @@ describe("etapi/create-entities", () => {
|
||||
({ createdNoteId, createdBranchId } = await createNote());
|
||||
});
|
||||
|
||||
it("deletes attachemnt", async () => {
|
||||
it("deletes attachment", async () => {
|
||||
const attachmentId = await createAttachment();
|
||||
|
||||
// Delete the attachment
|
||||
deleteEntity("attachments", attachmentId);
|
||||
expectNotFound("attachments", attachmentId);
|
||||
});
|
||||
|
||||
// Ensure the attachment can no longer be found.
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/attachments/${attachmentId}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(404);
|
||||
expect(response.body.code).toStrictEqual("ATTACHMENT_NOT_FOUND");
|
||||
it("deletes attribute", async () => {
|
||||
const attributeId = await createAttribute();
|
||||
deleteEntity("attributes", attributeId);
|
||||
expectNotFound("attributes", attributeId);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -106,7 +106,7 @@ async function createAttachment() {
|
||||
return response.body.attachmentId;
|
||||
}
|
||||
|
||||
async function deleteEntity(entity: "attachments", id: string) {
|
||||
async function deleteEntity(entity: EntityType, id: string) {
|
||||
// Delete twice to test idempotency.
|
||||
for (let i=0; i < 2; i++) {
|
||||
await supertest(app)
|
||||
@@ -115,3 +115,11 @@ async function deleteEntity(entity: "attachments", id: string) {
|
||||
.expect(204);
|
||||
}
|
||||
}
|
||||
|
||||
async function expectNotFound(entity: EntityType, id: string) {
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/${entity}/${id}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(404);
|
||||
expect(response.body.code).toStrictEqual("ATTACHMENT_NOT_FOUND");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user