Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(etapi): port search
Elian Doran95641a3b6db7
diff --git a/_regroup/test-etapi/search.http b/_regroup/test-etapi/search.httpdeleted file mode 100644index 4655f22e05..0000000000--- a/_regroup/test-etapi/search.http+++ /dev/null@@ -1,39 +0,0 @@-POST {{triliumHost}}/etapi/create-note-Authorization: {{authToken}}-Content-Type: application/json--{- "parentNoteId": "root",- "title": "title",- "type": "text",- "content": "{{$uuid}}"-}--> {% client.global.set("createdNoteId", response.body.note.noteId); %}--###--GET {{triliumHost}}/etapi/notes/{{createdNoteId}}/content-Authorization: {{authToken}}--> {% client.global.set("content", response.body); %}--###--GET {{triliumHost}}/etapi/notes?search={{content}}&debug=true-Authorization: {{authToken}}--> {%-client.assert(response.status === 200);-client.assert(response.body.results.length === 1);-%}--### Same but with fast search which doesn't look in the content so 0 notes should be found--GET {{triliumHost}}/etapi/notes?search={{content}}&fastSearch=true-Authorization: {{authToken}}--> {%-client.assert(response.status === 200);-client.assert(response.body.results.length === 0);-%}diff --git a/apps/server/spec/etapi/search.spec.ts b/apps/server/spec/etapi/search.spec.tsnew file mode 100644index 0000000000..bfd14e7400--- /dev/null+++ b/apps/server/spec/etapi/search.spec.ts@@ -0,0 +1,40 @@+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";+import { randomUUID } from "crypto";++let app: Application;+let token: string;++const USER = "etapi";+let content: string;++describe("etapi/search", () => {+ beforeAll(async () => {+ config.General.noAuthentication = false;+ const buildApp = (await (import("../../src/app.js"))).default;+ app = await buildApp();+ token = await login(app);++ content = randomUUID();+ await createNote(app, token, content);+ });++ it("finds by content", async () => {+ const response = await supertest(app)+ .get(`/etapi/notes?search=${content}&debug=true`)+ .auth(USER, token, { "type": "basic"})+ .expect(200);+ expect(response.body.results).toHaveLength(1);+ });++ it("does not find by content when fast search is on", async () => {+ const response = await supertest(app)+ .get(`/etapi/notes?search=${content}&debug=true&fastSearch=true`)+ .auth(USER, token, { "type": "basic"})+ .expect(200);+ expect(response.body.results).toHaveLength(0);+ });+});diff --git a/apps/server/spec/etapi/utils.ts b/apps/server/spec/etapi/utils.tsindex f9657eeab6..5096983701 100644--- a/apps/server/spec/etapi/utils.ts+++ b/apps/server/spec/etapi/utils.ts@@ -14,3 +14,20 @@ export async function login(app: Application) {expect(token).toBeTruthy();return token;}++export async function createNote(app: Application, token: string, content?: string) {+ const response = await supertest(app)+ .post("/etapi/create-note")+ .auth("etapi", token, { "type": "basic"})+ .send({+ "parentNoteId": "root",+ "title": "Hello",+ "type": "text",+ "content": content ?? "Hi there!",+ })+ .expect(201);++ const noteId = response.body.note.noteId;+ expect(noteId).toStrictEqual(noteId);+ return noteId;+}