import { CommandClasses } from "@zwave-js/core" ; import type { Driver } from "../driver/Driver" ; import { createEmptyMockDriver } from "../test/mocks" ; import { LanguageCC , LanguageCCGet , LanguageCCReport , LanguageCCSet , LanguageCommand , } from "./LanguageCC" ; const fakeDriver = createEmptyMockDriver ( ) as unknown as Driver ; function buildCCBuffer ( payload ) { return Buffer . concat ( [ Buffer . from ( [ CommandClasses . Language , ] ) , payload , ] ) ; } describe ( "lib/commandclass/LanguageCC => " , ( ) => { it ( "the Get command should serialize correctly" , ( ) => { const cc = new LanguageCCGet ( fakeDriver , { nodeId : 1 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ LanguageCommand . Get , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Set command should serialize correctly (w/o country code)" , ( ) => { const cc = new LanguageCCSet ( fakeDriver , { nodeId : 2 , language : "deu" , } ) ; const expected = buildCCBuffer ( Buffer . from ( [ LanguageCommand . Set , 0x64 , 0x65 , 0x75 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Set command should serialize correctly (w/ country code)" , ( ) => { const cc = new LanguageCCSet ( fakeDriver , { nodeId : 2 , language : "deu" , country : "DE" , } ) ; const expected = buildCCBuffer ( Buffer . from ( [ LanguageCommand . Set , 0x64 , 0x65 , 0x75 , 0x44 , 0x45 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Report command should be deserialized correctly (w/o country code)" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ LanguageCommand . Report , 0x64 , 0x65 , 0x75 , ] ) ) ; const cc = new LanguageCCReport ( fakeDriver , { nodeId : 4 , data : ccData , } ) ; expect ( cc . language ) . toBe ( "deu" ) ; expect ( cc . country ) . toBeUndefined ( ) ; } ) ; it ( "the Report command should be deserialized correctly (w/ country code)" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ LanguageCommand . Report , 0x64 , 0x65 , 0x75 , 0x44 , 0x45 , ] ) ) ; const cc = new LanguageCCReport ( fakeDriver , { nodeId : 4 , data : ccData , } ) ; expect ( cc . language ) . toBe ( "deu" ) ; expect ( cc . country ) . toBe ( "DE" ) ; } ) ; it ( "deserializing an unsupported command should return an unspecified version of LanguageCC" , ( ) => { const serializedCC = buildCCBuffer ( Buffer . from ( [ 255 ] ) ) ; const cc = new LanguageCC ( fakeDriver , { nodeId : 4 , data : serializedCC , } ) ; expect ( cc . constructor ) . toBe ( LanguageCC ) ; } ) ; } ) ;