fix(test): improve test isolation and reduce noise in unit tests
- Add logger/error-utils mocks to cleaner-handler test to suppress IPC error log noise - Move setupServiceMocks into beforeEach for consistent default mocking in cleaner tests - Replace vi.waitFor (2s timeout) with setImmediate microtask flush in extractor test - Remove dead activeType assignments in validation-database test - Align TestUser.id type with UserInfo.id (string → number) and use deterministic counter Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
8
tests/fixtures/factory.ts
vendored
8
tests/fixtures/factory.ts
vendored
@@ -73,10 +73,12 @@ export class UserFactory {
|
||||
/**
|
||||
* Generate unique user ID
|
||||
*
|
||||
* @returns Unique ID string in format USR-{timestamp}-{random}
|
||||
* @returns Unique numeric ID
|
||||
*/
|
||||
private static generateId(): string {
|
||||
return `USR-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`
|
||||
private static idCounter = 0
|
||||
|
||||
private static generateId(): number {
|
||||
return ++UserFactory.idCounter
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
4
tests/fixtures/types.ts
vendored
4
tests/fixtures/types.ts
vendored
@@ -88,8 +88,8 @@ export interface Order {
|
||||
* Simplified user data for creating test users.
|
||||
*/
|
||||
export interface TestUser {
|
||||
/** User ID */
|
||||
id: string
|
||||
/** User ID (matches UserInfo.id: number) */
|
||||
id: number
|
||||
/** Username for login */
|
||||
username: string
|
||||
/** User type/role */
|
||||
|
||||
11
tests/fixtures/user-factory.test.ts
vendored
11
tests/fixtures/user-factory.test.ts
vendored
@@ -2,17 +2,22 @@
|
||||
* UserFactory Unit Tests
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { UserFactory } from './factory'
|
||||
|
||||
describe('UserFactory', () => {
|
||||
beforeEach(() => {
|
||||
// Reset ID counter to ensure test isolation
|
||||
;(UserFactory as any).idCounter = 0
|
||||
})
|
||||
|
||||
it('creates user with default role', () => {
|
||||
const user = UserFactory.createUser()
|
||||
|
||||
expect(user.username).toMatch(/^test_user_\d+$/)
|
||||
expect(user.userType).toBe('User')
|
||||
expect(user.permissions).toEqual(['read', 'write'])
|
||||
expect(user.id).toMatch(/^USR-\d+-[a-z0-9]+$/)
|
||||
expect(user.id).toBeTypeOf('number')
|
||||
})
|
||||
|
||||
it('creates admin with correct permissions', () => {
|
||||
@@ -20,7 +25,7 @@ describe('UserFactory', () => {
|
||||
|
||||
expect(admin.userType).toBe('Admin')
|
||||
expect(admin.permissions).toEqual(['read', 'write', 'delete', 'admin'])
|
||||
expect(admin.id).toMatch(/^USR-\d+-[a-z0-9]+$/)
|
||||
expect(admin.id).toBeTypeOf('number')
|
||||
})
|
||||
|
||||
it('generates unique IDs', () => {
|
||||
|
||||
Reference in New Issue
Block a user