Files
outline/server/queues/processors/WebsocketsProcessor.test.ts
T
Tom Moor d82617b086 perf: Batch lookups when a group is removed from a collection (#14903)
* perf: Batch user and membership lookups when a group is removed from a collection

* perf: Limit membership lookups to each batch of group users

* chore: Explain membership lookups in remove_group handler

* fix: Ignore deleted groups when checking remaining collection access
2026-12-04 22:16:35 -05:00

80 lines
2.3 KiB
TypeScript

import type { Server } from "socket.io";
import { CollectionPermission } from "@shared/types";
import { GroupMembership } from "@server/models";
import {
buildAdmin,
buildCollection,
buildGroup,
buildGroupUser,
buildUser,
} from "@server/test/factories";
import WebsocketsProcessor from "./WebsocketsProcessor";
describe("WebsocketsProcessor", () => {
const processor = new WebsocketsProcessor();
describe("collections.remove_group", () => {
const setup = async () => {
const admin = await buildAdmin();
const teamId = admin.teamId;
const collection = await buildCollection({
teamId,
userId: admin.id,
permission: null,
});
const removedGroup = await buildGroup({ teamId, userId: admin.id });
const otherGroup = await buildGroup({ teamId, userId: admin.id });
await GroupMembership.create({
groupId: otherGroup.id,
collectionId: collection.id,
createdById: admin.id,
permission: CollectionPermission.Read,
});
const user = await buildUser({ teamId });
await buildGroupUser({
groupId: removedGroup.id,
userId: user.id,
teamId,
});
await buildGroupUser({ groupId: otherGroup.id, userId: user.id, teamId });
const socketio = {
to: () => ({ emit: vi.fn() }),
in: vi.fn(() => ({ socketsLeave: vi.fn() })),
};
const perform = () =>
processor.perform(
{
name: "collections.remove_group",
teamId,
actorId: admin.id,
ip: null,
collectionId: collection.id,
modelId: removedGroup.id,
data: { membershipId: "membership-id" },
},
socketio as unknown as Server
);
return { otherGroup, user, socketio, perform };
};
it("should keep users with access through another group", async () => {
const { socketio, perform } = await setup();
await perform();
expect(socketio.in).not.toHaveBeenCalled();
});
it("should remove users whose other group was deleted", async () => {
const { otherGroup, user, socketio, perform } = await setup();
await otherGroup.destroy();
await perform();
expect(socketio.in).toHaveBeenCalledWith(`user-${user.id}`);
});
});
});