2026-01-07 09:33:52 +00:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
import { userService } from './userService';
|
chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 18:39:18 +00:00
|
|
|
import { apiClient } from '@/services/api/client';
|
|
|
|
|
|
|
|
|
|
// Mock apiClient
|
|
|
|
|
vi.mock('@/services/api/client', () => ({
|
|
|
|
|
apiClient: {
|
|
|
|
|
get: vi.fn(),
|
|
|
|
|
put: vi.fn(),
|
|
|
|
|
delete: vi.fn(),
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const mockedApiClient = apiClient as {
|
|
|
|
|
get: ReturnType<typeof vi.fn>;
|
|
|
|
|
put: ReturnType<typeof vi.fn>;
|
|
|
|
|
};
|
2026-01-07 09:33:52 +00:00
|
|
|
|
|
|
|
|
describe('userService', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getProfile', () => {
|
|
|
|
|
it('should return user profile by id', async () => {
|
chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 18:39:18 +00:00
|
|
|
mockedApiClient.get.mockResolvedValue({
|
|
|
|
|
data: {
|
|
|
|
|
id: 'u1',
|
|
|
|
|
username: 'testuser',
|
|
|
|
|
email: 'test@example.com',
|
|
|
|
|
first_name: 'Test',
|
|
|
|
|
last_name: 'User',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
const result = await userService.getProfile('u1');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
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 () => {
|
chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 18:39:18 +00:00
|
|
|
mockedApiClient.get.mockResolvedValue({
|
|
|
|
|
data: {
|
|
|
|
|
id: 'u1',
|
|
|
|
|
username: 'testuser',
|
|
|
|
|
email: 'test@example.com',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
const result = await userService.getProfileByUsername('testuser');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
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 () => {
|
chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 18:39:18 +00:00
|
|
|
mockedApiClient.put.mockResolvedValue({
|
|
|
|
|
data: {
|
|
|
|
|
id: 'u1',
|
|
|
|
|
username: 'testuser',
|
|
|
|
|
first_name: 'Updated',
|
|
|
|
|
last_name: 'Name',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
const result = await userService.updateProfile('u1', {
|
chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 18:39:18 +00:00
|
|
|
first_name: 'Updated',
|
|
|
|
|
last_name: 'Name',
|
2026-01-07 09:33:52 +00:00
|
|
|
});
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(result).toBeDefined();
|
|
|
|
|
expect(result).toHaveProperty('profile');
|
chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 18:39:18 +00:00
|
|
|
expect(result.profile.first_name).toBe('Updated');
|
|
|
|
|
expect(result.profile.last_name).toBe('Name');
|
2026-01-07 09:33:52 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getProfileCompletion', () => {
|
|
|
|
|
it('should return profile completion data', async () => {
|
chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 18:39:18 +00:00
|
|
|
mockedApiClient.get.mockResolvedValue({
|
|
|
|
|
data: {
|
|
|
|
|
completion_percentage: 80,
|
|
|
|
|
missing_fields: ['bio', 'location'],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
const result = await userService.getProfileCompletion('u1');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|