Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Oct 31, 2023
1 parent 7d80fe1 commit 0efc420
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"scripts": {
"start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"qstart-server": "rm -r ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-server-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"start-electron": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .",
"start-electron-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .",
"qstart-electron": "rm -r ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-desktop-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .",
"start-test-server": "rm -rf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 node ./src/www",
"qstart-electron": "npm run qswitch-electron && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .",
"start-test-server": "npm run qswitch-server; rm -rf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 node ./src/www",
"switch-server": "rm -rf ./node_modules/better-sqlite3 && npm install",
"switch-electron": "./node_modules/.bin/electron-rebuild",
"qswitch-server": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-server-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node",
"qswitch-electron": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-desktop-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node",
"build-backend-docs": "rm -rf ./docs/backend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/backend_api src/becca/entities/*.js src/services/backend_script_api.js src/services/sql.js",
"build-frontend-docs": "rm -rf ./docs/frontend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/frontend_api src/public/app/entities/*.js src/public/app/services/frontend_script_api.js src/public/app/widgets/basic_widget.js src/public/app/widgets/note_context_aware_widget.js src/public/app/widgets/right_panel_widget.js",
"build-docs": "npm run build-backend-docs && npm run build-frontend-docs",
Expand Down
12 changes: 12 additions & 0 deletions spec/etapi/app_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {
describeEtapi, postEtapi,
putEtapiContent
} = require("../support/etapi");
const {getEtapi} = require("../support/etapi.js");

describeEtapi("app_info", () => {
it("get", async () => {
const appInfo = await getEtapi("app-info");
expect(appInfo.clipperProtocolVersion).toEqual("1.0");
});
});
12 changes: 12 additions & 0 deletions spec/etapi/backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {
describeEtapi, postEtapi,
getEtapi,
} = require("../support/etapi");
const {putEtapiContent} = require("../support/etapi.js");

describeEtapi("backup", () => {
it("create", async () => {
const response = await putEtapiContent("backup/etapi_test");
expect(response.status).toEqual(204);
});
});
24 changes: 24 additions & 0 deletions spec/etapi/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const {
describeEtapi, postEtapi,
postEtapiContent,
} = require("../support/etapi");
const fs = require("fs");
const path = require("path");
const {getEtapiContent} = require("../support/etapi.js");

describeEtapi("import", () => {
it("import", async () => {
const zipFileBuffer = fs.readFileSync(path.resolve(__dirname, 'test-export.zip'));

const response = await postEtapiContent("notes/root/import", zipFileBuffer);
expect(response.status).toEqual(201);

const {note, branch} = await response.json();

expect(note.title).toEqual("test-export");
expect(branch.parentNoteId).toEqual("root");

const content = await (await getEtapiContent(`notes/${note.noteId}/content`)).text();
expect(content).toContain("test export content");
});
});
11 changes: 9 additions & 2 deletions spec/etapi/notes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const {describeEtapi, postEtapi, getEtapi, getEtapiContent, patchEtapi, putEtapi, putEtapiContent} = require("../support/etapi");
const crypto = require('crypto');
const {deleteEtapi, getEtapiResponse} = require("../support/etapi.js");
const {
deleteEtapi,
getEtapiResponse,
describeEtapi, postEtapi,
getEtapi,
getEtapiContent,
patchEtapi, putEtapi,
putEtapiContent
} = require("../support/etapi");

describeEtapi("notes", () => {
it("create", async () => {
Expand Down
18 changes: 18 additions & 0 deletions spec/support/etapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ async function postEtapi(url, data = {}) {
return await processEtapiResponse(response);
}

async function postEtapiContent(url, data) {
const response = await fetch(`${HOST}/etapi/${url}`, {
method: 'POST',
headers: {
"Content-Type": "application/octet-stream",
Authorization: getEtapiAuthorizationHeader()
},
body: data
});

checkStatus(response);

return response;
}

async function putEtapi(url, data = {}) {
const response = await fetch(`${HOST}/etapi/${url}`, {
method: 'PUT',
Expand All @@ -113,6 +128,8 @@ async function putEtapiContent(url, data) {
});

checkStatus(response);

return response;
}

async function patchEtapi(url, data = {}) {
Expand Down Expand Up @@ -159,6 +176,7 @@ module.exports = {
getEtapiResponse,
getEtapiContent,
postEtapi,
postEtapiContent,
putEtapi,
putEtapiContent,
patchEtapi,
Expand Down

0 comments on commit 0efc420

Please sign in to comment.