Skip to content

Commit 87a3ccb

Browse files
author
Edgar Sherman
committed
test(OAuthClient) Add Additional unit tests for OAuthClient (intuit#47)
- Added tests for OAuthClient to bring test coverage higher - re-worked logic in OAuthClient.createError to be more consistent
1 parent 4cdaee8 commit 87a3ccb

File tree

3 files changed

+445
-212
lines changed

3 files changed

+445
-212
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
"test"
3737
],
3838
"check-coverage": true,
39-
"lines": 75,
40-
"statements": 75,
41-
"functions": 71,
42-
"branches": 56,
39+
"lines": 85,
40+
"statements": 85,
41+
"functions": 80,
42+
"branches": 75,
4343
"reporter": [
4444
"lcov",
4545
"text",
@@ -81,6 +81,7 @@
8181
"devDependencies": {
8282
"body-parser": "^1.15.2",
8383
"chai": "^4.1.2",
84+
"chai-as-promised": "^7.1.1",
8485
"chance": "^1.0.13",
8586
"cors": "^2.8.1",
8687
"coveralls": "^3.0.6",

src/OAuthClient.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,19 +583,32 @@ OAuthClient.prototype.loadResponseFromJWKsURI = function loadResponseFromJWKsURI
583583
*/
584584
OAuthClient.prototype.createError = function createError(e, authResponse) {
585585
if (!authResponse || authResponse.body === '') {
586-
e.error = e.originalMessage || '';
586+
e.error = (authResponse && authResponse.response.statusText) || e.message || '';
587587
e.authResponse = authResponse || '';
588-
e.intuit_tid = authResponse.headers().intuit_tid || '';
589-
e.originalMessage = authResponse.response.statusText || '';
590-
e.error = authResponse.response.statusText || '';
591-
e.error_description = authResponse.response.statusText || '';
588+
e.intuit_tid = (authResponse && authResponse.headers().intuit_tid) || '';
589+
e.originalMessage = e.message || '';
590+
e.error_description = (authResponse && authResponse.response.statusText) || '';
592591
return e;
593592
}
594593

595-
e.authResponse = authResponse || null;
594+
e.authResponse = authResponse;
596595
e.originalMessage = e.message;
597-
e.error = ('error' in authResponse.getJson() ? authResponse.getJson().error : '');
598-
e.error_description = ('error_description' in authResponse.getJson() ? authResponse.getJson().error_description : '');
596+
597+
e.error = '';
598+
if ('error' in authResponse.getJson()) {
599+
e.error = authResponse.getJson().error;
600+
} else if (authResponse.response.statusText) {
601+
e.error = authResponse.response.statusText;
602+
} else if (e.message) {
603+
e.error = e.message;
604+
}
605+
606+
e.error_description = '';
607+
if ('error_description' in authResponse.getJson()) {
608+
e.error_description = authResponse.getJson().error_description;
609+
} else if (authResponse.response.statusText) {
610+
e.error_description = authResponse.response.statusText;
611+
}
599612
e.intuit_tid = authResponse.headers().intuit_tid;
600613

601614
return e;

0 commit comments

Comments
 (0)