@@ -33,109 +33,113 @@ const propertyStrVal = 'ok';
3333const propertyBoolName = 'boolean' ;
3434const propertyBoolVal = true ;
3535
36- it ( 'ArduinoCloud connection' , ( done ) => {
36+ describe ( 'Test the library basic functionalities' , ( ) => {
37+ afterAll ( ( ) => ArduinoCloud . disconnect ( ) ) ;
38+
39+ it ( 'ArduinoCloud connection' , ( done ) => {
3740 /* global token */
38- ArduinoCloud . connect ( {
39- token,
40- onDisconnect : ( message ) => {
41- if ( message . errorCode !== 0 ) {
42- throw Error ( message ) ;
43- }
44- } ,
45- } )
46- . then ( ( ) => {
47- done ( ) ;
41+ ArduinoCloud . connect ( {
42+ token,
43+ onDisconnect : ( message ) => {
44+ if ( message . errorCode !== 0 ) {
45+ throw Error ( message ) ;
46+ }
47+ } ,
4848 } )
49- . catch ( ( error ) => {
50- throw new Error ( error ) ;
51- } ) ;
52- } ) ;
49+ . then ( ( ) => {
50+ done ( ) ;
51+ } )
52+ . catch ( ( error ) => {
53+ throw new Error ( error ) ;
54+ } ) ;
55+ } ) ;
5356
54- it ( 'Property name must be a string in sendProperty' , ( done ) => {
55- try {
56- ArduinoCloud . sendProperty ( deviceId , undefined , propertyIntValue ) ;
57- } catch ( error ) {
58- if ( error . message === 'Name must be a valid string' ) {
59- done ( ) ;
57+ it ( 'Property name must be a string in sendProperty' , ( done ) => {
58+ try {
59+ ArduinoCloud . sendProperty ( deviceId , undefined , propertyIntValue ) ;
60+ } catch ( error ) {
61+ if ( error . message === 'Name must be a valid string' ) {
62+ done ( ) ;
63+ }
6064 }
61- }
62- } ) ;
65+ } ) ;
6366
64- it ( 'Simulate client write to cloud monitor' , ( done ) => {
65- ArduinoCloud . writeCloudMonitor ( deviceId , `this is a test ${ Math . random ( ) } ` ) . then ( ( ) => {
66- done ( ) ;
67- } , ( error ) => {
68- throw new Error ( error ) ;
67+ it ( 'Simulate client write to cloud monitor' , ( done ) => {
68+ ArduinoCloud . writeCloudMonitor ( deviceId , `this is a test ${ Math . random ( ) } ` ) . then ( ( ) => {
69+ done ( ) ;
70+ } , ( error ) => {
71+ throw new Error ( error ) ;
72+ } ) ;
6973 } ) ;
70- } ) ;
7174
72- it ( 'Simulate device write to cloud monitor' , ( done ) => {
73- const cloudMonitorInputTopic = `/a/d/${ deviceId } /s/o` ;
74- ArduinoCloud . sendMessage ( cloudMonitorInputTopic , `this is a test ${ Math . random ( ) } ` ) . then ( ( ) => {
75- done ( ) ;
76- } , ( error ) => {
77- throw new Error ( error ) ;
75+ it ( 'Simulate device write to cloud monitor' , ( done ) => {
76+ const cloudMonitorInputTopic = `/a/d/${ deviceId } /s/o` ;
77+ ArduinoCloud . sendMessage ( cloudMonitorInputTopic , `this is a test ${ Math . random ( ) } ` ) . then ( ( ) => {
78+ done ( ) ;
79+ } , ( error ) => {
80+ throw new Error ( error ) ;
81+ } ) ;
7882 } ) ;
79- } ) ;
8083
81- it ( 'Simulate device write and client read his message from cloud monitor' , ( done ) => {
82- const cloudMonitorInputTopic = `/a/d/${ deviceId } /s/o` ;
84+ it ( 'Simulate device write and client read his message from cloud monitor' , ( done ) => {
85+ const cloudMonitorInputTopic = `/a/d/${ deviceId } /s/o` ;
8386
84- const cb = ( ) => {
87+ const cb = ( ) => {
8588 // console.log(`[${new Date()}] Message from monitor: ${message}`);
86- done ( ) ;
87- } ;
89+ done ( ) ;
90+ } ;
8891
89- ArduinoCloud . openCloudMonitor ( deviceId , cb ) . then ( ( ) => {
92+ ArduinoCloud . openCloudMonitor ( deviceId , cb ) . then ( ( ) => {
9093 // console.log(`Subscribed to topic: ${topic}`);
91- const message = `This is a test ${ new Date ( ) } ` ;
92- ArduinoCloud . sendMessage ( cloudMonitorInputTopic , message ) . then ( ( ) => {
93- // console.log(`[${new Date()}] Message sent to monitor: [${message}]`);
94+ const message = `This is a test ${ new Date ( ) } ` ;
95+ ArduinoCloud . sendMessage ( cloudMonitorInputTopic , message ) . then ( ( ) => {
96+ // console.log(`[${new Date()}] Message sent to monitor: [${message}]`);
97+ } , ( error ) => {
98+ throw new Error ( error ) ;
99+ } ) ;
94100 } , ( error ) => {
95101 throw new Error ( error ) ;
96102 } ) ;
97- } , ( error ) => {
98- throw new Error ( error ) ;
99103 } ) ;
100- } ) ;
101104
102- it ( 'Simulate client read integer property sent by device' , ( done ) => {
103- ArduinoCloud . onPropertyValue ( thingId , propertyIntName , ( value ) => {
104- if ( value === propertyIntValue ) {
105- done ( ) ;
106- }
107- } ) . then ( ( ) => {
108- ArduinoCloud . sendPropertyAsDevice ( deviceId , thingId , propertyIntName , propertyIntValue ) ;
105+ it ( 'Simulate client read integer property sent by device' , ( done ) => {
106+ ArduinoCloud . onPropertyValue ( thingId , propertyIntName , ( value ) => {
107+ if ( value === propertyIntValue ) {
108+ done ( ) ;
109+ }
110+ } ) . then ( ( ) => {
111+ ArduinoCloud . sendPropertyAsDevice ( deviceId , thingId , propertyIntName , propertyIntValue ) ;
112+ } ) ;
109113 } ) ;
110- } ) ;
111114
112- it ( 'Simulate client read float property sent by device' , ( done ) => {
113- ArduinoCloud . onPropertyValue ( thingId , propertyFloatName , ( value ) => {
114- if ( value === propertyFloatVal ) {
115- done ( ) ;
116- }
117- } ) . then ( ( ) => {
118- ArduinoCloud . sendPropertyAsDevice ( deviceId , thingId , propertyFloatName , propertyFloatVal ) ;
115+ it ( 'Simulate client read float property sent by device' , ( done ) => {
116+ ArduinoCloud . onPropertyValue ( thingId , propertyFloatName , ( value ) => {
117+ if ( value === propertyFloatVal ) {
118+ done ( ) ;
119+ }
120+ } ) . then ( ( ) => {
121+ ArduinoCloud . sendPropertyAsDevice ( deviceId , thingId , propertyFloatName , propertyFloatVal ) ;
122+ } ) ;
119123 } ) ;
120- } ) ;
121124
122- it ( 'Simulate client read string property sent by device' , ( done ) => {
123- ArduinoCloud . onPropertyValue ( thingId , propertyStrName , ( value ) => {
124- if ( value === propertyStrVal ) {
125- done ( ) ;
126- }
127- } ) . then ( ( ) => {
128- ArduinoCloud . sendPropertyAsDevice ( deviceId , thingId , propertyStrName , propertyStrVal ) ;
125+ it ( 'Simulate client read string property sent by device' , ( done ) => {
126+ ArduinoCloud . onPropertyValue ( thingId , propertyStrName , ( value ) => {
127+ if ( value === propertyStrVal ) {
128+ done ( ) ;
129+ }
130+ } ) . then ( ( ) => {
131+ ArduinoCloud . sendPropertyAsDevice ( deviceId , thingId , propertyStrName , propertyStrVal ) ;
132+ } ) ;
129133 } ) ;
130- } ) ;
131134
132- it ( 'Simulate client read boolean property sent by device' , ( done ) => {
133- ArduinoCloud . onPropertyValue ( thingId , propertyBoolName , ( value ) => {
134- if ( value === propertyBoolVal ) {
135- ArduinoCloud . disconnect ( ) ;
136- done ( ) ;
137- }
138- } ) . then ( ( ) => {
139- ArduinoCloud . sendPropertyAsDevice ( deviceId , thingId , propertyBoolName , propertyBoolVal ) ;
135+ it ( 'Simulate client read boolean property sent by device' , ( done ) => {
136+ ArduinoCloud . onPropertyValue ( thingId , propertyBoolName , ( value ) => {
137+ if ( value === propertyBoolVal ) {
138+ ArduinoCloud . disconnect ( ) ;
139+ done ( ) ;
140+ }
141+ } ) . then ( ( ) => {
142+ ArduinoCloud . sendPropertyAsDevice ( deviceId , thingId , propertyBoolName , propertyBoolVal ) ;
143+ } ) ;
140144 } ) ;
141145} ) ;
0 commit comments