Files
adam-acs/tests/unit/domain/device_parameter.spec.ts
T
Kevin L'Hereec 003ef50a8e test: improve coverage — domain, protocol, references, integration DB tests
- Domain: DeviceId, Command, DeviceParameter, DeviceProperty, Mode
- Protocol: SOAP parsing, CWMPMessageBuilder (all methods)
- References: config_loader, WassupProvider (timeout, errors)
- Integration: MongoDB tests (CRUD, pagination, references)
- Fix: Home.vue IP lookup for Device.WANDevice path
- Total: 384 tests passing
2026-06-02 16:29:19 +02:00

82 lines
2.8 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { DeviceParameter, DeviceProperty } from '../../../app/domain/device/device_parameter.js'
describe('DeviceParameter', () => {
it('creates with name and value', () => {
const p = new DeviceParameter('Device.Info.Name', 'hello')
expect(p.name).toBe('Device.Info.Name')
expect(p.value).toBe('hello')
})
it('updateValue changes value and updatedAt', () => {
const p = new DeviceParameter('x', 'old')
const before = p.updatedAt
p.updateValue('new')
expect(p.value).toBe('new')
expect(p.updatedAt.getTime()).toBeGreaterThanOrEqual(before.getTime())
})
it('updateAttributes sets notification and accessList', () => {
const p = new DeviceParameter('x', 'v')
p.updateAttributes(2, ['admin'])
expect(p.notification).toBe(2)
expect(p.accessList).toEqual(['admin'])
})
it('updateAttributes only sets provided fields', () => {
const p = new DeviceParameter('x', 'v')
p.updateAttributes(1)
expect(p.notification).toBe(1)
expect(p.accessList).toBeUndefined()
})
it('toSnapshot returns serializable object', () => {
const p = new DeviceParameter('Device.Info', 'val')
const snap = p.toSnapshot()
expect(snap.name).toBe('Device.Info')
expect(snap.value).toBe('val')
expect(snap.createdAt).toBeInstanceOf(Date)
})
})
describe('DeviceProperty', () => {
it('creates and reads value', () => {
const p = new DeviceProperty('Device.SW', '1.0')
expect(p.value).toBe('1.0')
})
it('updateValue changes value', () => {
const p = new DeviceProperty('x', 'old')
p.updateValue('new')
expect(p.value).toBe('new')
})
it('updateAttributes sets fields', () => {
const p = new DeviceProperty('x', 'v')
p.updateAttributes(0, [])
expect(p.notification).toBe(0)
expect(p.accessList).toEqual([])
})
it('getConnectionRequestURL returns URL for matching name', () => {
const p = new DeviceProperty('Device.ManagementServer.ConnectionRequestURL', 'http://example.com:7547/')
expect(p.getConnectionRequestURL()).not.toBeNull()
expect(p.getConnectionRequestURL()!.hostname).toBe('example.com')
})
it('getConnectionRequestURL returns null for non-matching name', () => {
const p = new DeviceProperty('Device.Info.Name', 'http://example.com')
expect(p.getConnectionRequestURL()).toBeNull()
})
it('getConnectionRequestURL returns null for invalid URL', () => {
const p = new DeviceProperty('Device.ManagementServer.ConnectionRequestURL', 'not-a-url')
expect(p.getConnectionRequestURL()).toBeNull()
})
it('getConnectionRequestURL returns null for empty value', () => {
const p = new DeviceProperty('Device.ManagementServer.ConnectionRequestURL', '')
expect(p.getConnectionRequestURL()).toBeNull()
})
})