test: 507 tests, 79% line coverage — near 80% threshold
- Device domain: full coverage of organizeParameters, updateFromValues - MainStateMachine: full lifecycle test, error handling, GPN failure - Coverage: 52% → 79% lines (507 tests)
This commit is contained in:
1 parent
12a1787151
commit
575975e211
2 files changed
+137
No files matched your search
@@ -64,6 +64,48 @@ describe('MainStateMachine', () => {
|
||||
const response = await sm.start()
|
||||
expect(response).toContain('InternetGatewayDevice.ManagementServer.')
|
||||
})
|
||||
|
||||
it('GPN failure sets gpnStatus unsupported and continues', async () => {
|
||||
const sm = new MainStateMachine(makeDevice('tr-181'), 'sess-1', new CWMPTaskQueue())
|
||||
await sm.start()
|
||||
// Simulate GPN fault (9001 = method not supported)
|
||||
await sm.handleResponse(false, { FaultCode: 9001, FaultString: 'Method not supported' })
|
||||
// Should have transitioned past discovering-parameters
|
||||
expect(sm.getCurrentStateName()).not.toBe('discovering-parameters')
|
||||
})
|
||||
|
||||
it('full lifecycle: idle → discovering → config-eval → compliance → executing → completed', async () => {
|
||||
const sm = new MainStateMachine(makeDevice('tr-181'), 'sess-1', new CWMPTaskQueue())
|
||||
// Step 1: start → GPN
|
||||
await sm.start()
|
||||
expect(sm.getCurrentStateName()).toBe('discovering-parameters')
|
||||
|
||||
// Step 2: GPN response → config-eval
|
||||
await sm.handleResponse(true, { ParameterList: { ParameterInfoStruct: [] } })
|
||||
expect(sm.getCurrentStateName()).toBe('configuration-evaluation')
|
||||
|
||||
// Step 3+: config eval will process its queue and eventually reach compliance-update
|
||||
// Since our mock engine returns inventoryPaths, it will send GPN requests
|
||||
// After all config eval actions complete, it reaches compliance-update → executing-commands → completed
|
||||
// Simulate multiple responses to drain the config eval state
|
||||
let guard = 0
|
||||
while (!sm.isCompleted() && guard++ < 20) {
|
||||
await sm.handleResponse(true, { Status: 0, ParameterList: { ParameterInfoStruct: [], ParameterValueStruct: [] } })
|
||||
}
|
||||
expect(sm.isCompleted()).toBe(true)
|
||||
})
|
||||
|
||||
it('error in state transitions to completed gracefully', async () => {
|
||||
const sm = new MainStateMachine(makeDevice('tr-181'), 'sess-1', new CWMPTaskQueue())
|
||||
await sm.start()
|
||||
// Force an unexpected error by passing malformed data many times
|
||||
for (let i = 0; i < 20; i++) {
|
||||
await sm.handleResponse(false, { error: 'unexpected' })
|
||||
if (sm.isCompleted()) break
|
||||
}
|
||||
// Should eventually complete (safety guard or error handling)
|
||||
expect(sm.isCompleted()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('ExecutingCommandsState', () => {
|
||||
|
||||
Reference in new issue
Block a user