@@ -174,7 +174,7 @@ describe('Base Service', () => {
174
174
authenticator : AUTHENTICATOR ,
175
175
} ) ;
176
176
177
- const fromCredsFile = testService . readOptionsFromExternalConfig ( ) ;
177
+ const fromCredsFile = testService . readOptionsFromExternalConfig ( DEFAULT_NAME ) ;
178
178
179
179
expect ( fromCredsFile . serviceUrl ) . toBe ( serviceUrl ) ;
180
180
expect ( fromCredsFile . disableSslVerification ) . toBe ( disableSsl ) ;
@@ -338,6 +338,54 @@ describe('Base Service', () => {
338
338
} ) ;
339
339
} ) . toThrow ( / R e v i s e t h e s e c r e d e n t i a l s / ) ;
340
340
} ) ;
341
+
342
+ it ( 'should have the default baseOptions values when instantiating' , ( ) => {
343
+ const testService = new TestService ( {
344
+ authenticator : AUTHENTICATOR ,
345
+ } ) ;
346
+ expect ( testService . baseOptions . serviceUrl ) . toEqual ( DEFAULT_URL ) ;
347
+ expect ( testService . baseOptions . disableSslVerification ) . toEqual ( false ) ;
348
+ expect ( testService . baseOptions . qs ) . toBeDefined ( ) ;
349
+ expect ( testService . baseOptions . qs ) . toEqual ( EMPTY_OBJECT ) ;
350
+ } ) ;
351
+
352
+ it ( 'should configure service by calling configureService method after instantiating' , ( ) => {
353
+ const testService = new TestService ( {
354
+ authenticator : AUTHENTICATOR ,
355
+ } ) ;
356
+
357
+ expect ( testService . baseOptions . serviceUrl ) . toEqual (
358
+ 'https://gateway.watsonplatform.net/test/api'
359
+ ) ;
360
+ expect ( testService . baseOptions . disableSslVerification ) . toEqual ( false ) ;
361
+
362
+ readExternalSourcesMock . mockImplementation ( ( ) => ( {
363
+ url : 'abc123.com' ,
364
+ disableSsl : true ,
365
+ } ) ) ;
366
+
367
+ testService . configureService ( DEFAULT_NAME ) ;
368
+
369
+ expect ( readExternalSourcesMock ) . toHaveBeenCalled ( ) ;
370
+ expect ( testService . baseOptions . serviceUrl ) . toEqual ( 'abc123.com' ) ;
371
+ expect ( testService . baseOptions . disableSslVerification ) . toEqual ( true ) ;
372
+ } ) ;
373
+
374
+ it ( 'configureService method should throw error if service name is not provided' , ( ) => {
375
+ const testService = new TestService ( {
376
+ authenticator : AUTHENTICATOR ,
377
+ } ) ;
378
+ const fakeError = new Error ( 'Error configuring service. Service name is required.' ) ;
379
+ let err ;
380
+
381
+ try {
382
+ testService . configureService ( ) ;
383
+ } catch ( e ) {
384
+ err = e ;
385
+ }
386
+
387
+ expect ( err ) . toStrictEqual ( fakeError ) ;
388
+ } ) ;
341
389
} ) ;
342
390
343
391
function TestService ( options ) {
0 commit comments