File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ class Particle {
2323 * @param {Object } options Options for this API call Options to be used for all requests (see [Defaults](../src/Defaults.js))
2424 */
2525 constructor ( options = { } ) {
26+ if ( options . defaultAuth ) {
27+ this . setDefaultAuth ( options . defaultAuth ) ;
28+ }
29+
2630 // todo - this seems a bit dangerous - would be better to put all options/context in a contained object
2731 Object . assign ( this , Defaults , options ) ;
2832 this . context = { } ;
Original file line number Diff line number Diff line change @@ -130,6 +130,20 @@ describe('ParticleAPI', () => {
130130 } ) ;
131131 } ) ;
132132
133+ describe ( 'without defaultAuth' , ( ) => {
134+ it ( 'does NOT call .setDefaultAuth(defaultAuth) unless provided value is truthy' , ( ) => {
135+ sinon . stub ( api , 'setDefaultAuth' ) ;
136+ expect ( api . setDefaultAuth ) . to . have . property ( 'callCount' , 0 ) ;
137+ } ) ;
138+ } ) ;
139+
140+ describe ( 'with defaultAuth' , ( ) => {
141+ it ( 'calls .setDefaultAuth(defaultAuth) when provided defaultAuth value is truthy' , ( ) => {
142+ sinon . stub ( Particle . prototype , 'setDefaultAuth' ) ;
143+ api = new Particle ( { defaultAuth : 'foo' } ) ;
144+ expect ( api . setDefaultAuth ) . to . have . property ( 'callCount' , 1 ) ;
145+ } ) ;
146+ } ) ;
133147 } ) ;
134148
135149 describe ( 'trackingIdentity' , ( ) => {
You can’t perform that action at this time.
0 commit comments