test: add 2 unit tests for GPN response processing in DiscoveringParametersState
- 'processes GPN response and stores parameters': verifies that writable params go to device.parameters, read-only to device.properties, object paths ignored, and gpnStatus set to 'supported' - 'sets gpnStatus supported even with empty param list': edge case with no params Generated with [Continue](https://continue.dev) Co-Authored-By: Continue <noreply@continue.dev>
This commit is contained in:
1 parent
7540327689
commit
92a3d992de
1 file changed
+53
@@ -105,6 +105,59 @@ describe('GPN Circuit Breaker — DiscoveringParametersState', () => {
|
||||
expect(response).toContain('GetParameterNames')
|
||||
})
|
||||
|
||||
it('DiscoveringParametersState processes GPN response and stores parameters', async () => {
|
||||
const device = makeDevice()
|
||||
device.setGpnStatus('unknown')
|
||||
const taskQueue = new CWMPTaskQueue()
|
||||
const sm = new MainStateMachine(device, 'session-1', taskQueue)
|
||||
|
||||
// Start: IdleState → DiscoveringParametersState → sends GPN
|
||||
await sm.start()
|
||||
|
||||
// Simulate a successful GPN response with ParameterInfoStruct list
|
||||
const gpnResponse = {
|
||||
ParameterList: {
|
||||
ParameterInfoStruct: [
|
||||
{ Name: 'InternetGatewayDevice.ManagementServer.', Writable: false },
|
||||
{ Name: 'InternetGatewayDevice.ManagementServer.PeriodicInformInterval', Writable: true },
|
||||
{ Name: 'InternetGatewayDevice.ManagementServer.PeriodicInformEnable', Writable: true },
|
||||
{ Name: 'InternetGatewayDevice.ManagementServer.URL', Writable: true },
|
||||
{ Name: 'InternetGatewayDevice.ManagementServer.ConnectionRequestURL', Writable: false },
|
||||
],
|
||||
},
|
||||
}
|
||||
await sm.handleResponse(true, gpnResponse)
|
||||
|
||||
// gpnStatus should be 'supported'
|
||||
expect(device.gpnStatus).toBe('supported')
|
||||
|
||||
// Writable params should be stored as parameters
|
||||
const periodicInterval = device.getParameter('InternetGatewayDevice.ManagementServer.PeriodicInformInterval')
|
||||
expect(periodicInterval).not.toBeNull()
|
||||
|
||||
// Read-only params should be stored as properties
|
||||
const connUrl = device.getProperty('InternetGatewayDevice.ManagementServer.ConnectionRequestURL')
|
||||
expect(connUrl).not.toBeNull()
|
||||
|
||||
// Object paths (ending with dot) should NOT be stored
|
||||
const obj = device.getParameter('InternetGatewayDevice.ManagementServer.')
|
||||
expect(obj).toBeNull()
|
||||
})
|
||||
|
||||
it('DiscoveringParametersState sets gpnStatus supported even with empty param list', async () => {
|
||||
const device = makeDevice()
|
||||
device.setGpnStatus('unknown')
|
||||
const taskQueue = new CWMPTaskQueue()
|
||||
const sm = new MainStateMachine(device, 'session-1', taskQueue)
|
||||
|
||||
await sm.start()
|
||||
|
||||
// Respond with empty list
|
||||
await sm.handleResponse(true, { ParameterList: { ParameterInfoStruct: [] } })
|
||||
|
||||
expect(device.gpnStatus).toBe('supported')
|
||||
})
|
||||
|
||||
it('DiscoveringParametersState calls recordGpnFailure and persists on fault', async () => {
|
||||
const device = makeDevice()
|
||||
device.setGpnStatus('unknown')
|
||||
|
||||
Reference in new issue
Block a user