This commit is contained in:
Kevin L'Hereec committed 2026-06-08 16:03:03 +02:00
1 parent a6c1b05a76
commit 08f4bb1ea5
4 files changed
+9 -25

No files matched your search

@@ -83,7 +83,7 @@ describe('DeviceActionExecutor — coverage', () => {
const device = makeDevice()
device.setGpnStatus('unknown')
let capturedCallback: any
vi.spyOn(taskQueue, 'addTask').mockImplementation((deviceId, type, props, cb) => {
vi.spyOn(taskQueue, 'addTask').mockImplementation((_deviceId, _type, _props, cb) => {
capturedCallback = cb
return { xml: '<gpn/>', taskId: 'tid-1' }
})
@@ -99,7 +99,7 @@ describe('DeviceActionExecutor — coverage', () => {
const device = makeDevice()
device.setGpnStatus('unknown')
let capturedCallback: any
vi.spyOn(taskQueue, 'addTask').mockImplementation((deviceId, type, props, cb) => {
vi.spyOn(taskQueue, 'addTask').mockImplementation((_deviceId, _type, _props, cb) => {
capturedCallback = cb
return { xml: '<gpn/>', taskId: 'tid-2' }
})
@@ -115,7 +115,7 @@ describe('DeviceActionExecutor — coverage', () => {
const device = makeDevice()
device.setGpnStatus('unknown')
let capturedCallback: any
vi.spyOn(taskQueue, 'addTask').mockImplementation((deviceId, type, props, cb) => {
vi.spyOn(taskQueue, 'addTask').mockImplementation((_deviceId, _type, _props, cb) => {
capturedCallback = cb
return { xml: '<gpn/>', taskId: 'tid-3' }
})
@@ -131,7 +131,7 @@ describe('DeviceActionExecutor — coverage', () => {
const device = makeDevice()
device.setGpnStatus('unknown')
let capturedCallback: any
vi.spyOn(taskQueue, 'addTask').mockImplementation((deviceId, type, props, cb) => {
vi.spyOn(taskQueue, 'addTask').mockImplementation((_deviceId, _type, _props, cb) => {
capturedCallback = cb
return { xml: '<gpn/>', taskId: 'tid-4' }
})
@@ -212,7 +212,7 @@ describe('DeviceActionExecutor — coverage', () => {
it('persistDevice calls DeviceModel.createOrUpdate', async () => {
const device = makeDevice()
let capturedCallback: any
vi.spyOn(taskQueue, 'addTask').mockImplementation((deviceId, type, props, cb) => {
vi.spyOn(taskQueue, 'addTask').mockImplementation((_deviceId, _type, _props, cb) => {
capturedCallback = cb
return { xml: '<xml/>', taskId: 'tid-p' }
})
@@ -492,7 +492,7 @@ describe('DeviceActionExecutor — callback execution for remaining uncovered li
const device = makeDevice()
device.setGpnStatus('unknown')
let capturedCallback: any
vi.spyOn(taskQueue, 'addTask').mockImplementation((deviceId, type, props, cb) => {
vi.spyOn(taskQueue, 'addTask').mockImplementation((_deviceId, _type, _props, cb) => {
capturedCallback = cb
return { xml: '<gpn/>', taskId: 'tid-nested' }
})
@@ -194,16 +194,8 @@ describe('ExecutingCommandsState — direct testing', () => {
const cmd = { _id: 'c8', action: 'INVALID_TYPE', parameters: {}, status: CommandStatus.PENDING, mode: ModeType.I, priority: 1 }
setupCommandMock([cmd])
const device = makeDevice()
const context = makeContext(device)
const state = new ExecutingCommandsState(true)
await state.handle(context)
expect(vi.mocked(CommandModel.updateCommand)).toHaveBeenCalledWith(
'c8',
expect.objectContaining({ status: CommandStatus.FAILED })
)
expect(vi.mocked(logger.error)).toHaveBeenCalled()
expect(vi.mocked(CommandModel.updateCommand)).toHaveBeenCalledWith('c8', expect.objectContaining({ status: CommandStatus.FAILED }))
})
it('marks command COMPLETED on success response and does SPV optimistic update', async () => {
@@ -244,8 +236,6 @@ describe('ExecutingCommandsState — direct testing', () => {
// Second handle: receives fault
context.message = { success: false, data: { FaultCode: 9001 } }
await state.handle(context)
expect(vi.mocked(CommandModel.updateCommand)).toHaveBeenCalledWith('c10', expect.objectContaining({ status: CommandStatus.FAILED }))
})
})
@@ -28,7 +28,6 @@ vi.mock('../../../../app/models/command.js', () => ({
import { StateMachineManager, MachineStatus } from '../../../../app/services/cwmp/state_machine_manager.js'
import { Device } from '../../../../app/domain/device/device.js'
import { DeviceId } from '../../../../app/domain/device/device_id.js'
import { CWMPTaskQueue, ResultStatus } from '../../../../app/services/cwmp/task_queue.js'
function makeDevice(): Device {
const device = new Device(new DeviceId('Sagemcom', 'F8B7FF', 'Livebox 4', 'LB4-TEST-001'))
@@ -118,9 +117,6 @@ describe('StateMachineManager — additional coverage', () => {
// --- continue() serving task from queue ---
it('continue() serves pending task from queue when state machine returns empty', async () => {
const device = makeDevice()
const machine = await manager.startStateMachine(device, 'sess-q', { events: ['6 CONNECTION REQUEST'] })
// Start the immediate command SM (completes with no commands)
await manager.continue('sess-q')
+1 -3
View File
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { CWMPTaskQueue, TaskStatus, ResultStatus, TaskResult } from '../../../../app/services/cwmp/task_queue.js'
import { CWMPTaskQueue, TaskStatus, ResultStatus } from '../../../../app/services/cwmp/task_queue.js'
import { DeviceId } from '../../../../app/domain/device/device_id.js'
// Mock AdonisJS logger
@@ -101,7 +101,6 @@ describe('CWMPTaskQueue', () => {
return result.status === ResultStatus.Success ? 'ok' : 'fail'
})
// Get the task ID (the first task in the map)
const task = queue.getTaskForDevice(deviceId)
// Since addTask already dequeued via SENT, we check via callback
// Actually addTask doesn't dequeue — it marks as SENT but keeps in map
// Let's use the registerCallback approach
@@ -117,7 +116,6 @@ describe('CWMPTaskQueue', () => {
it('removes pending tasks but keeps sent ones', () => {
const deviceId = makeDeviceId()
queue.addCWMPTask(deviceId, 'reboot', {})
const t2 = queue.addCWMPTask(deviceId, 'factory_reset', {})
// Mark first as SENT by getting it
queue.getTaskForDevice(deviceId)
// Now clear — the SENT task should remain, pending ones removed