File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ class Monitor {
66
66
this . _api = this . constructor . _api ;
67
67
}
68
68
69
- async data ( ) {
69
+ async loadData ( ) {
70
70
return this . _api . axios
71
71
. get ( this . _api . monitorUrl ( this . key ) )
72
72
. then ( ( res ) => {
Original file line number Diff line number Diff line change @@ -201,6 +201,31 @@ describe('Monitor', () => {
201
201
expect ( stub ) . to . be . calledWith ( 'https://eu.cronitor.link/ping/apiKey123/a-key' ) ;
202
202
done ( ) ;
203
203
} ) ;
204
+
205
+ it ( 'should load monitor data' , async function ( ) {
206
+ const monitor = new cronitor . Monitor ( 'a-key' ) ;
207
+ const mockResponse = { data : { name : 'Test Monitor' , type : 'job' } } ;
208
+ const stub = sinon . stub ( monitor . _api . axios , 'get' ) . resolves ( mockResponse ) ;
209
+
210
+ const result = await monitor . loadData ( ) ;
211
+
212
+ expect ( stub ) . to . be . calledWith ( monitor . _api . monitorUrl ( monitor . key ) ) ;
213
+ expect ( result ) . to . deep . equal ( mockResponse . data ) ;
214
+ expect ( monitor . data ) . to . deep . equal ( mockResponse . data ) ;
215
+ } ) ;
216
+
217
+ it ( 'should return error response when loadData fails' , async function ( ) {
218
+ const monitor = new cronitor . Monitor ( 'a-key' ) ;
219
+ const errorResponse = { status : 404 , data : { error : 'Not Found' } } ;
220
+ const stub = sinon . stub ( monitor . _api . axios , 'get' )
221
+ . rejects ( { response : errorResponse } ) ;
222
+
223
+ const result = await monitor . loadData ( ) ;
224
+
225
+ expect ( stub ) . to . be . calledWith ( monitor . _api . monitorUrl ( monitor . key ) ) ;
226
+ expect ( result ) . to . deep . equal ( errorResponse ) ;
227
+ expect ( monitor . data ) . to . be . null ;
228
+ } ) ;
204
229
} ) ;
205
230
206
231
describe ( 'Event' , ( ) => {
You can’t perform that action at this time.
0 commit comments