@@ -370,6 +370,18 @@ describe('ParticleAPI', () => {
370370 } ) ;
371371
372372 describe ( '.listDevices' , ( ) => {
373+ describe ( 'uses effective auth' , ( ) => {
374+ afterEach ( ( ) => {
375+ sinon . restore ( ) ;
376+ } ) ;
377+ it ( 'calls this._getEffectiveAuth' , async ( ) => {
378+ sinon . stub ( api , '_getEffectiveAuth' ) ;
379+ sinon . stub ( api , 'get' ) ; // don't actually call the real method
380+ await api . listDevices ( props ) ;
381+ expect ( api . _getEffectiveAuth ) . to . have . property ( 'callCount' , 1 ) ;
382+ } ) ;
383+ } ) ;
384+
373385 describe ( 'user scope' , ( ) => {
374386 it ( 'generates request' , ( ) => {
375387 return api . listDevices ( props ) . then ( ( results ) => {
@@ -2728,4 +2740,29 @@ describe('ParticleAPI', () => {
27282740 expect ( api . _defaultAuth ) . to . eql ( auth ) ;
27292741 } ) ;
27302742 } ) ;
2743+
2744+ describe ( '_getEffectiveAuth(auth)' , ( ) => {
2745+ afterEach ( ( ) => {
2746+ sinon . restore ( ) ;
2747+ } ) ;
2748+
2749+ it ( 'returns provided value when provided value is truthy' , ( ) => {
2750+ const expectedReturnValue = 'pass through' ;
2751+ expect ( api . _getEffectiveAuth ( expectedReturnValue ) ) . to . eql ( expectedReturnValue ) ;
2752+ } ) ;
2753+
2754+ it ( 'returns value of _defaultAuth when provided value is NOT truthy' , ( ) => {
2755+ const providedValue = undefined ;
2756+ const expectedReturnValue = 'default auth value' ;
2757+ api . setDefaultAuth ( expectedReturnValue ) ;
2758+ expect ( api . _getEffectiveAuth ( providedValue ) ) . to . eql ( expectedReturnValue ) ;
2759+ } ) ;
2760+
2761+ it ( 'returns undefined when both provided value and _defaultAuth are NOT truthy' , ( ) => {
2762+ const providedValue = undefined ;
2763+ const expectedReturnValue = undefined ;
2764+ api . setDefaultAuth ( undefined ) ;
2765+ expect ( api . _getEffectiveAuth ( providedValue ) ) . to . eql ( expectedReturnValue ) ;
2766+ } ) ;
2767+ } ) ;
27312768} ) ;
0 commit comments