Add comprehensive unit tests for: - lib layer: config, device-fingerprint, errors, storage, hooks/useBreadcrumbs, http - services layer: devices, login-logs, operation-logs, permissions, profile, roles, settings, stats, import-export All 491 tests pass across 74 test files.
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const getMock = vi.fn()
|
|
|
|
vi.mock('@/lib/http/client', () => ({
|
|
get: getMock,
|
|
}))
|
|
|
|
describe('stats service', () => {
|
|
beforeEach(() => {
|
|
getMock.mockReset()
|
|
})
|
|
|
|
it('gets dashboard stats', async () => {
|
|
const mockStats = {
|
|
total_users: 100,
|
|
active_users: 75,
|
|
new_users_today: 5,
|
|
total_devices: 200,
|
|
trusted_devices: 150,
|
|
}
|
|
|
|
getMock.mockResolvedValue(mockStats)
|
|
|
|
const { getDashboardStats } = await import('./stats')
|
|
const result = await getDashboardStats()
|
|
|
|
expect(getMock).toHaveBeenCalledWith('/admin/stats/dashboard')
|
|
expect(result).toEqual(mockStats)
|
|
})
|
|
|
|
it('gets user stats', async () => {
|
|
const mockUserStats = {
|
|
total: 100,
|
|
active: 75,
|
|
inactive: 25,
|
|
verified: 80,
|
|
unverified: 20,
|
|
}
|
|
|
|
getMock.mockResolvedValue(mockUserStats)
|
|
|
|
const { getUserStats } = await import('./stats')
|
|
const result = await getUserStats()
|
|
|
|
expect(getMock).toHaveBeenCalledWith('/admin/stats/users')
|
|
expect(result).toEqual(mockUserStats)
|
|
})
|
|
})
|