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";
|
||||
|
||||
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");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user