From 37706f61c425f18867cf4508cadb441677d43e48 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 29 Aug 2026 00:53:35 +0100 Subject: [PATCH] Add mock implementations for permissions module in user API tests This commit introduces mock functions for the `permissions` module in the user API test file, enhancing test isolation and allowing for comprehensive testing of permission-related functionalities. The new mocks include methods for checking permissions, managing user permissions cache, and resolving permission settings, improving the overall test coverage and reliability of the user API tests. --- src/__tests__/users.api.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/__tests__/users.api.test.js b/src/__tests__/users.api.test.js index 6fc18a0..d91b097 100644 --- a/src/__tests__/users.api.test.js +++ b/src/__tests__/users.api.test.js @@ -13,6 +13,18 @@ jest.unstable_mockModule('../keycloak.js', () => ({ expressSession: (req, res, next) => next(), })); +jest.unstable_mockModule('../database/permissions.js', () => ({ + checkPermissions: () => (req, res, next) => next(), + hasPermission: jest.fn(async () => true), + getUserPermissionsCacheKey: jest.fn((userId) => `permissions:${userId}`), + saveUserPermissionsToRedis: jest.fn(), + applyPermissionSettingsList: jest.fn(() => ({})), + getPermissionSettingsId: jest.fn(), + excludeIdFromList: jest.fn((items = []) => items), + resolveReferencedDocs: jest.fn(async () => []), + resolvePermissionSettings: jest.fn(async () => []), +})); + // Mock database connections and initializations in index.js jest.unstable_mockModule('../database/mongo.js', () => ({ dbConnect: jest.fn(),