Files
outline/server/models/Integration.test.ts
Tom MoorandClaude Opus 5.5 f9d995e6f1 perf: Add cached Integration.findEnabledByTeamIdAndService lookup (#14635)
* perf: Add cached Integration.findEnabledByTeamIdAndService lookup

Caches a lightweight projection of a team's integrations for a service in
Redis so event processors can cheaply check whether a team uses a service,
e.g. from shouldQueue, before creating a job. The cache is invalidated after
commit by model lifecycle hooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: Remove comment from Integration cache invalidation

* perf: Skip queueing Slack jobs for teams without a matching post integration

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 08:20:15 -05:00

84 lines
2.5 KiB
TypeScript

import { IntegrationService, IntegrationType } from "@shared/types";
import { sequelize } from "@server/storage/database";
import { buildIntegration, buildTeam } from "@server/test/factories";
import Integration from "./Integration";
describe("Integration", () => {
describe("findEnabledByTeamIdAndService", () => {
it("returns only integrations for the team and service", async () => {
const integration = await buildIntegration({
service: IntegrationService.GitHub,
type: IntegrationType.Post,
});
await buildIntegration({ teamId: integration.teamId });
await buildIntegration({ service: IntegrationService.GitHub });
const result = await Integration.findEnabledByTeamIdAndService(
integration.teamId,
IntegrationService.GitHub
);
expect(result).toEqual([
{
id: integration.id,
type: IntegrationType.Post,
collectionId: null,
events: integration.events,
},
]);
});
it("returns an empty array when the team has no integrations", async () => {
const team = await buildTeam();
const result = await Integration.findEnabledByTeamIdAndService(
team.id,
IntegrationService.GitHub
);
expect(result).toEqual([]);
});
it("reflects an integration created after the cache is primed", async () => {
const team = await buildTeam();
const before = await Integration.findEnabledByTeamIdAndService(
team.id,
IntegrationService.GitHub
);
expect(before).toHaveLength(0);
await sequelize.transaction(async (transaction) => {
await Integration.create(
{ teamId: team.id, service: IntegrationService.GitHub },
{ transaction }
);
});
const after = await Integration.findEnabledByTeamIdAndService(
team.id,
IntegrationService.GitHub
);
expect(after).toHaveLength(1);
});
it("reflects changes after an integration is destroyed and restored", async () => {
const integration = await buildIntegration({
service: IntegrationService.GitHub,
});
const find = () =>
Integration.findEnabledByTeamIdAndService(
integration.teamId,
IntegrationService.GitHub
);
expect(await find()).toHaveLength(1);
await integration.destroy();
expect(await find()).toHaveLength(0);
await integration.restore();
expect(await find()).toHaveLength(1);
});
});
});