Skip to content

Commit 5f973d4

Browse files
Merge branch 'master' into dev
2 parents f813590 + f150d0f commit 5f973d4

13 files changed

+48
-43
lines changed

spec/content/BatchRequestContent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ describe("BatchRequestContent.ts", () => {
4848
this.timeout(20 * 1000);
4949
it("Should Create BatchRequestContent instance with no requests", (done) => {
5050
const batchReq = new BatchRequestContent();
51-
assert.equal(batchReq.constructor.name, "BatchRequestContent");
51+
assert(batchReq instanceof BatchRequestContent);
5252
done();
5353
});
5454

5555
it("Should create BatchRequestContent instance with empty array", (done) => {
5656
const batchReq = new BatchRequestContent([]);
57-
assert.equal(batchReq.constructor.name, "BatchRequestContent");
57+
assert(batchReq instanceof BatchRequestContent);
5858
done();
5959
});
6060

spec/middleware/MiddlewareControl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ describe("MiddlewareControl.ts", () => {
3636
describe("getMiddlewareOption", () => {
3737
it("Should return the middleware option for a given class name", () => {
3838
const middlewareControl = new MiddlewareControl([dummyHandlerOption]);
39-
const retryOptions: DummyHandlerOptions = middlewareControl.getMiddlewareOptions(dummyHandlerOption.constructor.name) as DummyHandlerOptions;
39+
const retryOptions: DummyHandlerOptions = middlewareControl.getMiddlewareOptions(dummyHandlerOption.constructor as () => any) as DummyHandlerOptions;
4040
assert.isDefined(retryOptions);
4141
assert.equal(dummyHandlerOption, retryOptions);
4242
});
4343

4444
it("Should return undefined for unknown class name", () => {
4545
const middlewareControl = new MiddlewareControl([dummyHandlerOption]);
46-
const retryOptions = middlewareControl.getMiddlewareOptions("NotAvailableHandlerOption");
46+
const retryOptions = middlewareControl.getMiddlewareOptions(() => "NotAvailableHandlerOption");
4747
assert.isUndefined(retryOptions);
4848
});
4949
});

spec/middleware/TelemetryHandlerOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("TelemetryHandlerOptions.ts", () => {
2727
middlewareControl: new MiddlewareControl(),
2828
};
2929
TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
30-
const options: TelemetryHandlerOptions = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions.name) as TelemetryHandlerOptions;
30+
const options: TelemetryHandlerOptions = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions) as TelemetryHandlerOptions;
3131
assert.equal(options["featureUsage"], FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
3232
});
3333

@@ -37,7 +37,7 @@ describe("TelemetryHandlerOptions.ts", () => {
3737
middlewareControl: new MiddlewareControl([new TelemetryHandlerOptions()]),
3838
};
3939
TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
40-
const options: TelemetryHandlerOptions = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions.name) as TelemetryHandlerOptions;
40+
const options: TelemetryHandlerOptions = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions) as TelemetryHandlerOptions;
4141
assert.equal(options["featureUsage"], FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
4242
});
4343

@@ -46,7 +46,7 @@ describe("TelemetryHandlerOptions.ts", () => {
4646
request: "url",
4747
};
4848
TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
49-
const options: TelemetryHandlerOptions = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions.name) as TelemetryHandlerOptions;
49+
const options: TelemetryHandlerOptions = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions) as TelemetryHandlerOptions;
5050
assert.equal(options["featureUsage"], FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
5151
});
5252
});

