large mock refector hopefully done + no errors?
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h19m21s

This commit is contained in:
2025-12-21 12:38:53 -08:00
parent 9d5fea19b2
commit 0cf4ca02b7
25 changed files with 156 additions and 120 deletions

View File

@@ -8,7 +8,7 @@ import { RecipeRepository } from './recipe.db';
vi.unmock('./recipe.db'); // This line is correct.
const mockQuery = mockPoolInstance.query;
import type { Recipe, FavoriteRecipe, RecipeComment } from '../../types';
import type { FavoriteRecipe, RecipeComment } from '../../types';
import { createMockRecipe } from '../../tests/utils/mockFactories';
// Mock the logger to prevent console output during tests. This is a server-side DB test.

View File

@@ -127,17 +127,48 @@ export class UserRepository {
* @param email The email of the user to find.
* @returns A promise that resolves to the combined user and profile object or undefined if not found.
*/
async findUserWithProfileByEmail(email: string, logger: Logger): Promise<(DbUser & Profile) | undefined> {
async findUserWithProfileByEmail(email: string, logger: Logger): Promise<(UserProfile & DbUser) | undefined> {
logger.debug({ email }, `[DB findUserWithProfileByEmail] Searching for user.`);
try {
const query = `
SELECT u.*, p.full_name, p.avatar_url, p.role, p.points, p.preferences, p.address_id
SELECT
u.user_id, u.email, u.password_hash, u.refresh_token, u.failed_login_attempts, u.last_failed_login,
p.full_name, p.avatar_url, p.role, p.points, p.preferences, p.address_id,
p.created_at, p.updated_at
FROM public.users u
JOIN public.profiles p ON u.user_id = p.user_id
WHERE u.email = $1;
`;
const res = await this.db.query<(DbUser & Profile)>(query, [email]);
return res.rows[0];
const res = await this.db.query<any>(query, [email]);
const flatUser = res.rows[0];
if (!flatUser) {
return undefined;
}
// Manually construct the nested UserProfile object and add auth fields
const authableProfile: UserProfile & DbUser = {
user_id: flatUser.user_id,
full_name: flatUser.full_name,
avatar_url: flatUser.avatar_url,
role: flatUser.role,
points: flatUser.points,
preferences: flatUser.preferences,
address_id: flatUser.address_id,
created_at: flatUser.created_at,
updated_at: flatUser.updated_at,
user: {
user_id: flatUser.user_id,
email: flatUser.email,
},
email: flatUser.email,
password_hash: flatUser.password_hash,
failed_login_attempts: flatUser.failed_login_attempts,
last_failed_login: flatUser.last_failed_login,
refresh_token: flatUser.refresh_token,
};
return authableProfile;
} catch (error) {
logger.error({ err: error, email }, 'Database error in findUserWithProfileByEmail');
throw new Error('Failed to retrieve user with profile from database.');