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:
@ -1,7 +1,7 @@
|
||||
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||
import TestServer from "fetch-test-server";
|
||||
import app from "../app";
|
||||
import { Authentication } from "../models";
|
||||
import { Authentication, SearchQuery } from "../models";
|
||||
import * as Slack from "../slack";
|
||||
import { buildDocument } from "../test/factories";
|
||||
import { flushdb, seed } from "../test/support";
|
||||
@ -132,6 +132,30 @@ describe("#hooks.slack", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("should save search term, hits and source", async (done) => {
|
||||
const { user, team } = await seed();
|
||||
await server.post("/api/hooks.slack", {
|
||||
body: {
|
||||
token: process.env.SLACK_VERIFICATION_TOKEN,
|
||||
user_id: user.serviceId,
|
||||
team_id: team.slackId,
|
||||
text: "contains",
|
||||
},
|
||||
});
|
||||
|
||||
// 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: "contains" },
|
||||
});
|
||||
expect(searchQuery.length).toBe(1);
|
||||
expect(searchQuery[0].results).toBe(0);
|
||||
expect(searchQuery[0].source).toBe("slack");
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it("should respond with help content for help keyword", async () => {
|
||||
const { user, team } = await seed();
|
||||
const res = await server.post("/api/hooks.slack", {
|
||||
|
Reference in New Issue
Block a user