fix: Match search requests from Slack using Integration for non-Slack teams (#1599)

* Match slack hook requests to integration
This commit is contained in:
Tom Moor
2020-10-21 08:53:38 -07:00
committed by GitHub
parent 15337b5bdf
commit b78e2f1e05
4 changed files with 120 additions and 13 deletions

View File

@ -3,7 +3,7 @@ import TestServer from "fetch-test-server";
import app from "../app";
import { Authentication, SearchQuery } from "../models";
import * as Slack from "../slack";
import { buildDocument } from "../test/factories";
import { buildDocument, buildIntegration } from "../test/factories";
import { flushdb, seed } from "../test/support";
const server = new TestServer(app.callback());
@ -212,6 +212,41 @@ describe("#hooks.slack", () => {
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.text).toContain("you havent signed in to Outline yet");
expect(body.attachments.length).toEqual(1);
expect(body.attachments[0].title).toEqual(document.title);
expect(body.attachments[0].text).toEqual(
"This title *contains* a search term"
);
});
it("should return search results with snippet for user through integration mapping", async () => {
const { user } = await seed();
const serviceTeamId = "slack_team_id";
await buildIntegration({
teamId: user.teamId,
settings: {
serviceTeamId,
},
});
const document = await buildDocument({
text: "This title contains a search term",
userId: user.id,
teamId: user.teamId,
});
const res = await server.post("/api/hooks.slack", {
body: {
token: process.env.SLACK_VERIFICATION_TOKEN,
user_id: "unknown-slack-user-id",
team_id: serviceTeamId,
text: "contains",
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.text).toContain("you havent signed in to Outline yet");
expect(body.attachments.length).toEqual(1);
expect(body.attachments[0].title).toEqual(document.title);
expect(body.attachments[0].text).toEqual(