Skip to content

Commit 5d40cdc

Browse files
committed
Adding documentation
1 parent 7084038 commit 5d40cdc

21 files changed

+167
-161
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ samples/browser/src/graph-js-sdk.js
2424
samples/browser/src/graph-es-sdk.js
2525

2626

27-
spec/**/secrets.ts
27+
test/development/secrets.ts
2828

2929
.nyc_output/*

.huskyrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"hooks": {
3-
"pre-commit": "npm run build"
3+
"pre-commit": "npm run pre-build && git add src/Version.ts && lint-staged && npm run lint && npm run test"
44
}
55
}

.prettierignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ src/**/*.js
66
src/**/*.js.map
77
src/**/*.d.ts
88

9-
spec/**/*.js
10-
spec/**/*.js.map
11-
spec/**/*.d.ts
9+
test/**/*.js
10+
test/**/*.js.map
11+
test/**/*.d.ts

.vscode/launch.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"request": "launch",
1919
"name": "Run Content tests",
2020
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
21-
"args": ["${workspaceRoot}/lib/spec/content/*.js"],
21+
"args": ["${workspaceRoot}/lib/test/common/**/*.js"],
2222
"cwd": "${workspaceRoot}",
2323
"preLaunchTask": "Run Compile",
2424
"outFiles": [],
@@ -29,7 +29,7 @@
2929
"request": "launch",
3030
"name": "Run Core tests",
3131
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
32-
"args": ["${workspaceRoot}/lib/spec/core/*.js"],
32+
"args": ["${workspaceRoot}/lib/test/common/core/*.js"],
3333
"cwd": "${workspaceRoot}",
3434
"preLaunchTask": "Run Compile",
3535
"outFiles": [],
@@ -40,7 +40,7 @@
4040
"request": "launch",
4141
"name": "Run Middleware tests",
4242
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
43-
"args": ["${workspaceRoot}/lib/spec/middleware/*.js"],
43+
"args": ["${workspaceRoot}/lib/test/common/middleware/*.js"],
4444
"cwd": "${workspaceRoot}",
4545
"preLaunchTask": "Run Compile",
4646
"outFiles": [],
@@ -51,7 +51,7 @@
5151
"request": "launch",
5252
"name": "Run Tasks tests",
5353
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
54-
"args": ["${workspaceRoot}/lib/spec/tasks/*.js"],
54+
"args": ["${workspaceRoot}/lib/test/common/tasks/*.js"],
5555
"cwd": "${workspaceRoot}",
5656
"preLaunchTask": "Run Compile",
5757
"outFiles": [],
@@ -62,7 +62,7 @@
6262
"request": "launch",
6363
"name": "Run Workload tests",
6464
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
65-
"args": ["${workspaceRoot}/spec/development/workload/*.js"],
65+
"args": ["${workspaceRoot}/test/common/development/workload/*.js"],
6666
"cwd": "${workspaceRoot}",
6767
"preLaunchTask": "Run Compile",
6868
"outFiles": [],

lib/.npmignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.npmignore
2-
spec/
2+
test/

package.json

