chore: More flakey test improvements (#5801)

This commit is contained in:
Tom Moor
2023-09-09 18:30:19 -04:00
committed by GitHub
parent 7270e65f0c
commit 80ef0a38d6
37 changed files with 245 additions and 210 deletions

View File

@@ -1,3 +1,4 @@
import randomstring from "randomstring";
import { IntegrationService } from "@shared/types";
import env from "@server/env";
import { IntegrationAuthentication, SearchQuery } from "@server/models";
@@ -17,7 +18,7 @@ jest.mock("../slack", () => ({
const server = getTestServer();
describe("#hooks.unfurl", () => {
it("should return documents", async () => {
it("should return documents with matching SSO user", async () => {
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
@@ -28,18 +29,19 @@ describe("#hooks.unfurl", () => {
service: IntegrationService.Slack,
userId: user.id,
teamId: user.teamId,
token: "",
token: randomstring.generate(32),
});
const res = await server.post("/api/hooks.unfurl", {
body: {
token: env.SLACK_VERIFICATION_TOKEN,
team_id: "TXXXXXXXX",
api_app_id: "AXXXXXXXXX",
team_id: `T${randomstring.generate(8)}`,
api_app_id: `A${randomstring.generate(8)}`,
event: {
type: "link_shared",
channel: "Cxxxxxx",
channel: `C${randomstring.generate(8)}`,
user: user.authentications[0].providerId,
message_ts: "123456789.9875",
message_ts: randomstring.generate(12),
links: [
{
domain: "getoutline.com",

View File

@@ -70,20 +70,31 @@ router.post(
model: UserAuthentication,
as: "authentications",
required: true,
separate: true,
},
],
});
if (!user) {
Logger.debug("plugins", "No user found for Slack user ID", {
providerId: event.user,
});
return;
}
const auth = await IntegrationAuthentication.findOne({
where: {
service: IntegrationService.Slack,
teamId: user.teamId,
},
});
if (!auth) {
Logger.debug(
"plugins",
"No Slack integration authentication found for team",
{
teamId: user.teamId,
}
);
return;
}
// get content for unfurled links