import { CommandClasses } from "@zwave-js/core" ; import type { Driver } from "../driver/Driver" ; import { createEmptyMockDriver } from "../test/mocks" ; import { AssociationCCGet , AssociationCCRemove , AssociationCCReport , AssociationCCSet , AssociationCCSupportedGroupingsGet , AssociationCCSupportedGroupingsReport , AssociationCommand , } from "./AssociationCC" ; const fakeDriver = createEmptyMockDriver ( ) as unknown as Driver ; function buildCCBuffer ( payload ) { return Buffer . concat ( [ Buffer . from ( [ CommandClasses . Association , ] ) , payload , ] ) ; } describe ( "lib/commandclass/AssociationCC => " , ( ) => { it ( "the SupportedGroupingsGet command should serialize correctly" , ( ) => { const cc = new AssociationCCSupportedGroupingsGet ( fakeDriver , { nodeId : 1 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ AssociationCommand . SupportedGroupingsGet , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the SupportedGroupingsReport command should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ AssociationCommand . SupportedGroupingsReport , 7 , ] ) ) ; const cc = new AssociationCCSupportedGroupingsReport ( fakeDriver , { nodeId : 2 , data : ccData } ) ; expect ( cc . groupCount ) . toBe ( 7 ) ; } ) ; it ( "the Set command should serialize correctly" , ( ) => { const cc = new AssociationCCSet ( fakeDriver , { nodeId : 2 , groupId : 5 , nodeIds : [ 1 , 2 , 5 ] } ) ; const expected = buildCCBuffer ( Buffer . from ( [ AssociationCommand . Set , 5 , 1 , 2 , 5 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Get command should serialize correctly" , ( ) => { const cc = new AssociationCCGet ( fakeDriver , { nodeId : 1 , groupId : 9 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ AssociationCommand . Get , 9 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Report command should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ AssociationCommand . Report , 5 , 9 , 0 , 1 , 2 , 5 , ] ) ) ; const cc = new AssociationCCReport ( fakeDriver , { nodeId : 1 , data : ccData } ) ; expect ( cc . groupId ) . toBe ( 5 ) ; expect ( cc . maxNodes ) . toBe ( 9 ) ; expect ( cc . reportsToFollow ) . toBe ( 0 ) ; expect ( cc . nodeIds ) . toEqual ( [ 1 , 2 , 5 ] ) ; } ) ; it ( "the Remove command should serialize correctly" , ( ) => { const cc = new AssociationCCRemove ( fakeDriver , { nodeId : 2 , groupId : 5 , nodeIds : [ 1 , 2 , 5 ] } ) ; const expected = buildCCBuffer ( Buffer . from ( [ AssociationCommand . Remove , 5 , 1 , 2 , 5 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Remove command should serialize correctly (empty node list)" , ( ) => { const cc = new AssociationCCRemove ( fakeDriver , { nodeId : 2 , groupId : 5 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ AssociationCommand . Remove , 5 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; } ) ;