mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
wip
This commit is contained in:
parent
10f3df3ed4
commit
f195c7d1b6
@ -1,109 +0,0 @@
|
|||||||
const crypto = require('crypto');
|
|
||||||
const {
|
|
||||||
deleteEtapi,
|
|
||||||
getEtapiResponse,
|
|
||||||
describeEtapi, postEtapi,
|
|
||||||
getEtapi,
|
|
||||||
getEtapiContent,
|
|
||||||
patchEtapi, putEtapi,
|
|
||||||
putEtapiContent
|
|
||||||
} = require("../support/etapi");
|
|
||||||
|
|
||||||
describeEtapi("notes", () => {
|
|
||||||
it("create", async () => {
|
|
||||||
const {note, branch} = await postEtapi('create-note', {
|
|
||||||
parentNoteId: 'root',
|
|
||||||
type: 'text',
|
|
||||||
title: 'Hello World!',
|
|
||||||
content: 'Content',
|
|
||||||
prefix: 'Custom prefix'
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(note.title).toEqual("Hello World!");
|
|
||||||
expect(branch.parentNoteId).toEqual("root");
|
|
||||||
expect(branch.prefix).toEqual("Custom prefix");
|
|
||||||
|
|
||||||
const rNote = await getEtapi(`notes/${note.noteId}`);
|
|
||||||
expect(rNote.title).toEqual("Hello World!");
|
|
||||||
|
|
||||||
const rContent = await (await getEtapiContent(`notes/${note.noteId}/content`)).text();
|
|
||||||
expect(rContent).toEqual("Content");
|
|
||||||
|
|
||||||
const rBranch = await getEtapi(`branches/${branch.branchId}`);
|
|
||||||
expect(rBranch.parentNoteId).toEqual("root");
|
|
||||||
expect(rBranch.prefix).toEqual("Custom prefix");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("patch", async () => {
|
|
||||||
const {note} = await postEtapi('create-note', {
|
|
||||||
parentNoteId: 'root',
|
|
||||||
type: 'text',
|
|
||||||
title: 'Hello World!',
|
|
||||||
content: 'Content'
|
|
||||||
});
|
|
||||||
|
|
||||||
await patchEtapi(`notes/${note.noteId}`, {
|
|
||||||
title: 'new title',
|
|
||||||
type: 'code',
|
|
||||||
mime: 'text/apl',
|
|
||||||
dateCreated: '2000-01-01 12:34:56.999+0200',
|
|
||||||
utcDateCreated: '2000-01-01 10:34:56.999Z',
|
|
||||||
});
|
|
||||||
|
|
||||||
const rNote = await getEtapi(`notes/${note.noteId}`);
|
|
||||||
expect(rNote.title).toEqual("new title");
|
|
||||||
expect(rNote.type).toEqual("code");
|
|
||||||
expect(rNote.mime).toEqual("text/apl");
|
|
||||||
expect(rNote.dateCreated).toEqual("2000-01-01 12:34:56.999+0200");
|
|
||||||
expect(rNote.utcDateCreated).toEqual("2000-01-01 10:34:56.999Z");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("update content", async () => {
|
|
||||||
const {note} = await postEtapi('create-note', {
|
|
||||||
parentNoteId: 'root',
|
|
||||||
type: 'text',
|
|
||||||
title: 'Hello World!',
|
|
||||||
content: 'Content'
|
|
||||||
});
|
|
||||||
|
|
||||||
await putEtapiContent(`notes/${note.noteId}/content`, "new content");
|
|
||||||
|
|
||||||
const rContent = await (await getEtapiContent(`notes/${note.noteId}/content`)).text();
|
|
||||||
expect(rContent).toEqual("new content");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("create / update binary content", async () => {
|
|
||||||
const {note} = await postEtapi('create-note', {
|
|
||||||
parentNoteId: 'root',
|
|
||||||
type: 'file',
|
|
||||||
title: 'Hello World!',
|
|
||||||
content: 'ZZZ'
|
|
||||||
});
|
|
||||||
|
|
||||||
const updatedContent = crypto.randomBytes(16);
|
|
||||||
|
|
||||||
await putEtapiContent(`notes/${note.noteId}/content`, updatedContent);
|
|
||||||
|
|
||||||
const rContent = await (await getEtapiContent(`notes/${note.noteId}/content`)).arrayBuffer();
|
|
||||||
expect(Buffer.from(new Uint8Array(rContent))).toEqual(updatedContent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("delete note", async () => {
|
|
||||||
const {note} = await postEtapi('create-note', {
|
|
||||||
parentNoteId: 'root',
|
|
||||||
type: 'text',
|
|
||||||
title: 'Hello World!',
|
|
||||||
content: 'Content'
|
|
||||||
});
|
|
||||||
|
|
||||||
await deleteEtapi(`notes/${note.noteId}`);
|
|
||||||
|
|
||||||
const resp = await getEtapiResponse(`notes/${note.noteId}`);
|
|
||||||
expect(resp.status).toEqual(404);
|
|
||||||
|
|
||||||
const error = await resp.json();
|
|
||||||
expect(error.status).toEqual(404);
|
|
||||||
expect(error.code).toEqual("NOTE_NOT_FOUND");
|
|
||||||
expect(error.message).toEqual(`Note '${note.noteId}' not found.`);
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,5 +1,108 @@
|
|||||||
describe("Notes", () => {
|
const crypto = require('crypto');
|
||||||
it("zzz", () => {
|
const {
|
||||||
|
deleteEtapi,
|
||||||
|
getEtapiResponse,
|
||||||
|
describeEtapi, postEtapi,
|
||||||
|
getEtapi,
|
||||||
|
getEtapiContent,
|
||||||
|
patchEtapi, putEtapi,
|
||||||
|
putEtapiContent
|
||||||
|
} = require("../support/etapi");
|
||||||
|
|
||||||
|
describeEtapi("notes", () => {
|
||||||
|
it("create", async () => {
|
||||||
|
const {note, branch} = await postEtapi('create-note', {
|
||||||
|
parentNoteId: 'root',
|
||||||
|
type: 'text',
|
||||||
|
title: 'Hello World!',
|
||||||
|
content: 'Content',
|
||||||
|
prefix: 'Custom prefix'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(note.title).toEqual("Hello World!");
|
||||||
|
expect(branch.parentNoteId).toEqual("root");
|
||||||
|
|
||||||
|
const rNote = await getEtapi(`notes/${note.noteId}`);
|
||||||
|
expect(rNote.title).toEqual("Hello World!");
|
||||||
|
|
||||||
|
const rContent = await (await getEtapiContent(`notes/${note.noteId}/content`)).text();
|
||||||
|
expect(rContent).toEqual("Content");
|
||||||
|
|
||||||
|
const rBranch = await getEtapi(`branches/${branch.branchId}`);
|
||||||
|
expect(rBranch.parentNoteId).toEqual("root");
|
||||||
|
expect(rBranch.prefix).toEqual("Custom prefix");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("patch", async () => {
|
||||||
|
const {note} = await postEtapi('create-note', {
|
||||||
|
parentNoteId: 'root',
|
||||||
|
type: 'text',
|
||||||
|
title: 'Hello World!',
|
||||||
|
content: 'Content'
|
||||||
|
});
|
||||||
|
|
||||||
|
await patchEtapi(`notes/${note.noteId}`, {
|
||||||
|
title: 'new title',
|
||||||
|
type: 'code',
|
||||||
|
mime: 'text/apl',
|
||||||
|
dateCreated: '2000-01-01 12:34:56.999+0200',
|
||||||
|
utcDateCreated: '2000-01-01 10:34:56.999Z',
|
||||||
|
});
|
||||||
|
|
||||||
|
const rNote = await getEtapi(`notes/${note.noteId}`);
|
||||||
|
expect(rNote.title).toEqual("new title");
|
||||||
|
expect(rNote.type).toEqual("code");
|
||||||
|
expect(rNote.mime).toEqual("text/apl");
|
||||||
|
expect(rNote.dateCreated).toEqual("2000-01-01 12:34:56.999+0200");
|
||||||
|
expect(rNote.utcDateCreated).toEqual("2000-01-01 10:34:56.999Z");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("update content", async () => {
|
||||||
|
const {note} = await postEtapi('create-note', {
|
||||||
|
parentNoteId: 'root',
|
||||||
|
type: 'text',
|
||||||
|
title: 'Hello World!',
|
||||||
|
content: 'Content'
|
||||||
|
});
|
||||||
|
|
||||||
|
await putEtapiContent(`notes/${note.noteId}/content`, "new content");
|
||||||
|
|
||||||
|
const rContent = await (await getEtapiContent(`notes/${note.noteId}/content`)).text();
|
||||||
|
expect(rContent).toEqual("new content");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("create / update binary content", async () => {
|
||||||
|
const {note} = await postEtapi('create-note', {
|
||||||
|
parentNoteId: 'root',
|
||||||
|
type: 'file',
|
||||||
|
title: 'Hello World!',
|
||||||
|
content: 'ZZZ'
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedContent = crypto.randomBytes(16);
|
||||||
|
|
||||||
|
await putEtapiContent(`notes/${note.noteId}/content`, updatedContent);
|
||||||
|
|
||||||
|
const rContent = await (await getEtapiContent(`notes/${note.noteId}/content`)).arrayBuffer();
|
||||||
|
expect(Buffer.from(new Uint8Array(rContent))).toEqual(updatedContent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("delete note", async () => {
|
||||||
|
const {note} = await postEtapi('create-note', {
|
||||||
|
parentNoteId: 'root',
|
||||||
|
type: 'text',
|
||||||
|
title: 'Hello World!',
|
||||||
|
content: 'Content'
|
||||||
|
});
|
||||||
|
|
||||||
|
await deleteEtapi(`notes/${note.noteId}`);
|
||||||
|
|
||||||
|
const resp = await getEtapiResponse(`notes/${note.noteId}`);
|
||||||
|
expect(resp.status).toEqual(404);
|
||||||
|
|
||||||
|
const error = await resp.json();
|
||||||
|
expect(error.status).toEqual(404);
|
||||||
|
expect(error.code).toEqual("NOTE_NOT_FOUND");
|
||||||
|
expect(error.message).toEqual(`Note '${note.noteId}' not found.`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
43
spec/etapi/search.spec.js
Normal file
43
spec/etapi/search.spec.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
const crypto = require('crypto');
|
||||||
|
const {
|
||||||
|
deleteEtapi,
|
||||||
|
getEtapiResponse,
|
||||||
|
describeEtapi, postEtapi,
|
||||||
|
getEtapi,
|
||||||
|
getEtapiContent,
|
||||||
|
patchEtapi, putEtapi,
|
||||||
|
putEtapiContent
|
||||||
|
} = require("../support/etapi");
|
||||||
|
const {createTextNote} = require("../support/etapi.js");
|
||||||
|
|
||||||
|
describeEtapi("search", () => {
|
||||||
|
describe('search', () => {
|
||||||
|
let europe, america;
|
||||||
|
let austria, czechia;
|
||||||
|
let usa, canada;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
europe = await createTextNote(null, 'Europe');
|
||||||
|
austria = await createTextNote(europe.noteId, 'Austria');
|
||||||
|
czechia = await createTextNote(europe.noteId, 'Czechia');
|
||||||
|
|
||||||
|
america = await createTextNote(null, 'America');
|
||||||
|
usa = await createTextNote(null, 'USA');
|
||||||
|
canada = await createTextNote(null, 'Canada');
|
||||||
|
});
|
||||||
|
|
||||||
|
async function search(searchString, params) {
|
||||||
|
const keyToValues = Object.keys(params).map(key => `${key}=${params[key]}`);
|
||||||
|
|
||||||
|
const {results} = await getEtapi(`notes?search=${searchString}&${keyToValues.join('&')}`);
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
it("search", async () => {
|
||||||
|
const results = await search('Austria');
|
||||||
|
|
||||||
|
expect(results.length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -8,6 +8,8 @@ const getEtapiAuthorizationHeader = () => "Basic " + Buffer.from(`etapi:${etapiA
|
|||||||
const PORT = '9999';
|
const PORT = '9999';
|
||||||
const HOST = 'http://localhost:' + PORT;
|
const HOST = 'http://localhost:' + PORT;
|
||||||
|
|
||||||
|
let currentTestRootNote = null;
|
||||||
|
|
||||||
function describeEtapi(description, specDefinitions) {
|
function describeEtapi(description, specDefinitions) {
|
||||||
describe(description, () => {
|
describe(description, () => {
|
||||||
let appProcess;
|
let appProcess;
|
||||||
@ -42,6 +44,10 @@ function describeEtapi(description, specDefinitions) {
|
|||||||
})).json()).authToken;
|
})).json()).authToken;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
currentTestRootNote = await createTextNote('root', "test root");
|
||||||
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
console.log("Attempting to kill the Trilium process as part of the cleanup...");
|
console.log("Attempting to kill the Trilium process as part of the cleanup...");
|
||||||
kill(appProcess.pid, 'SIGKILL', () => { console.log("Trilium process killed.") });
|
kill(appProcess.pid, 'SIGKILL', () => { console.log("Trilium process killed.") });
|
||||||
@ -51,6 +57,30 @@ function describeEtapi(description, specDefinitions) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createTextNote(parentNoteId = null, title = 'new note', content = '') {
|
||||||
|
if (!parentNoteId) {
|
||||||
|
parentNoteId = currentTestRootNote.noteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {note} = await postEtapi('create-note', {
|
||||||
|
parentNoteId,
|
||||||
|
type: 'text',
|
||||||
|
title,
|
||||||
|
content
|
||||||
|
});
|
||||||
|
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createLabel(noteId, name, value = '', isInheritable = false) {
|
||||||
|
return await postEtapi('attributes', {
|
||||||
|
type: 'label',
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
isInheritable
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function getEtapiResponse(url) {
|
async function getEtapiResponse(url) {
|
||||||
return await fetch(`${HOST}/etapi/${url}`, {
|
return await fetch(`${HOST}/etapi/${url}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -172,6 +202,9 @@ function checkStatus(response) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
describeEtapi,
|
describeEtapi,
|
||||||
|
createTextNote,
|
||||||
|
createLabel,
|
||||||
|
getCurrentTestRootNote: () => currentTestRootNote,
|
||||||
getEtapi,
|
getEtapi,
|
||||||
getEtapiResponse,
|
getEtapiResponse,
|
||||||
getEtapiContent,
|
getEtapiContent,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user