+95-95
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,96 @@
11
{
2-
"name": "@microsoft/microsoft-graph-client",
3-
"version": "2.1.0-Preview.2",
4-
"description": "Microsoft Graph Client Library",
5-
"license": "MIT",
6-
"main": "lib/src/index.js",
7-
"module": "lib/es/index.js",
8-
"typings": "lib/src/index",
9-
"files": [
10-
"lib/",
11-
"src/"
12-
],
13-
"types": "./lib/src/index.d.ts",
14-
"dependencies": {
15-
"@babel/runtime": "^7.4.4",
16-
"esm": "^3.2.25",
17-
"fs": "0.0.1-security",
18-
"karma": "^5.2.3",
19-
"tslib": "^1.9.3"
20-
},
21-
"devDependencies": {
22-
"@babel/core": "^7.4.4",
23-
"@babel/plugin-transform-runtime": "^7.4.4",
24-
"@babel/preset-env": "^7.4.4",
25-
"@istanbuljs/nyc-config-typescript": "^1.0.1",
26-
"@microsoft/microsoft-graph-types": "^1.28.0",
27-
"@types/chai": "^4.2.14",
28-
"@types/mocha": "^5.2.7",
29-
"@types/node": "^12.0.10",
30-
"chai": "^4.2.0",
31-
"form-data": "^2.3.3",
32-
"gulp": "^4.0.2",
33-
"husky": "^2.2.0",
34-
"isomorphic-fetch": "^3.0.0",
35-
"karma-chai": "^0.1.0",
36-
"karma-chrome-launcher": "^3.1.0",
37-
"karma-firefox-launcher": "^2.1.0",
38-
"karma-mocha": "^2.0.1",
39-
"karma-typescript": "^5.2.0",
40-
"lint-staged": "^8.1.5",
41-
"mocha": "^6.2.3",
42-
"msal": "^1.0.0",
43-
"nyc": "^15.1.0",
44-
"prettier": "^1.17.0",
45-
"rollup": "^1.10.1",
46-
"rollup-plugin-babel": "^4.3.2",
47-
"rollup-plugin-commonjs": "^10.0.1",
48-
"rollup-plugin-node-resolve": "^5.2.0",
49-
"rollup-plugin-terser": "^5.0.0",
50-
"source-map-support": "^0.5.19",
51-
"ts-node": "^9.0.0",
52-
"tslint": "^5.16.0",
53-
"tslint-config-prettier": "^1.18.0",
54-
"typescript": "^3.4.5",
55-
"uglify-es": "^3.3.9"
56-
},
57-
"scripts": {
58-
"setVersion": "gulp setVersion",
59-
"build:es": "tsc --p tsconfig-es.json",
60-
"build:cjs": "tsc --p tsconfig-cjs.json",
61-
"pre-build": "npm run setVersion",
62-
"build": "npm run pre-build && npm run build:cjs && npm run build:es && rollup -c",
63-
"test": "npm run test:cjs && npm run test:esm",
64-
"test:development": "tsc --p test/tsconfig-test-cjs.json && mocha 'lib/test/development/**/*.js' --require isomorphic-fetch --grep PageIterator",
65-
"lint": "tslint --project ./tsconfig-cjs.json -c tslint.json",
66-
"format:css": "prettier --write \"**/*.css\"",
67-
"format:html": "prettier --write \"**/*.html\"",
68-
"format:js": "prettier --write \"**/*.js\"",
69-
"format:json": "prettier --write \"**/*.json\"",
70-
"format:md": "prettier --write \"**/*.md\"",
71-
"format:rc": "prettier --write --parser json \"**/.*rc\"",
72-
"format:ts": "prettier --write \"**/*.ts\"",
73-
"format": "npm run format:css && npm run format:html && npm run format:js && npm run format:json && npm run format:md && npm run format:rc && npm run format:ts",
74-
"prepack": "npm install && npm run build && npm run test",
75-
"test:coverage": "TS_NODE_PROJECT='./tsconfig-cjs.json' nyc mocha --require isomorphic-fetch -r ts-node/register test/common/**/*.ts && mocha --require isomorphic-fetch -r ts-node/register test/common/**/*.ts",
76-
"test:cjs": "tsc -p tsconfig-cjs.json && mocha 'lib/test/common/**/*.js' --require isomorphic-fetch && mocha 'lib/test/node/**/*.js' --require isomorphic-fetch",
77-
"test:esm": "tsc -p tsconfig-es.json && mocha 'lib/es/test/common/**/*.js' --require esm --require isomorphic-fetch && mocha 'lib/es/test/node/**/*.js' --require esm --require isomorphic-fetch",
78-
"karma": "karma start --single-run --browsers ChromeHeadless karma.conf.js"
79-
},
80-
"repository": {
81-
"type": "git",
82-
"url": "https://github.com/microsoftgraph/msgraph-sdk-javascript.git"
83-
},
84-
"nyc": {
85-
"all": true,
86-
"cache": false,
87-
"exclude": [
88-
"samples/",
89-
"*.js",
90-
"lib/"
91-
],
92-
"include": [
93-
"src/"
94-
]
95-
}
96-
}
2+
"name": "@microsoft/microsoft-graph-client",
3+
"version": "2.1.0-Preview.2",
4+
"description": "Microsoft Graph Client Library",
5+
"license": "MIT",
6+
"main": "lib/src/index.js",
7+
"module": "lib/es/index.js",
8+
"typings": "lib/src/index",
9+
"files": [
10+
"lib/",
11+
"src/"
12+
],
13+
"types": "./lib/src/index.d.ts",
14+
"dependencies": {
15+
"@babel/runtime": "^7.4.4",
16+
"tslib": "^1.9.3"
17+
},
18+
"devDependencies": {
19+
"@babel/core": "^7.4.4",
20+
"@babel/plugin-transform-runtime": "^7.4.4",
21+
"@babel/preset-env": "^7.4.4",
22+
"@istanbuljs/nyc-config-typescript": "^1.0.1",
23+
"@microsoft/microsoft-graph-types": "^1.28.0",
24+
"@types/chai": "^4.2.14",
25+
"@types/mocha": "^5.2.7",
26+
"@types/node": "^12.0.10",
27+
"chai": "^4.2.0",
28+
"form-data": "^2.3.3",
29+
"gulp": "^4.0.2",
30+
"husky": "^2.2.0",
31+
"isomorphic-fetch": "^3.0.0",
32+
"karma-chai": "^0.1.0",
33+
"karma-chrome-launcher": "^3.1.0",
34+
"karma-firefox-launcher": "^2.1.0",
35+
"karma-mocha": "^2.0.1",
36+
"karma-typescript": "^5.2.0",
37+
"lint-staged": "^8.1.5",
38+
"mocha": "^6.2.3",
39+
"msal": "^1.0.0",
40+
"nyc": "^15.1.0",
41+
"prettier": "^1.17.0",
42+
"rollup": "^1.10.1",
43+
"rollup-plugin-babel": "^4.3.2",
44+
"rollup-plugin-commonjs": "^10.0.1",
45+
"rollup-plugin-node-resolve": "^5.2.0",
46+
"rollup-plugin-terser": "^5.0.0",
47+
"source-map-support": "^0.5.19",
48+
"ts-node": "^9.0.0",
49+
"tslint": "^5.16.0",
50+
"tslint-config-prettier": "^1.18.0",
51+
"typescript": "^3.4.5",
52+
"uglify-es": "^3.3.9",
53+
"esm": "^3.2.25",
54+
"fs": "0.0.1-security",
55+
"karma": "^5.2.3"
56+
},
57+
"scripts": {
58+
"setVersion": "gulp setVersion",
59+
"build:es": "tsc --p tsconfig-es.json",
60+
"build:cjs": "tsc --p tsconfig-cjs.json",
61+
"pre-build": "npm run setVersion",
62+
"build": "npm run pre-build && npm run build:cjs && npm run build:es && rollup -c",
63+
"test": "npm run test:cjs && npm run test:esm",
64+
"test:development": "tsc --p test/tsconfig-test-development.json && mocha 'lib/test/development/**/*.js' --require isomorphic-fetch",
65+
"lint": "tslint --project ./tsconfig-cjs.json -c tslint.json",
66+
"format:css": "prettier --write \"**/*.css\"",
67+
"format:html": "prettier --write \"**/*.html\"",
68+
"format:js": "prettier --write \"**/*.js\"",
69+
"format:json": "prettier --write \"**/*.json\"",
70+
"format:md": "prettier --write \"**/*.md\"",
71+
"format:rc": "prettier --write --parser json \"**/.*rc\"",
72+
"format:ts": "prettier --write \"**/*.ts\"",
73+
"format": "npm run format:css && npm run format:html && npm run format:js && npm run format:json && npm run format:md && npm run format:rc && npm run format:ts",
74+
"prepack": "npm install && npm run build && npm run test",
75+
"test:coverage": "TS_NODE_PROJECT='./tsconfig-cjs.json' nyc mocha --require isomorphic-fetch -r ts-node/register test/common/**/*.ts && mocha --require isomorphic-fetch -r ts-node/register test/common/**/*.ts",
76+
"test:cjs": "tsc -p tsconfig-cjs.json && mocha 'lib/test/common/**/*.js' --require isomorphic-fetch && mocha 'lib/test/node/**/*.js' --require isomorphic-fetch",
77+
"test:esm": "tsc -p tsconfig-es.json && mocha 'lib/es/test/common/**/*.js' --require esm --require isomorphic-fetch && mocha 'lib/es/test/node/**/*.js' --require esm --require isomorphic-fetch",
78+
"karma": "karma start --single-run --browsers ChromeHeadless karma.conf.js"
79+
},
80+
"repository": {
81+
"type": "git",
82+
"url": "https://github.com/microsoftgraph/msgraph-sdk-javascript.git"
83+
},
84+
"nyc": {
85+
"all": true,
86+
"cache": false,
87+
"exclude": [
88+
"samples/",
89+
"*.js",
90+
"lib/"
91+
],
92+
"include": [
93+
"src/"
94+
]
95+
}
96+
}

