fix(test): replace meaningless assertions with behavior-based tests across 7 test files

Replace toBeDefined()/typeof checks with assertions that verify actual
behavior and output content. Key changes:

- locators: assert actual CSS selector values instead of existence
- logger-integration: test run()/getContext()/withRequestContext() behavior
- logger: verify winstonCalls content (level, message, metadata)
- config-manager: test default values, singleton, and getConfig() throws
- erp-auth: remove empty Class Structure block (covered by behavior tests)
- audit-logger: spy on auditLogger.info to verify JSONL entry content
- extractor: remove Math.ceil tests, verify error result structure

Net: -209 lines of hollow/redundant test code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-04-04 22:07:09 +08:00
parent 75f0105167
commit fc71b2a585
7 changed files with 314 additions and 523 deletions

View File

@@ -1,93 +1,28 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { describe, it, expect } from 'vitest'
import { ErpAuthService } from '../../src/main/services/erp/erp-auth'
import type { ErpConfig } from '../../src/main/types/erp.types'
const testConfig: ErpConfig = {
url: 'https://test.example.com',
username: 'testuser',
password: 'testpass'
}
describe('ERP Authentication Service (Unit)', () => {
describe('Session Management', () => {
it('should create service instance with config', () => {
const config: ErpConfig = {
url: 'https://test.example.com',
username: 'testuser',
password: 'testpass'
}
const service = new ErpAuthService(config)
expect(service).toBeDefined()
describe('Initial State', () => {
it('should report inactive status before login', () => {
const service = new ErpAuthService(testConfig)
expect(service.isActive()).toBe(false)
})
it('should throw error when getting session before login', () => {
const config: ErpConfig = {
url: 'https://test.example.com',
username: 'testuser',
password: 'testpass'
}
const service = new ErpAuthService(config)
const service = new ErpAuthService(testConfig)
expect(() => service.getSession()).toThrow('Not logged in. Call login() first.')
})
it('should report inactive status before login', () => {
const config: ErpConfig = {
url: 'https://test.example.com',
username: 'testuser',
password: 'testpass'
}
const service = new ErpAuthService(config)
expect(service.isActive()).toBe(false)
})
})
describe('Close Method', () => {
it('should handle close when no session exists', async () => {
const config: ErpConfig = {
url: 'https://test.example.com',
username: 'testuser',
password: 'testpass'
}
const service = new ErpAuthService(config)
// Should not throw when closing without session
const service = new ErpAuthService(testConfig)
await expect(service.close()).resolves.toBeUndefined()
})
})
describe('Class Structure', () => {
let service: ErpAuthService
beforeEach(() => {
const config: ErpConfig = {
url: 'https://test.example.com',
username: 'testuser',
password: 'testpass'
}
service = new ErpAuthService(config)
})
it('should have login method that returns a Promise', () => {
expect(service.login).toBeDefined()
expect(typeof service.login).toBe('function')
expect(service.login()).toBeInstanceOf(Promise)
})
it('should have close method', () => {
expect(service.close).toBeDefined()
expect(typeof service.close).toBe('function')
})
it('should have getSession method', () => {
expect(service.getSession).toBeDefined()
expect(typeof service.getSession).toBe('function')
})
it('should have isActive method', () => {
expect(service.isActive).toBeDefined()
expect(typeof service.isActive).toBe('function')
})
})
})