spec/tasks/PageIterator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ describe("PageIterator.ts", () => {
6161
describe("Constructor", () => {
6262
it("Should create instance without nextLink", () => {
6363
const pageIterator = new PageIterator(client, getPageCollection(), truthyCallback);
64-
assert.equal(pageIterator.constructor.name, "PageIterator");
64+
assert(pageIterator instanceof PageIterator);
6565
});
6666

6767
it("Should create instance with nextLink", () => {
6868
const pageIterator = new PageIterator(client, getPageCollectionWithNext(), truthyCallback);
69-
assert.equal(pageIterator.constructor.name, "PageIterator");
69+
assert(pageIterator instanceof PageIterator);
7070
});
7171
});
7272

src/GraphErrorHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class GraphErrorHandler {
8989
let gError: GraphError;
9090
if (error && error.error) {
9191
gError = GraphErrorHandler.constructErrorFromResponse(error, statusCode);
92-
} else if (error && error.constructor.name === "Error") {
92+
} else if (error instanceof Error) {
9393
gError = GraphErrorHandler.constructError(error, statusCode);
9494
} else {
9595
gError = new GraphError(statusCode);

src/GraphRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ export class GraphRequest {
551551
method: RequestMethod.POST,
552552
body: serializeContent(content),
553553
headers:
554-
content.constructor !== undefined && content.constructor.name === "FormData"
554+
content instanceof FormData
555555
? {}
556556
: {
557557
"Content-Type": "application/json",

src/middleware/AuthenticationHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class AuthenticationHandler implements Middleware {
6464
try {
6565
let options: AuthenticationHandlerOptions;
6666
if (context.middlewareControl instanceof MiddlewareControl) {
67-
options = context.middlewareControl.getMiddlewareOptions(AuthenticationHandlerOptions.name) as AuthenticationHandlerOptions;
67+
options = context.middlewareControl.getMiddlewareOptions(AuthenticationHandlerOptions) as AuthenticationHandlerOptions;
6868
}
6969
let authenticationProvider: AuthenticationProvider;
7070
let authenticationProviderOptions: AuthenticationProviderOptions;

src/middleware/MiddlewareControl.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export class MiddlewareControl {
2020
* @private
2121
* A member holding map of MiddlewareOptions
2222
*/
23-
private middlewareOptions: Map<string, MiddlewareOptions>;
23+
// tslint:disable-next-line:ban-types
24+
private middlewareOptions: Map<Function, MiddlewareOptions>;
2425

2526
/**
2627
* @public
@@ -30,31 +31,38 @@ export class MiddlewareControl {
3031
* @returns The instance of MiddlewareControl
3132
*/
3233
public constructor(middlewareOptions: MiddlewareOptions[] = []) {
33-
this.middlewareOptions = new Map<string, MiddlewareOptions>();
34+
// tslint:disable-next-line:ban-types
35+
this.middlewareOptions = new Map<Function, MiddlewareOptions>();
3436
for (const option of middlewareOptions) {
35-
const name = option.constructor.name;
36-
this.middlewareOptions.set(name, option);
37+
const fn = option.constructor;
38+
this.middlewareOptions.set(fn, option);
3739
}
3840
}
3941

4042
/**
4143
* @public
42-
* To get the middleware option using the class name of the option
43-
* @param {string} name - The class name of the strongly typed option class
44+
* To get the middleware option using the class of the option
45+
* @param {Function} fn - The class of the strongly typed option class
4446
* @returns The middleware option
47+
* @example
48+
* // if you wanted to return the middleware option associated with this class (MiddlewareControl)
49+
* // call this function like this:
50+
* getMiddlewareOptions(MiddlewareControl)
4551
*/
46-
public getMiddlewareOptions(name: string): MiddlewareOptions {
47-
return this.middlewareOptions.get(name);
52+
// tslint:disable-next-line:ban-types
53+
public getMiddlewareOptions(fn: Function): MiddlewareOptions {
54+
return this.middlewareOptions.get(fn);
4855
}
4956

5057
/**
5158
* @public
52-
* To set the middleware options using the class name of the option
53-
* @param {string} name - The class name of the strongly typed option class
59+
* To set the middleware options using the class of the option
60+
* @param {Function} fn - The class of the strongly typed option class
5461
* @param {MiddlewareOptions} option - The strongly typed middleware option
5562
* @returns nothing
5663
*/
57-
public setMiddlewareOptions(name: string, option: MiddlewareOptions): void {
58-
this.middlewareOptions.set(name, option);
64+
// tslint:disable-next-line:ban-types
65+
public setMiddlewareOptions(fn: Function, option: MiddlewareOptions): void {
66+
this.middlewareOptions.set(fn, option);
5967
}
6068
}

src/middleware/RedirectHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class RedirectHandler implements Middleware {
173173
private getOptions(context: Context): RedirectHandlerOptions {
174174
let options: RedirectHandlerOptions;
175175
if (context.middlewareControl instanceof MiddlewareControl) {
176-
options = context.middlewareControl.getMiddlewareOptions(this.options.constructor.name) as RedirectHandlerOptions;
176+
options = context.middlewareControl.getMiddlewareOptions(RedirectHandlerOptions) as RedirectHandlerOptions;
177177
}
178178
if (typeof options === "undefined") {
179179
options = Object.assign(new RedirectHandlerOptions(), this.options);

src/middleware/RetryHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class RetryHandler implements Middleware {
155155
private getOptions(context: Context): RetryHandlerOptions {
156156
let options: RetryHandlerOptions;
157157
if (context.middlewareControl instanceof MiddlewareControl) {
158-
options = context.middlewareControl.getMiddlewareOptions(this.options.constructor.name) as RetryHandlerOptions;
158+
options = context.middlewareControl.getMiddlewareOptions(this.options.constructor) as RetryHandlerOptions;
159159
}
160160
if (typeof options === "undefined") {
161161
options = Object.assign(new RetryHandlerOptions(), this.options);

0 commit comments

Comments
 (0)