Refactor tests and improve error handling across various services
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 10m38s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 10m38s
- Updated `useAuth` tests to use async functions for JSON responses to avoid promise resolution issues. - Changed `AdminBrandManager` tests to use `mockImplementation` for consistent mock behavior. - Enhanced `ProfileManager.Authenticated` tests to ensure proper error handling and assertions for partial updates. - Modified `SystemCheck` tests to prevent memory leaks by using `mockImplementation` for API calls. - Improved error handling in `ai.routes.ts` by refining validation schemas and adding error extraction utility. - Updated `auth.routes.test.ts` to inject mock logger for better error tracking. - Refined `flyer.routes.ts` to ensure proper validation and error handling for flyer ID parameters. - Enhanced `admin.db.ts` to ensure specific errors are re-thrown for better error management. - Updated `budget.db.test.ts` to improve mock behavior and ensure accurate assertions. - Refined `flyer.db.ts` to improve error handling for race conditions during store creation. - Enhanced `notification.db.test.ts` to ensure specific error types are tested correctly. - Updated `recipe.db.test.ts` to ensure proper handling of not found errors. - Improved `user.db.ts` to ensure consistent error handling for user retrieval. - Enhanced `flyerProcessingService.server.test.ts` to ensure accurate assertions on transformed data. - Updated `logger.server.ts` to disable transport in test environments to prevent issues. - Refined `queueService.workers.test.ts` to ensure accurate mocking of email service. - Improved `userService.test.ts` to ensure proper mock implementations for repository classes. - Enhanced `checksum.test.ts` to ensure reliable file content creation in tests. - Updated `pdfConverter.test.ts` to reset shared state objects and mock implementations before each test.
This commit is contained in:
@@ -178,11 +178,12 @@ export class UserRepository {
|
||||
'SELECT user_id, email, password_hash FROM public.users WHERE user_id = $1',
|
||||
[userId]
|
||||
);
|
||||
if (res.rowCount === 0) {
|
||||
if ((res.rowCount ?? 0) === 0) {
|
||||
throw new NotFoundError(`User with ID ${userId} not found.`);
|
||||
}
|
||||
return res.rows[0];
|
||||
} catch (error) {
|
||||
if (error instanceof NotFoundError) throw error;
|
||||
logger.error({ err: error, userId }, 'Database error in findUserWithPasswordHashById');
|
||||
throw new Error('Failed to retrieve user with sensitive data by ID from database.');
|
||||
}
|
||||
@@ -366,7 +367,7 @@ export class UserRepository {
|
||||
'SELECT user_id, email FROM public.users WHERE refresh_token = $1',
|
||||
[refreshToken]
|
||||
);
|
||||
if (res.rowCount === 0) {
|
||||
if ((res.rowCount ?? 0) === 0) {
|
||||
throw new NotFoundError('User not found for the given refresh token.');
|
||||
}
|
||||
return res.rows[0];
|
||||
|
||||
Reference in New Issue
Block a user