mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
test(etapi): port search
This commit is contained in:
parent
4e81be8c76
commit
95641a3b6d
@ -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);
|
|
||||||
%}
|
|
40
apps/server/spec/etapi/search.spec.ts
Normal file
40
apps/server/spec/etapi/search.spec.ts
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
@ -14,3 +14,20 @@ export async function login(app: Application) {
|
|||||||
expect(token).toBeTruthy();
|
expect(token).toBeTruthy();
|
||||||
return token;
|
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;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user