Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ module.exports = {
app_token: appToken
};

this._authenticate(requestData, function(responseData) {
this._authenticate(requestData, function(err, responseData) {
if (err) {
callback(err);

return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to pass the err all the way to the top, like this: https://github.com/podio/podio-js/blob/master/lib/auth.js#L104

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, was assuming that _authenticate will call the callback itself, but we don't pass it the callback. Will fix


this._onAccessTokenAcquired(responseData, callback);
}.bind(this));
},
Expand Down
17 changes: 16 additions & 1 deletion test/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('auth', function() {
var authData = { access_token: 'a321' };
var callback = function() {};
var host = {
_authenticate: sinon.stub().callsArgWith(1, authData),
_authenticate: sinon.stub().callsArgWith(1, null, authData),
_onAccessTokenAcquired: sinon.stub()
};

Expand All @@ -209,6 +209,21 @@ describe('auth', function() {
expect(host._onAccessTokenAcquired.calledWithExactly(authData, callback)).toBe(true);
});

it('should not call _onAccessTokenAcquired when auth failed and call the callback', function() {
var callback = sinon.stub();
var err = new Error();
var host = {
_authenticate: sinon.stub().callsArgWith(1, err),
_onAccessTokenAcquired: sinon.stub()
};

auth.authenticateWithApp.call(host, 123, 'e123', callback);

expect(host._onAccessTokenAcquired.called).toBe(false);
expect(callback.called).toBe(true);
expect(callback.calledWithExactly(err)).toBe(true);
});

});

describe('_getAuthFromStore', function() {
Expand Down