Files
adam-acs/tests/unit/services/references/reference_engine.spec.ts
T
Kevin L'Hereec e857b4fbe7 feat: reference providers system with Wassup integration
- Pluggable multi-provider architecture (ReferenceEngine)
- Wassup provider implementation (HTTP GET + X_WASSUP_USER_IP)
- Auto-resolve references on Inform (BOOT/BOOTSTRAP events)
- References displayed in device Identity card
- REST API: GET/POST references per device
- Config via config/references.json
- Fix event extraction for single EventStruct and numeric EventCodes
- Mock Wassup provisioned by home-device-simulator on device creation
2026-06-02 15:52:16 +02:00

58 lines
2.2 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { ReferenceEngine } from '../../../../app/services/references/reference_engine.js'
import type { DeviceRecord } from '../../../../app/domain/device/device_record.js'
import type { InformContext } from '../../../../app/services/references/types.js'
import { DeviceId } from '../../../../app/domain/device/device_id.js'
function makeDevice(): DeviceRecord {
return {
identifier: 'test-device-001',
deviceId: new DeviceId('TestCorp', 'AABBCC', 'TestBox', 'SERIAL001'),
properties: [
{ name: 'Device.DeviceInfo.MACAddress', value: 'AA:BB:CC:11:22:33', type: 'xsd:string' as any },
],
parameters: [],
}
}
describe('ReferenceEngine.extractResolveValue', () => {
const context: InformContext = { events: [], remoteIp: '192.168.1.100', headers: {} }
it('extracts IP from context', () => {
const value = ReferenceEngine.extractResolveValue(makeDevice(), 'ip', context)
expect(value).toBe('192.168.1.100')
})
it('extracts serialNumber from device', () => {
const value = ReferenceEngine.extractResolveValue(makeDevice(), 'serialNumber', context)
expect(value).toBe('SERIAL001')
})
it('extracts OUI from device', () => {
const value = ReferenceEngine.extractResolveValue(makeDevice(), 'oui', context)
expect(value).toBe('AABBCC')
})
it('extracts MAC from device parameters', () => {
const value = ReferenceEngine.extractResolveValue(makeDevice(), 'mac', context)
expect(value).toBe('AA:BB:CC:11:22:33')
})
it('extracts parameter by path', () => {
const device = makeDevice()
device.properties.push({ name: 'Device.ManagementServer.Username', value: 'admin', type: 'xsd:string' as any })
const value = ReferenceEngine.extractResolveValue(device, 'parameter:Device.ManagementServer.Username', context)
expect(value).toBe('admin')
})
it('returns null for empty IP', () => {
const value = ReferenceEngine.extractResolveValue(makeDevice(), 'ip', { events: [], remoteIp: '', headers: {} })
expect(value).toBeNull()
})
it('returns null for unknown resolveBy', () => {
const value = ReferenceEngine.extractResolveValue(makeDevice(), 'unknown_key', context)
expect(value).toBeNull()
})
})