From 50b0dc178e6c75ccdb84f604418dfa673a048dcd Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 6 Dec 2025 09:27:56 +0200 Subject: [PATCH] chore(regroup): clean up old ETAPI tests They are already integrated in apps/server/spec/etapi. --- _regroup/spec/etapi/app_info.ts | 9 -- _regroup/spec/etapi/backup.ts | 10 --- _regroup/spec/etapi/import.ts | 26 ------ _regroup/spec/etapi/notes.ts | 103 ---------------------- _regroup/spec/support/etapi.ts | 152 -------------------------------- 5 files changed, 300 deletions(-) delete mode 100644 _regroup/spec/etapi/app_info.ts delete mode 100644 _regroup/spec/etapi/backup.ts delete mode 100644 _regroup/spec/etapi/import.ts delete mode 100644 _regroup/spec/etapi/notes.ts delete mode 100644 _regroup/spec/support/etapi.ts diff --git a/_regroup/spec/etapi/app_info.ts b/_regroup/spec/etapi/app_info.ts deleted file mode 100644 index 9c510d99b..000000000 --- a/_regroup/spec/etapi/app_info.ts +++ /dev/null @@ -1,9 +0,0 @@ -import etapi from "../support/etapi.js"; -/* TriliumNextTODO: port to Vitest -etapi.describeEtapi("app_info", () => { - it("get", async () => { - const appInfo = await etapi.getEtapi("app-info"); - expect(appInfo.clipperProtocolVersion).toEqual("1.0"); - }); -}); -*/ diff --git a/_regroup/spec/etapi/backup.ts b/_regroup/spec/etapi/backup.ts deleted file mode 100644 index 924213f0e..000000000 --- a/_regroup/spec/etapi/backup.ts +++ /dev/null @@ -1,10 +0,0 @@ -import etapi from "../support/etapi.js"; - -/* TriliumNextTODO: port to Vitest -etapi.describeEtapi("backup", () => { - it("create", async () => { - const response = await etapi.putEtapiContent("backup/etapi_test"); - expect(response.status).toEqual(204); - }); -}); -*/ diff --git a/_regroup/spec/etapi/import.ts b/_regroup/spec/etapi/import.ts deleted file mode 100644 index 36782a26a..000000000 --- a/_regroup/spec/etapi/import.ts +++ /dev/null @@ -1,26 +0,0 @@ -import etapi from "../support/etapi.js"; -import fs from "fs"; -import path from "path"; -import { fileURLToPath } from "url"; - -/* TriliumNextTODO: port to Vitest -etapi.describeEtapi("import", () => { - // temporarily skip this test since test-export.zip is missing - xit("import", async () => { - const scriptDir = path.dirname(fileURLToPath(import.meta.url)); - - const zipFileBuffer = fs.readFileSync(path.resolve(scriptDir, "test-export.zip")); - - const response = await etapi.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 etapi.getEtapiContent(`notes/${note.noteId}/content`)).text(); - expect(content).toContain("test export content"); - }); -}); -*/ diff --git a/_regroup/spec/etapi/notes.ts b/_regroup/spec/etapi/notes.ts deleted file mode 100644 index d5c9b680c..000000000 --- a/_regroup/spec/etapi/notes.ts +++ /dev/null @@ -1,103 +0,0 @@ -import crypto from "crypto"; -import etapi from "../support/etapi.js"; - -/* TriliumNextTODO: port to Vitest -etapi.describeEtapi("notes", () => { - it("create", async () => { - const { note, branch } = await etapi.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 etapi.getEtapi(`notes/${note.noteId}`); - expect(rNote.title).toEqual("Hello World!"); - - const rContent = await (await etapi.getEtapiContent(`notes/${note.noteId}/content`)).text(); - expect(rContent).toEqual("Content"); - - const rBranch = await etapi.getEtapi(`branches/${branch.branchId}`); - expect(rBranch.parentNoteId).toEqual("root"); - expect(rBranch.prefix).toEqual("Custom prefix"); - }); - - it("patch", async () => { - const { note } = await etapi.postEtapi("create-note", { - parentNoteId: "root", - type: "text", - title: "Hello World!", - content: "Content" - }); - - await etapi.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 etapi.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 etapi.postEtapi("create-note", { - parentNoteId: "root", - type: "text", - title: "Hello World!", - content: "Content" - }); - - await etapi.putEtapiContent(`notes/${note.noteId}/content`, "new content"); - - const rContent = await (await etapi.getEtapiContent(`notes/${note.noteId}/content`)).text(); - expect(rContent).toEqual("new content"); - }); - - it("create / update binary content", async () => { - const { note } = await etapi.postEtapi("create-note", { - parentNoteId: "root", - type: "file", - title: "Hello World!", - content: "ZZZ" - }); - - const updatedContent = crypto.randomBytes(16); - - await etapi.putEtapiContent(`notes/${note.noteId}/content`, updatedContent); - - const rContent = await (await etapi.getEtapiContent(`notes/${note.noteId}/content`)).arrayBuffer(); - expect(Buffer.from(new Uint8Array(rContent))).toEqual(updatedContent); - }); - - it("delete note", async () => { - const { note } = await etapi.postEtapi("create-note", { - parentNoteId: "root", - type: "text", - title: "Hello World!", - content: "Content" - }); - - await etapi.deleteEtapi(`notes/${note.noteId}`); - - const resp = await etapi.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.`); - }); -}); -*/ diff --git a/_regroup/spec/support/etapi.ts b/_regroup/spec/support/etapi.ts deleted file mode 100644 index b32ba38e7..000000000 --- a/_regroup/spec/support/etapi.ts +++ /dev/null @@ -1,152 +0,0 @@ -import { describe, beforeAll, afterAll } from "vitest"; - -let etapiAuthToken: string | undefined; - -const getEtapiAuthorizationHeader = (): string => "Basic " + Buffer.from(`etapi:${etapiAuthToken}`).toString("base64"); - -const PORT: string = "9999"; -const HOST: string = "http://localhost:" + PORT; - -type SpecDefinitionsFunc = () => void; - -function describeEtapi(description: string, specDefinitions: SpecDefinitionsFunc): void { - describe(description, () => { - beforeAll(async () => {}); - - afterAll(() => {}); - - specDefinitions(); - }); -} - -async function getEtapiResponse(url: string): Promise { - return await fetch(`${HOST}/etapi/${url}`, { - method: "GET", - headers: { - Authorization: getEtapiAuthorizationHeader() - } - }); -} - -async function getEtapi(url: string): Promise { - const response = await getEtapiResponse(url); - return await processEtapiResponse(response); -} - -async function getEtapiContent(url: string): Promise { - const response = await fetch(`${HOST}/etapi/${url}`, { - method: "GET", - headers: { - Authorization: getEtapiAuthorizationHeader() - } - }); - - checkStatus(response); - - return response; -} - -async function postEtapi(url: string, data: Record = {}): Promise { - const response = await fetch(`${HOST}/etapi/${url}`, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: getEtapiAuthorizationHeader() - }, - body: JSON.stringify(data) - }); - return await processEtapiResponse(response); -} - -async function postEtapiContent(url: string, data: BodyInit): Promise { - 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: string, data: Record = {}): Promise { - const response = await fetch(`${HOST}/etapi/${url}`, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: getEtapiAuthorizationHeader() - }, - body: JSON.stringify(data) - }); - return await processEtapiResponse(response); -} - -async function putEtapiContent(url: string, data?: BodyInit): Promise { - const response = await fetch(`${HOST}/etapi/${url}`, { - method: "PUT", - headers: { - "Content-Type": "application/octet-stream", - Authorization: getEtapiAuthorizationHeader() - }, - body: data - }); - - checkStatus(response); - - return response; -} - -async function patchEtapi(url: string, data: Record = {}): Promise { - const response = await fetch(`${HOST}/etapi/${url}`, { - method: "PATCH", - headers: { - "Content-Type": "application/json", - Authorization: getEtapiAuthorizationHeader() - }, - body: JSON.stringify(data) - }); - return await processEtapiResponse(response); -} - -async function deleteEtapi(url: string): Promise { - const response = await fetch(`${HOST}/etapi/${url}`, { - method: "DELETE", - headers: { - Authorization: getEtapiAuthorizationHeader() - } - }); - return await processEtapiResponse(response); -} - -async function processEtapiResponse(response: Response): Promise { - const text = await response.text(); - - if (response.status < 200 || response.status >= 300) { - throw new Error(`ETAPI error ${response.status}: ${text}`); - } - - return text?.trim() ? JSON.parse(text) : null; -} - -function checkStatus(response: Response): void { - if (response.status < 200 || response.status >= 300) { - throw new Error(`ETAPI error ${response.status}`); - } -} - -export default { - describeEtapi, - getEtapi, - getEtapiResponse, - getEtapiContent, - postEtapi, - postEtapiContent, - putEtapi, - putEtapiContent, - patchEtapi, - deleteEtapi -};