forked from mboocannon/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.ts
More file actions
79 lines (71 loc) · 2.79 KB
/
Copy pathClient.ts
File metadata and controls
79 lines (71 loc) · 2.79 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
72
73
74
75
76
77
78
79
/**
* -------------------------------------------------------------------------------------------
* 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 "isomorphic-fetch";
import { Client } from "../../src/Client";
import { AuthProvider } from "../../src/IAuthProvider";
import { ClientOptions } from "../../src/IClientOptions";
import { Options } from "../../src/IOptions";
import { DummyAuthenticationProvider } from "../DummyAuthenticationProvider";
import { DummyHTTPMessageHandler } from "../DummyHTTPMessageHandler";
describe("Client.ts", () => {
/* tslint:disable: no-string-literal */
describe("initWithMiddleware", () => {
const dummyAuthProvider = new DummyAuthenticationProvider();
const dummyHTTPHandler = new DummyHTTPMessageHandler();
it("Should throw an error in case if both auth provider and custom middleware is passed", () => {
try {
const options: ClientOptions = {
authProvider: dummyAuthProvider,
middleware: dummyHTTPHandler,
};
const client: Client = Client.initWithMiddleware(options);
throw new Error("Something wrong with the ambiguity check");
} catch (error) {
assert.equal(error.name, "AmbiguityInInitialization");
}
});
it("Should return client instance for an authentication provider", () => {
const options: ClientOptions = {
authProvider: dummyAuthProvider,
};
const client: Client = Client.initWithMiddleware(options);
assert.isTrue(client instanceof Client);
assert.isDefined(client["httpClient"]);
});
it("Should return client instance for a custom middleware chain", () => {
const options: ClientOptions = {
middleware: dummyHTTPHandler,
};
const client: Client = Client.initWithMiddleware(options);
assert.isTrue(client instanceof Client);
assert.isDefined(client["httpClient"]);
});
it("Should throw error in case of neither auth provider nor custom middleware is passed", () => {
try {
const options: ClientOptions = {};
Client.initWithMiddleware(options);
throw new Error("Something wrong with the client initialization check");
} catch (error) {
assert.equal(error.name, "InvalidMiddlewareChain");
}
});
});
describe("init", () => {
it("Should return a client instance with default authentication provider and default middleware chain", () => {
const provider: AuthProvider = (done) => {
done(null, "dummy_token");
};
const options: Options = {
authProvider: provider,
};
const client: Client = Client.init(options);
assert.isDefined(client["httpClient"]);
});
});
/* tslint:enable: no-string-literal */
});