Skip to content

Commit c00fac2

Browse files
author
REDMOND\lahuey
committed
Update unit test
Switch to isomorphic fetch
1 parent f31d3e9 commit c00fac2

File tree

9 files changed

+42
-57
lines changed

9 files changed

+42
-57
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import 'whatwg-fetch';
1+
import 'isomorphic-fetch';

lib/spec/core/responseHandling.js

Lines changed: 15 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/spec/core/responseHandling.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/GraphRequest.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Promise } from 'es6-promise';
2-
import 'whatwg-fetch';
2+
import 'isomorphic-fetch';
33
import { Options, URLComponents, GraphRequestCallback } from "./common";
44
export declare class GraphRequest {
55
config: Options;

lib/src/GraphRequest.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/GraphRequest.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
"@types/node": "^9.4.0",
1414
"browserify": "^13.1.0",
1515
"mocha": "^3.2.0",
16-
"typescript": "^2.2.1",
17-
"whatwg-fetch": "^2.0.3"
16+
"typescript": "^2.2.1"
1817
},
1918
"scripts": {
2019
"build": "tsc && node node-browserify.js > lib/graph-js-sdk-web.js",
2120
"test": "mocha lib/spec/core",
2221
"test:types": "tsc --p spec/types && mocha spec/types"
2322
},
2423
"dependencies": {
25-
"es6-promise": "^4.1.0"
24+
"es6-promise": "^4.1.0",
25+
"isomorphic-fetch": "^2.2.1"
2626
},
2727
"repository": {
2828
"type": "git",

spec/core/responseHandling.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import 'whatwg-fetch';
1+
import 'isomorphic-fetch';
22
import {ResponseHandler} from "../../src/ResponseHandler"
33
import {GraphError} from '../../src/common'
44

55
import * as mocha from 'mocha'
66

77
import * as assert from 'assert';
88

9-
const _200_SUPERAGENT_RES_BODY: any = { a: 1 };
10-
const _200_SUPERAGENT_RES_INIT: ResponseInit = { status: 200 };
11-
const _200_SUPERAGENT_RES: Response =
12-
new Response(_200_SUPERAGENT_RES_BODY, _200_SUPERAGENT_RES_INIT);
9+
const _200_RES_BODY: any = { a: 1 };
10+
const _200_RES_INIT: ResponseInit = { status: 200 };
11+
const _200_RES: Response =
12+
new Response(_200_RES_BODY, _200_RES_INIT);
1313

14-
const _500_SUPERAGENT_RES_BODY: any = {
14+
const _500_RES_BODY: any = {
1515
error: {
1616
"code": "SearchEvents",
1717
"message": "The parameter $search is not currently supported on the Events resource.",
@@ -20,48 +20,40 @@ const _500_SUPERAGENT_RES_BODY: any = {
2020
"date": "2016-11-17T18:37:45"
2121
}
2222
}
23-
};
24-
const _500_SUPERAGENT_RES_INIT: ResponseInit = { status: 500 };
25-
const _500_SUPERAGENT_RES: Response =
26-
new Response(_200_SUPERAGENT_RES_BODY, _200_SUPERAGENT_RES_INIT);
23+
};
2724

28-
const error: Error = new Error();
29-
(error as any).statusCode = 404;
25+
const _500_RES_INIT: ResponseInit = { status: 500 };
26+
const _500_RES: Response =
27+
new Response(_500_RES_BODY, _500_RES_INIT);
3028

3129
describe('#handleResponse()', function() {
3230
it('passes through response to callback', function() {
33-
ResponseHandler.init(_200_SUPERAGENT_RES, null, _200_SUPERAGENT_RES_BODY, (err:GraphError, res) => {
34-
assert.equal(res, _200_SUPERAGENT_RES.body);
31+
ResponseHandler.init(_200_RES, null, _200_RES_BODY, (err:GraphError, res) => {
32+
assert.equal(res, _200_RES.body);
3533
});
3634
});
3735

3836
it('200 response => err is null', function() {
39-
ResponseHandler.init(_200_SUPERAGENT_RES, null, _200_SUPERAGENT_RES_BODY, (err:GraphError, res) => {
37+
ResponseHandler.init(_200_RES, null, _200_RES_BODY, (err:GraphError, res) => {
4038
assert.equal(err, null);
4139
});
4240
});
4341
});
4442

4543
describe('#ParseResponse()', function() {
4644
it('extracts code and request-id from the JSON body of 500 errors', function() {
47-
ResponseHandler.init(_500_SUPERAGENT_RES, null, _500_SUPERAGENT_RES_BODY, (err:GraphError, res) => {
48-
assert.equal(err.code, _500_SUPERAGENT_RES_BODY.error.code);
49-
assert.equal(err.requestId, _500_SUPERAGENT_RES_BODY.error.innerError["request-id"]);
45+
ResponseHandler.init(_500_RES, null, _500_RES_BODY, (err:GraphError, res) => {
46+
assert.equal(err.code, _500_RES_BODY.error.code);
47+
assert.equal(err.requestId, _500_RES_BODY.error.innerError["request-id"]);
5048
});
5149
});
5250
});
5351

5452
describe('#ParseError()', function() {
55-
it('500 error => res param in callback is null', function() {
53+
it('res param in callback is null', function() {
5654
ResponseHandler.init(null, null, null, (err:GraphError, res) => {
5755
assert.equal(res, null);
56+
assert.equal(err.statusCode, -1);
5857
});
5958
});
60-
61-
it('parses a 404 superagent error', function() {
62-
let graphErr = ResponseHandler.ParseError(error);
63-
ResponseHandler.init(null, null, null, (err:GraphError, res) => {
64-
assert.equal(graphErr.statusCode, 404);
65-
});
66-
})
6759
});

src/GraphRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Promise } from 'es6-promise'
2-
import 'whatwg-fetch';
2+
import 'isomorphic-fetch';
33

44
import { Options, URLComponents, GraphError, oDataQueryNames, GraphRequestCallback } from "./common"
55
import { ResponseHandler } from "./ResponseHandler"

0 commit comments

Comments
 (0)