test(etapi): port get-inherited-attribute

This commit is contained in:
Elian Doran 2025-06-03 18:26:13 +03:00
parent 8b2d951ad1
commit 9d24ed902c
No known key found for this signature in database
2 changed files with 61 additions and 61 deletions

View File

@ -1,61 +0,0 @@
POST {{triliumHost}}/etapi/create-note
Authorization: {{authToken}}
Content-Type: application/json
{
"parentNoteId": "root",
"title": "GetInheritedAttributes Test Note",
"type": "text",
"content": "Hi there!"
}
> {%
client.assert(response.status === 201);
client.global.set("parentNoteId", response.body.note.noteId);
%}
###
POST {{triliumHost}}/etapi/attributes
Authorization: {{authToken}}
Content-Type: application/json
{
"noteId": "{{parentNoteId}}",
"type": "label",
"name": "mylabel",
"value": "val",
"isInheritable": true
}
> {% client.global.set("createdAttributeId", response.body.attributeId); %}
###
POST {{triliumHost}}/etapi/create-note
Authorization: {{authToken}}
Content-Type: application/json
{
"parentNoteId": "{{parentNoteId}}",
"title": "Hello",
"type": "text",
"content": "Hi there!"
}
> {%
client.global.set("createdNoteId", response.body.note.noteId);
client.global.set("createdBranchId", response.body.branch.branchId);
%}
###
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
Authorization: {{authToken}}
> {%
client.assert(response.status === 200);
client.assert(response.body.noteId == client.global.get("createdNoteId"));
client.assert(response.body.attributes.length == 1);
client.assert(response.body.attributes[0].attributeId == client.global.get("createdAttributeId"));
%}

View File

@ -0,0 +1,61 @@
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 parentNoteId: string;
describe("etapi/patch-note", () => {
beforeAll(async () => {
config.General.noAuthentication = false;
const buildApp = (await (import("../../src/app.js"))).default;
app = await buildApp();
token = await login(app);
parentNoteId = await createNote(app, token);
});
it("gets inherited attribute", async () => {
// Create an inheritable attribute on the parent note.
let response = await supertest(app)
.post("/etapi/attributes")
.auth("etapi", token, { "type": "basic"})
.send({
"noteId": parentNoteId,
"type": "label",
"name": "mylabel",
"value": "val",
"isInheritable": true
})
.expect(201);
const createdAttributeId = response.body.attributeId;
expect(createdAttributeId).toBeTruthy();
// Create a subnote.
response = await supertest(app)
.post("/etapi/create-note")
.auth("etapi", token, { "type": "basic"})
.send({
"parentNoteId": parentNoteId,
"title": "Hello",
"type": "text",
"content": "Hi there!"
})
.expect(201);
const createdNoteId = response.body.note.noteId;
// Check the attribute is inherited.
response = await supertest(app)
.get(`/etapi/notes/${createdNoteId}`)
.auth("etapi", token, { "type": "basic"})
.expect(200);
expect(response.body.noteId).toStrictEqual(createdNoteId);
expect(response.body.attributes).toHaveLength(1);
expect(response.body.attributes[0].attributeId === createdAttributeId);
});
});