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() }) })