diff --git a/_regroup/test-etapi/delete-attribute.http b/_regroup/test-etapi/delete-attribute.http deleted file mode 100644 index d61b75ba2..000000000 --- a/_regroup/test-etapi/delete-attribute.http +++ /dev/null @@ -1,52 +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); %} - -### - -POST {{triliumHost}}/etapi/attributes -Authorization: {{authToken}} -Content-Type: application/json - -{ - "noteId": "{{createdNoteId}}", - "type": "label", - "name": "mylabel", - "value": "val", - "isInheritable": true -} - -> {% client.global.set("createdAttributeId", response.body.attributeId); %} - -### - -DELETE {{triliumHost}}/etapi/attributes/{{createdAttributeId}} -Authorization: {{authToken}} - -> {% client.assert(response.status === 204, "Response status is not 204"); %} - -### repeat the DELETE request to test the idempotency - -DELETE {{triliumHost}}/etapi/attributes/{{createdAttributeId}} -Authorization: {{authToken}} - -> {% client.assert(response.status === 204, "Response status is not 204"); %} - -### - -GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}} -Authorization: {{authToken}} - -> {% - client.assert(response.status === 404, "Response status is not 404"); - client.assert(response.body.code === "ATTRIBUTE_NOT_FOUND"); -%} diff --git a/apps/server/spec/etapi/delete-entities.spec.ts b/apps/server/spec/etapi/delete-entities.spec.ts index 0a2bb0bee..7b8399f38 100644 --- a/apps/server/spec/etapi/delete-entities.spec.ts +++ b/apps/server/spec/etapi/delete-entities.spec.ts @@ -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"); +}