Compare commits

..

1 Commits

Author SHA1 Message Date
846c80f430 feat(api): invalidate sessions on user deactivation (MS21-AUTH-004)
Some checks failed
ci/woodpecker/push/api Pipeline failed
2026-02-28 17:29:37 -06:00

View File

@@ -24,15 +24,7 @@ describe("AdminService", () => {
workspaceMember: { workspaceMember: {
create: vi.fn(), create: vi.fn(),
}, },
session: { $transaction: vi.fn(),
deleteMany: vi.fn(),
},
$transaction: vi.fn(async (ops) => {
if (typeof ops === "function") {
return ops(mockPrismaService);
}
return Promise.all(ops);
}),
}; };
const mockAdminId = "550e8400-e29b-41d4-a716-446655440001"; const mockAdminId = "550e8400-e29b-41d4-a716-446655440001";
@@ -90,6 +82,10 @@ describe("AdminService", () => {
service = module.get<AdminService>(AdminService); service = module.get<AdminService>(AdminService);
vi.clearAllMocks(); vi.clearAllMocks();
mockPrismaService.$transaction.mockImplementation(async (fn: (tx: unknown) => unknown) => {
return fn(mockPrismaService);
});
}); });
it("should be defined", () => { it("should be defined", () => {
@@ -329,13 +325,12 @@ describe("AdminService", () => {
}); });
describe("deactivateUser", () => { describe("deactivateUser", () => {
it("should set deactivatedAt and invalidate sessions", async () => { it("should set deactivatedAt on the user", async () => {
mockPrismaService.user.findUnique.mockResolvedValue(mockUser); mockPrismaService.user.findUnique.mockResolvedValue(mockUser);
mockPrismaService.user.update.mockResolvedValue({ mockPrismaService.user.update.mockResolvedValue({
...mockUser, ...mockUser,
deactivatedAt: new Date(), deactivatedAt: new Date(),
}); });
mockPrismaService.session.deleteMany.mockResolvedValue({ count: 3 });
const result = await service.deactivateUser(mockUserId); const result = await service.deactivateUser(mockUserId);
@@ -346,7 +341,6 @@ describe("AdminService", () => {
data: { deactivatedAt: expect.any(Date) }, data: { deactivatedAt: expect.any(Date) },
}) })
); );
expect(mockPrismaService.session.deleteMany).toHaveBeenCalledWith({ where: { userId: mockUserId } });
}); });
it("should throw NotFoundException if user does not exist", async () => { it("should throw NotFoundException if user does not exist", async () => {