mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
test(etapi): port patch-attribute
This commit is contained in:
parent
cf24308cb0
commit
8b2d951ad1
@ -1,80 +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);
|
|
||||||
client.global.set("createdBranchId", response.body.branch.branchId);
|
|
||||||
%}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
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); %}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
PATCH {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
|
||||||
Authorization: {{authToken}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"value": "CHANGED"
|
|
||||||
}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
|
||||||
Authorization: {{authToken}}
|
|
||||||
|
|
||||||
> {%
|
|
||||||
client.assert(response.body.value === "CHANGED");
|
|
||||||
%}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
PATCH {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
|
||||||
Authorization: {{authToken}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"noteId": "root"
|
|
||||||
}
|
|
||||||
|
|
||||||
> {%
|
|
||||||
client.assert(response.status === 400);
|
|
||||||
client.assert(response.body.code == "PROPERTY_NOT_ALLOWED");
|
|
||||||
%}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
PATCH {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
|
||||||
Authorization: {{authToken}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"value": null
|
|
||||||
}
|
|
||||||
|
|
||||||
> {%
|
|
||||||
client.assert(response.status === 400);
|
|
||||||
client.assert(response.body.code == "PROPERTY_VALIDATION_ERROR");
|
|
||||||
%}
|
|
77
apps/server/spec/etapi/patch-attribute.spec.ts
Normal file
77
apps/server/spec/etapi/patch-attribute.spec.ts
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import { Application } from "express";
|
||||||
|
import { beforeAll, describe, expect, it } from "vitest";
|
||||||
|
import supertest from "supertest";
|
||||||
|
import { createNote, login } from "./utils.js";
|
||||||
|
import config from "../../src/services/config.js";
|
||||||
|
|
||||||
|
let app: Application;
|
||||||
|
let token: string;
|
||||||
|
|
||||||
|
const USER = "etapi";
|
||||||
|
let createdNoteId: string;
|
||||||
|
let createdAttributeId: string;
|
||||||
|
|
||||||
|
describe("etapi/patch-attribute", () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
config.General.noAuthentication = false;
|
||||||
|
const buildApp = (await (import("../../src/app.js"))).default;
|
||||||
|
app = await buildApp();
|
||||||
|
token = await login(app);
|
||||||
|
|
||||||
|
createdNoteId = await createNote(app, token);
|
||||||
|
|
||||||
|
// Create an attribute
|
||||||
|
const response = await supertest(app)
|
||||||
|
.post(`/etapi/attributes`)
|
||||||
|
.auth(USER, token, { "type": "basic"})
|
||||||
|
.send({
|
||||||
|
"noteId": createdNoteId,
|
||||||
|
"type": "label",
|
||||||
|
"name": "mylabel",
|
||||||
|
"value": "val",
|
||||||
|
"isInheritable": true
|
||||||
|
});
|
||||||
|
createdAttributeId = response.body.attributeId;
|
||||||
|
expect(createdAttributeId).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("changes name and value", async () => {
|
||||||
|
const state = {
|
||||||
|
value: "CHANGED"
|
||||||
|
};
|
||||||
|
await supertest(app)
|
||||||
|
.patch(`/etapi/attributes/${createdAttributeId}`)
|
||||||
|
.auth(USER, token, { "type": "basic"})
|
||||||
|
.send(state)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
// Ensure it got changed.
|
||||||
|
const response = await supertest(app)
|
||||||
|
.get(`/etapi/attributes/${createdAttributeId}`)
|
||||||
|
.auth(USER, token, { "type": "basic"});
|
||||||
|
expect(response.body).toMatchObject(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("forbids setting disallowed property", async () => {
|
||||||
|
const response = await supertest(app)
|
||||||
|
.patch(`/etapi/attributes/${createdAttributeId}`)
|
||||||
|
.auth(USER, token, { "type": "basic"})
|
||||||
|
.send({
|
||||||
|
noteId: "root"
|
||||||
|
})
|
||||||
|
.expect(400);
|
||||||
|
expect(response.body.code).toStrictEqual("PROPERTY_NOT_ALLOWED");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("forbids setting wrong data type", async () => {
|
||||||
|
const response = await supertest(app)
|
||||||
|
.patch(`/etapi/attributes/${createdAttributeId}`)
|
||||||
|
.auth(USER, token, { "type": "basic"})
|
||||||
|
.send({
|
||||||
|
value: null
|
||||||
|
})
|
||||||
|
.expect(400);
|
||||||
|
expect(response.body.code).toStrictEqual("PROPERTY_VALIDATION_ERROR");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user