Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad252b2
commit 89bec95
Showing
3 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* `LiveConnectAPIError` error. | ||
* | ||
* References: | ||
* - http://msdn.microsoft.com/en-us/library/live/hh243648.aspx#error | ||
* | ||
* @constructor | ||
* @param {String} [message] | ||
* @param {String} [code] | ||
* @api public | ||
*/ | ||
function LiveConnectAPIError(message, code) { | ||
Error.call(this); | ||
Error.captureStackTrace(this, arguments.callee); | ||
this.name = 'LiveConnectAPIError'; | ||
this.message = message; | ||
this.code = code; | ||
} | ||
|
||
/** | ||
* Inherit from `Error`. | ||
*/ | ||
LiveConnectAPIError.prototype.__proto__ = Error.prototype; | ||
|
||
|
||
/** | ||
* Expose `LiveConnectAPIError`. | ||
*/ | ||
module.exports = LiveConnectAPIError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var WindowsLiveStrategy = require('../lib/strategy'); | ||
|
||
|
||
describe('Strategy#userProfile', function() { | ||
|
||
var strategy = new WindowsLiveStrategy({ | ||
clientID: 'ABC123', | ||
clientSecret: 'secret' | ||
}, | ||
function() {}); | ||
|
||
// mock | ||
strategy._oauth2.get = function(url, accessToken, callback) { | ||
if (url != 'https://apis.live.net/v5.0/me') { return callback(new Error('wrong url argument')); } | ||
if (accessToken != 'token') { return callback(new Error('wrong token argument')); } | ||
|
||
var body = '{ \ | ||
"error": { \ | ||
"code": "request_token_expired", \ | ||
"message": "The provided access token has expired." \ | ||
} \ | ||
}'; | ||
|
||
callback({ statusCode: 401, data: body }); | ||
} | ||
|
||
describe('encountering an API error', function() { | ||
var err, profile; | ||
|
||
before(function(done) { | ||
strategy.userProfile('token', function(e, p) { | ||
err = e; | ||
profile = p; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should error', function() { | ||
expect(err).to.be.an.instanceOf(Error); | ||
expect(err.constructor.name).to.equal('LiveConnectAPIError'); | ||
expect(err.message).to.equal('The provided access token has expired.'); | ||
expect(err.code).to.equal('request_token_expired'); | ||
}); | ||
|
||
it('should not load profile', function() { | ||
expect(profile).to.be.undefined; | ||
}); | ||
}); | ||
|
||
}); |