fix tests ugh
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m59s

This commit is contained in:
2025-12-09 17:06:43 -08:00
parent 3a66f31d55
commit 6354189d5c
10 changed files with 473 additions and 314 deletions

View File

@@ -174,6 +174,30 @@ describe('User DB Service', () => {
});
});
describe('findUserWithProfileByEmail', () => {
it('should query for a user and their profile by email', async () => {
const mockUserWithProfile = { user_id: '123', email: 'test@example.com', full_name: 'Test User', role: 'user' };
mockPoolInstance.query.mockResolvedValue({ rows: [mockUserWithProfile] });
const result = await userRepo.findUserWithProfileByEmail('test@example.com');
expect(mockPoolInstance.query).toHaveBeenCalledWith(expect.stringContaining('JOIN public.profiles'), ['test@example.com']);
expect(result).toEqual(mockUserWithProfile);
});
it('should return undefined if user is not found', async () => {
mockPoolInstance.query.mockResolvedValue({ rows: [] });
const result = await userRepo.findUserWithProfileByEmail('notfound@example.com');
expect(result).toBeUndefined();
});
it('should throw a generic error if the database query fails', async () => {
const dbError = new Error('DB Connection Error');
mockPoolInstance.query.mockRejectedValue(dbError);
await expect(userRepo.findUserWithProfileByEmail('test@example.com')).rejects.toThrow('Failed to retrieve user with profile from database.');
});
});
describe('findUserById', () => {
it('should query for a user by their ID', async () => {
mockPoolInstance.query.mockResolvedValue({ rows: [{ user_id: '123' }] });