Add mock implementations for permissions module in user API tests
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good

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.
This commit is contained in:
Tom Butcher 2026-08-29 00:53:35 +01:00
parent e98828bfc7
commit 37706f61c4

View File

@ -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(),