import { describe, it, expect } from 'vitest' import { DeviceId } from '../../../app/domain/device/device_id.js' describe('DeviceId', () => { it('creates a valid DeviceId', () => { const id = new DeviceId('Sagemcom', 'F8B7FF', 'Livebox', 'SN001') expect(id.manufacturer).toBe('Sagemcom') expect(id.oui).toBe('F8B7FF') expect(id.productClass).toBe('Livebox') expect(id.serialNumber).toBe('SN001') }) it('throws if manufacturer is empty', () => { expect(() => new DeviceId('', 'OUI', 'PC', 'SN')).toThrow('Manufacturer is required') }) it('throws if manufacturer is whitespace', () => { expect(() => new DeviceId(' ', 'OUI', 'PC', 'SN')).toThrow('Manufacturer is required') }) it('throws if serialNumber is empty', () => { expect(() => new DeviceId('Mfr', 'OUI', 'PC', '')).toThrow('Serial number is required') }) it('toIdentifier returns formatted string', () => { const id = new DeviceId('Sagemcom', 'F8B7FF', 'Livebox 4', 'SN001') expect(id.toIdentifier()).toBe('Sagemcom-F8B7FF-Livebox 4-SN001') }) it('toString delegates to toIdentifier', () => { const id = new DeviceId('Mfr', 'OUI', 'PC', 'SN') expect(id.toString()).toBe(id.toIdentifier()) }) it('equals returns true for same values', () => { const a = new DeviceId('Mfr', 'OUI', 'PC', 'SN') const b = new DeviceId('Mfr', 'OUI', 'PC', 'SN') expect(a.equals(b)).toBe(true) }) it('equals returns false for different values', () => { const a = new DeviceId('Mfr', 'OUI', 'PC', 'SN1') const b = new DeviceId('Mfr', 'OUI', 'PC', 'SN2') expect(a.equals(b)).toBe(false) }) it('fromInform creates DeviceId from inform data', () => { const id = DeviceId.fromInform({ Manufacturer: 'Huawei', OUI: '202BC1', ProductClass: 'BM632w', SerialNumber: '000000' }) expect(id.manufacturer).toBe('Huawei') expect(id.oui).toBe('202BC1') }) it('fromInform handles missing fields gracefully', () => { // fromInform with empty strings will fail validation since manufacturer is required expect(() => DeviceId.fromInform({})).toThrow('Manufacturer is required') }) })