samples/node/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ You can get an access token by doing the following:
77
1. Rename [secrets.sample.json](./secrets.sample.json) to secrets.json
88
2. Go to Graph Explorer.
99
3. Login with the account you want to use to run the node samples.
10-
4. Open the F12 dev tools.
11-
5. Type tokenPlease() into the console to get an access token.
12-
6. Copy the access token and put it into the secrets.json file and save the file.
10+
4. Click on the Access token tab option to get an access token.
11+
5. Copy the access token and put it into the secrets.json file and save the file.
1312

1413
## Run Sample
1514

src/middleware/ChaosHandler.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ export class ChaosHandler implements Middleware {
6262
/**
6363
* Generates responseHeader
6464
* @private
65-
* @param {number} statusCode - the status code to be returned for the request
65+
* @param {ChaosHandlerOptions} chaosHandlerOptions - The ChaosHandlerOptions object
6666
* @param {string} requestID - request id
6767
* @param {string} requestDate - date of the request
6868
* @returns response Header
6969
*/
7070
private createResponseHeaders(chaosHandlerOptions: ChaosHandlerOptions, requestID: string, requestDate: string) {
71-
7271
const responseHeader: Headers = chaosHandlerOptions.headers ? new Headers(chaosHandlerOptions.headers) : new Headers();
7372
responseHeader.append("Cache-Control", "no-store");
7473
responseHeader.append("request-id", requestID);
@@ -88,21 +87,19 @@ export class ChaosHandler implements Middleware {
8887
/**
8988
* Generates responseBody
9089
* @private
91-
* @param {number} statusCode - the status code to be returned for the request
92-
* @param {string} statusMessage - the status message to be returned for the request
90+
* @param {ChaosHandlerOptions} options - The ChaosHandlerOptions object
9391
* @param {string} requestID - request id
9492
* @param {string} requestDate - date of the request
95-
* @param {any?} requestBody - the request body to be returned for the request
96-
* @returns response body
93+
* * @returns response body
9794
*/
98-
private createResponseBody(options: ChaosHandlerOptions, requestID: string, requestDate: string) {
99-
if (options.responseBody) {
100-
return options.responseBody;
95+
private createResponseBody(chaosHandlerOptions: ChaosHandlerOptions, requestID: string, requestDate: string) {
96+
if (chaosHandlerOptions.responseBody) {
97+
return chaosHandlerOptions.responseBody;
10198
}
10299
let body: any;
103-
if (options.statusCode >= 400) {
104-
const codeMessage: string = httpStatusCode[options.statusCode];
105-
const errMessage: string = options.statusMessage;
100+
if (chaosHandlerOptions.statusCode >= 400) {
101+
const codeMessage: string = httpStatusCode[chaosHandlerOptions.statusCode];
102+
const errMessage: string = chaosHandlerOptions.statusMessage;
106103

107104
body = {
108105
error: {

src/middleware/options/ChaosHandlerOptions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ChaosHandlerOptions implements MiddlewareOptions {
5656
public responseBody: any;
5757

5858
/**
59-
* The response body to be returned in the response
59+
* The response headers to be returned in the response
6060
*
6161
* @public
6262
*/
@@ -73,13 +73,13 @@ export class ChaosHandlerOptions implements MiddlewareOptions {
7373
* @param {any?} responseBody - The response body to be returned in the response
7474
* @returns An instance of ChaosHandlerOptions
7575
*/
76-
public constructor(chaosStrategy: ChaosStrategy = ChaosStrategy.RANDOM, statusMessage: string = "Some error Happened", statusCode?: number, chaosPercentage?: number, responseBody?: any, headers?:Headers) {
76+
public constructor(chaosStrategy: ChaosStrategy = ChaosStrategy.RANDOM, statusMessage: string = "Some error Happened", statusCode?: number, chaosPercentage?: number, responseBody?: any, headers?: Headers) {
7777
this.chaosStrategy = chaosStrategy;
7878
this.statusCode = statusCode;
7979
this.statusMessage = statusMessage;
8080
this.chaosPercentage = chaosPercentage !== undefined ? chaosPercentage : 10;
8181
this.responseBody = responseBody;
82-
this.headers = headers
82+
this.headers = headers;
8383
if (this.chaosPercentage > 100) {
8484
throw new Error("Error Pecentage can not be more than 100");
8585
}

test/Tests.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The /test folder consists of unit tests written using the following testing tools
2+
3+
- mocha
4+
- chai
5+
- karma
6+
- @istanbuljs/nyc-config-typescript
7+
8+
Scripts used
9+
10+
- `npm run test` - To run unit tests in test/common and test/node.
11+
- `npm run test:cjs` - To run unit tests in test/common and test/node compiled as CommonJS modules.
12+
- `npm run test:esm` - To run unit tests in test/common and test/node compiled as ESM modules.
13+
- `npm run test:development` - To run tests in test/development folder.
14+
- `npm run test:coverage` - To get the test code coverage after running the tests.
15+
- `npm run karma` - To run the units tests in test/common and test/browser folders on a headless browser.

test/browser/BrowserTests.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This folder contains unit tests which are browser-specific. Example - The tests in [GraphResponseHandler](./core/GraphResponseHandler.ts) requires the DOMParser which is a browser functionality.
2+
3+
Karma is used for testing the code in browsers. To run the unit tests using karma run the following steps -
4+
5+
- Run the script `npm install`.
6+
- Run the script `npm run karma`.

spec/core/GraphClientError.ts renamed to test/common/core/GraphClientError.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { assert } from "chai";
99

10-
import { GraphClientError } from "../../src/GraphClientError";
10+
import { GraphClientError } from "../../../src/GraphClientError";
1111

1212
describe("GraphClientError", () => {
1313
const message = "test";

test/common/core/HTTPClient.ts

-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ describe("HTTPClient.ts", () => {
3636
}
3737
});
3838

39-
it("Should throw an error if middleware is passed as null", () => {
40-
try {
41-
const client = new HTTPClient(null);
42-
} catch (error) {
43-
assert.equal(error.name, "InvalidMiddlewareChain");
44-
}
45-
});
46-
4739
it("Should throw an error if middleware is passed as an empty array", () => {
4840
try {
4941
const client = new HTTPClient(...[]);

0 commit comments

Comments
 (0)