test: add Stage 1 lib and Stage 2 services test coverage

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.
This commit is contained in:
2026-04-17 23:59:15 +08:00
parent 582ad7a069
commit 40d146b6aa
15 changed files with 1900 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
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)
})
})