1+ import test from 'node:test'
2+ import assert from 'node:assert'
3+
4+ import { ApplicationTag , BACNetAppData , CalendarWeekDay , CalendarDateRange } from '../../src'
5+
6+ test . describe ( 'ApplicationData types' , ( ) => {
7+ test ( 'should correctly type OCTET_STRING as number[]' , ( ) => {
8+ const octetStringData : BACNetAppData < ApplicationTag . OCTET_STRING > = {
9+ type : ApplicationTag . OCTET_STRING ,
10+ value : [ 0x01 , 0x02 , 0x03 , 0x04 ] ,
11+ }
12+
13+ assert . strictEqual ( octetStringData . type , ApplicationTag . OCTET_STRING )
14+ assert . ok ( Array . isArray ( octetStringData . value ) )
15+ assert . strictEqual ( octetStringData . value [ 0 ] , 0x01 )
16+ } )
17+
18+ test ( 'should correctly type BOOLEAN as boolean' , ( ) => {
19+ const booleanData : BACNetAppData < ApplicationTag . BOOLEAN > = {
20+ type : ApplicationTag . BOOLEAN ,
21+ value : true ,
22+ }
23+
24+ assert . strictEqual ( booleanData . type , ApplicationTag . BOOLEAN )
25+ assert . strictEqual ( typeof booleanData . value , 'boolean' )
26+ assert . strictEqual ( booleanData . value , true )
27+ } )
28+
29+ test ( 'should correctly type EMPTYLIST as unknown[]' , ( ) => {
30+ const emptyListData : BACNetAppData < ApplicationTag . EMPTYLIST > = {
31+ type : ApplicationTag . EMPTYLIST ,
32+ value : [ ] ,
33+ }
34+
35+ assert . strictEqual ( emptyListData . type , ApplicationTag . EMPTYLIST )
36+ assert . ok ( Array . isArray ( emptyListData . value ) )
37+ assert . strictEqual ( emptyListData . value . length , 0 )
38+ } )
39+
40+ test ( 'should correctly type WEEKNDAY as CalendarWeekDay' , ( ) => {
41+ const weekDayData : BACNetAppData < ApplicationTag . WEEKNDAY > = {
42+ type : ApplicationTag . WEEKNDAY ,
43+ value : {
44+ len : 4 ,
45+ month : 1 ,
46+ week : 1 ,
47+ wday : 1 ,
48+ } as CalendarWeekDay ,
49+ }
50+
51+ assert . strictEqual ( weekDayData . type , ApplicationTag . WEEKNDAY )
52+ assert . strictEqual ( typeof weekDayData . value , 'object' )
53+ assert . strictEqual ( weekDayData . value . month , 1 )
54+ } )
55+
56+ test ( 'should correctly type DATERANGE as CalendarDateRange' , ( ) => {
57+ const dateRangeData : BACNetAppData < ApplicationTag . DATERANGE > = {
58+ type : ApplicationTag . DATERANGE ,
59+ value : {
60+ len : 16 ,
61+ startDate : {
62+ len : 8 ,
63+ value : new Date ( '2024-01-01' ) ,
64+ } ,
65+ endDate : {
66+ len : 8 ,
67+ value : new Date ( '2024-12-31' ) ,
68+ } ,
69+ } as CalendarDateRange ,
70+ }
71+
72+ assert . strictEqual ( dateRangeData . type , ApplicationTag . DATERANGE )
73+ assert . strictEqual ( typeof dateRangeData . value , 'object' )
74+ assert . strictEqual ( dateRangeData . value . len , 16 )
75+ } )
76+
77+ test ( 'should correctly type DATETIME as Date' , ( ) => {
78+ const dateTimeData : BACNetAppData < ApplicationTag . DATETIME > = {
79+ type : ApplicationTag . DATETIME ,
80+ value : new Date ( '2024-01-01T12:00:00Z' ) ,
81+ }
82+
83+ assert . strictEqual ( dateTimeData . type , ApplicationTag . DATETIME )
84+ assert . ok ( dateTimeData . value instanceof Date )
85+ assert . strictEqual ( dateTimeData . value . getFullYear ( ) , 2024 )
86+ } )
87+
88+ test ( 'should allow complex structures with unknown for untyped entries' , ( ) => {
89+ const complexData : BACNetAppData < ApplicationTag . WEEKLY_SCHEDULE > = {
90+ type : ApplicationTag . WEEKLY_SCHEDULE ,
91+ value : {
92+ // This can be any complex structure for now
93+ scheduleId : 123 ,
94+ entries : [
95+ { day : 'Monday' , schedule : [ ] } ,
96+ { day : 'Tuesday' , schedule : [ ] } ,
97+ ] ,
98+ } as unknown ,
99+ }
100+
101+ assert . strictEqual ( complexData . type , ApplicationTag . WEEKLY_SCHEDULE )
102+ assert . strictEqual ( typeof complexData . value , 'object' )
103+ } )
104+ } )
0 commit comments