test(etapi): port delete-attribute

This commit is contained in:
Elian Doran
2025-06-03 19:11:27 +03:00
parent fe19e05715
commit 94fd53db05
2 changed files with 19 additions and 63 deletions

View File

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