import { CommandClasses } from "@zwave-js/core" ; import type { Driver } from "../driver/Driver" ; import { ZWaveNode } from "../node/Node" ; import { assertCC } from "../test/assertCC" ; import { createEmptyMockDriver } from "../test/mocks" ; import { DoorLockLoggingCC , DoorLockLoggingCCRecordGet , DoorLockLoggingCCRecordReport , DoorLockLoggingCCRecordsSupportedGet , DoorLockLoggingCCRecordsSupportedReport , DoorLockLoggingCommand , EventType , } from "./DoorLockLoggingCC" ; const fakeDriver = createEmptyMockDriver ( ) as unknown as Driver ; function buildCCBuffer ( payload ) { return Buffer . concat ( [ Buffer . from ( [ CommandClasses [ "Door Lock Logging" ] , ] ) , payload , ] ) ; } describe ( "lib/commandclass/DoorLockLoggingCC => " , ( ) => { it ( "the RecordsCountGet command should serialize correctly" , ( ) => { const cc = new DoorLockLoggingCCRecordsSupportedGet ( fakeDriver , { nodeId : 1 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ DoorLockLoggingCommand . RecordsSupportedGet , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the RecordsCountReport command should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ DoorLockLoggingCommand . RecordsSupportedReport , 0x14 , ] ) ) ; const cc = new DoorLockLoggingCCRecordsSupportedReport ( fakeDriver , { nodeId : 1 , data : ccData } ) ; expect ( cc . recordsCount ) . toBe ( 20 ) ; } ) ; it ( "the RecordGet command should serialize correctly" , ( ) => { const cc = new DoorLockLoggingCCRecordGet ( fakeDriver , { nodeId : 1 , recordNumber : 1 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ DoorLockLoggingCommand . RecordGet , 1 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the RecordReport command should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ DoorLockLoggingCommand . RecordReport , 7 , 0x07 , 0xc5 , 12 , 27 , 0x2a , 40 , 30 , EventType . LockCode , 1 , 0 , 0 , ] ) ) ; const cc = new DoorLockLoggingCCRecordReport ( fakeDriver , { nodeId : 1 , data : ccData } ) ; expect ( cc . recordNumber ) . toBe ( 7 ) ; expect ( cc . record ! . eventType ) . toBe ( 1 ) ; expect ( cc . record ! . label ) . toBe ( "Locked via Access Code" ) ; expect ( cc . record ! . timestamp ) . toBe ( new Date ( 1989 , 12 - 1 , 27 , 10 , 40 , 30 ) . toISOString ( ) ) ; expect ( cc . record ! . userId ) . toBe ( 1 ) ; } ) ; describe ( `interview()` , ( ) => { const fakeDriver = createEmptyMockDriver ( ) ; const node = new ZWaveNode ( 2 , fakeDriver as unknown as Driver ) ; beforeAll ( ( ) => { fakeDriver . sendMessage . mockImplementation ( ( ) => Promise . resolve ( { command : { } } ) ) ; fakeDriver . controller . nodes . set ( node . id , node ) ; node . addCC ( CommandClasses [ "Door Lock Logging" ] , { version : 1 , isSupported : true } ) ; } ) ; beforeEach ( ( ) => fakeDriver . sendMessage . mockClear ( ) ) ; afterAll ( ( ) => { fakeDriver . sendMessage . mockImplementation ( ( ) => Promise . resolve ( ) ) ; node . destroy ( ) ; } ) ; it ( "should send a DoorLockLoggingCC.RecordsCountGet" , async ( ) => { node . addCC ( CommandClasses [ "Door Lock Logging" ] , { isSupported : true } ) ; const cc = node . createCCInstance ( DoorLockLoggingCC ) ! ; await cc . interview ( ) ; expect ( fakeDriver . sendMessage ) . toBeCalled ( ) ; assertCC ( fakeDriver . sendMessage . mock . calls [ 0 ] [ 0 ] , { cc : DoorLockLoggingCCRecordsSupportedGet , nodeId : node . id } ) ; } ) ; it . todo ( "Test the behavior when the request failed" ) ; it . todo ( "Test the behavior when the request succeeds" ) ; } ) ; } ) ;