forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPClient.ts
More file actions
71 lines (65 loc) · 2.17 KB
/
Copy pathHTTPClient.ts
File metadata and controls
71 lines (65 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { assert } from "chai";
import { HTTPClient } from "../../src/HTTPClient";
import { Context } from "../../src/IContext";
import { FetchOptions } from "../../src/IFetchOptions";
import { DummyHTTPMessageHandler } from "../DummyHTTPMessageHandler";
describe("HTTPClient.ts", () => {
const httpMessageHandler: DummyHTTPMessageHandler = new DummyHTTPMessageHandler();
const httpClient: HTTPClient = new HTTPClient(httpMessageHandler);
/* tslint:disable: no-string-literal */
describe("constructor", () => {
it("Should create an instance and populate middleware member", () => {
assert.isDefined(httpClient["middleware"]);
assert.equal(httpClient["middleware"], httpMessageHandler);
});
});
/* tslint:enable: no-string-literal */
describe("sendRequest", async () => {
it("Should throw error for invalid request options incase if the url and options are passed", async () => {
try {
const url = "dummy_url";
const context: Context = {
request: url,
};
await httpClient.sendRequest(context);
throw new Error("Something wrong with the context validation");
} catch (error) {
assert.equal(error.name, "InvalidRequestOptions");
}
});
it("Should execute for context object with Request instance", async () => {
try {
const request: Request = new Request("dummy_url", {
method: "GET",
});
const context: Context = {
request,
};
await httpClient.sendRequest(context);
} catch (error) {
throw error;
}
});
it("Should execute for context object with request uri and options", async () => {
try {
const url = "dummy_url";
const options: FetchOptions = {
method: "GET",
};
const context: Context = {
request: url,
options,
};
await httpClient.sendRequest(context);
} catch (error) {
throw error;
}
});
});
});