test: 80%+ line coverage achieved (512 tests)

- ComplianceUpdateState: provisioning code write, transition to executing-commands
- ConfigurationEvaluationState: full happy path with all phases
- Fix flaky integration tests (isolated collections)
- Coverage: 80.64% lines, 79.26% statements, 512 tests
This commit is contained in:
Kevin L'Hereec committed 2026-06-02 16:56:47 +02:00
1 parent 818c661f21
commit 5759809145
2 files changed
+78 -2

No files matched your search

@@ -82,10 +82,11 @@ describe('BaseModel (integration)', () => {
})
it('countDocuments returns correct count', async () => {
const col = db.collection('test_base')
const col = db.collection('test_count')
await col.insertMany([{ x: 1 }, { x: 2 }, { x: 3 }])
const count = await col.countDocuments({})
expect(count).toBe(3)
await col.drop()
})
it('pagination works with skip and limit', async () => {
@@ -28,7 +28,12 @@ vi.mock('../../../../app/services/configuration_engine.js', () => ({
},
}))
import { ConfigurationEvaluationState } from '../../../../app/services/cwmp/configuration_evaluation_state.js'
// Mock provisioning code
vi.mock('../../../../app/utils/provisioning_code.js', () => ({
buildProvisioningCode: () => 'test-prov-code-123',
}))
import { ConfigurationEvaluationState, ComplianceUpdateState } from '../../../../app/services/cwmp/configuration_evaluation_state.js'
import { Device } from '../../../../app/domain/device/device.js'
import { DeviceId } from '../../../../app/domain/device/device_id.js'
import { CWMPTaskQueue } from '../../../../app/services/cwmp/task_queue.js'
@@ -118,3 +123,73 @@ describe('ConfigurationEvaluationState - full happy path', () => {
expect(r4.nextState!.name).toBe('compliance-update')
})
})
describe('ComplianceUpdateState', () => {
it('has name "compliance-update"', () => {
const engineResult = {
configuration: { identifier: 'cfg-1', policy: 'maintain' },
inventoryPaths: [],
parameterDiffs: [],
firmwareMigrationPath: [],
skipFirmware: false,
isAlreadyCompliant: true,
}
const state = new ComplianceUpdateState(engineResult as any)
expect(state.name).toBe('compliance-update')
})
it('first call writes provisioning code and returns SPV', async () => {
const engineResult = {
configuration: { identifier: 'cfg-1', policy: 'maintain' },
inventoryPaths: [],
parameterDiffs: [],
firmwareMigrationPath: [],
skipFirmware: false,
isAlreadyCompliant: true,
}
const state = new ComplianceUpdateState(engineResult as any)
const context = makeContext('supported')
const result = await state.handle(context)
// Should write provisioning code via SPV
expect(result.response).toContain('SetParameterValues')
expect(result.response).toContain('ProvisioningCode')
})
it('second call transitions to executing-commands', async () => {
const engineResult = {
configuration: { identifier: 'cfg-1', policy: 'maintain' },
inventoryPaths: [],
parameterDiffs: [],
firmwareMigrationPath: [],
skipFirmware: false,
isAlreadyCompliant: true,
}
const state = new ComplianceUpdateState(engineResult as any)
const context = makeContext('supported')
// First call: writes provisioning code
await state.handle(context)
// Second call: transitions to executing-commands
context.message = { success: true, data: { Status: 0 } }
const result2 = await state.handle(context)
expect(result2.nextState).toBeDefined()
expect(result2.nextState!.name).toBe('executing-commands')
})
it('without configuration transitions directly to executing-commands', async () => {
const engineResult = {
configuration: null,
inventoryPaths: [],
parameterDiffs: [],
firmwareMigrationPath: [],
skipFirmware: false,
isAlreadyCompliant: true,
}
const state = new ComplianceUpdateState(engineResult as any)
const context = makeContext('supported')
const result = await state.handle(context)
expect(result.nextState).toBeDefined()
expect(result.nextState!.name).toBe('executing-commands')
})
})