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