Skip to content

Commit 1a73735

Browse files
author
Joe Goggins
committed
Particle constructor calls setDefaultAuth when defaultAuth option is truthy
1 parent 72c15e1 commit 1a73735

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Particle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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 = {};

test/Particle.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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', () => {

0 commit comments

Comments
 (0)