import { describe, it, expect, vi, beforeEach } from 'vitest'; import { userService } from './userService'; describe('userService', () => { beforeEach(() => { vi.clearAllMocks(); }); describe('getProfile', () => { it('should return user profile by id', async () => { const result = await userService.getProfile('u1'); expect(result).toBeDefined(); expect(result).toHaveProperty('profile'); expect(result.profile).toHaveProperty('id'); expect(result.profile).toHaveProperty('username'); expect(result.profile).toHaveProperty('email'); }); }); describe('getProfileByUsername', () => { it('should return user profile by username', async () => { const result = await userService.getProfileByUsername('testuser'); expect(result).toBeDefined(); expect(result).toHaveProperty('profile'); expect(result.profile).toHaveProperty('username'); expect(result.profile.username).toBe('testuser'); }); }); describe('updateProfile', () => { it('should update user profile', async () => { const result = await userService.updateProfile('u1', { firstName: 'Updated', lastName: 'Name', }); expect(result).toBeDefined(); expect(result).toHaveProperty('profile'); expect(result.profile.firstName).toBe('Updated'); expect(result.profile.lastName).toBe('Name'); }); }); describe('getProfileCompletion', () => { it('should return profile completion data', async () => { const result = await userService.getProfileCompletion('u1'); expect(result).toBeDefined(); expect(result).toHaveProperty('completion_percentage'); expect(result).toHaveProperty('missing_fields'); expect(typeof result.completion_percentage).toBe('number'); expect(Array.isArray(result.missing_fields)).toBe(true); }); }); });