feat: Record search queries (#1554)
* Record search queries * feat: add totalCount to the search response * feat: add comments to explain why we use setTimeout
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
Revision,
|
||||
Backlink,
|
||||
CollectionUser,
|
||||
SearchQuery,
|
||||
} from "../models";
|
||||
import {
|
||||
buildShare,
|
||||
@@ -954,6 +955,25 @@ describe("#documents.search", () => {
|
||||
expect(res.status).toEqual(401);
|
||||
expect(body).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("should save search term, hits and source", async (done) => {
|
||||
const { user } = await seed();
|
||||
await server.post("/api/documents.search", {
|
||||
body: { token: user.getJwtToken(), query: "my term" },
|
||||
});
|
||||
|
||||
// setTimeout is needed here because SearchQuery is saved asynchronously
|
||||
// in order to not slow down the response time.
|
||||
setTimeout(async () => {
|
||||
const searchQuery = await SearchQuery.findAll({
|
||||
where: { query: "my term" },
|
||||
});
|
||||
expect(searchQuery.length).toBe(1);
|
||||
expect(searchQuery[0].results).toBe(0);
|
||||
expect(searchQuery[0].source).toBe("app");
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#documents.archived", () => {
|
||||
|
||||
Reference in New Issue
Block a user