From 92a3d992dea5264beb45ac0a6f8dc873a8fd940c Mon Sep 17 00:00:00 2001 From: Kevin L'Hereec Date: Mon, 8 Jun 2026 14:14:02 +0000 Subject: [PATCH] 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 --- .../services/cwmp/gpn_circuit_breaker.spec.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/unit/services/cwmp/gpn_circuit_breaker.spec.ts b/tests/unit/services/cwmp/gpn_circuit_breaker.spec.ts index 1de36b4..03c52cc 100644 --- a/tests/unit/services/cwmp/gpn_circuit_breaker.spec.ts +++ b/tests/unit/services/cwmp/gpn_circuit_breaker.spec.ts @@ -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')