forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetryHandlerOptions.ts
More file actions
104 lines (93 loc) · 3.49 KB
/
Copy pathRetryHandlerOptions.ts
File metadata and controls
104 lines (93 loc) · 3.49 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* -------------------------------------------------------------------------------------------
* 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 { RetryHandlerOptions, ShouldRetry } from "../../src/middleware/options/RetryHandlerOptions";
describe("RetryHandlerOptions.ts", () => {
/* tslint:disable: no-string-literal */
describe("Constructor", () => {
it("Should use default values if not given", () => {
try {
const options = new RetryHandlerOptions();
assert.equal(options["delay"], RetryHandlerOptions["DEFAULT_DELAY"]);
assert.equal(options["maxRetries"], RetryHandlerOptions["DEFAULT_MAX_RETRIES"]);
assert.equal(options["shouldRetry"], RetryHandlerOptions["DEFAULT_SHOULD_RETRY"]);
} catch (error) {
throw error;
}
});
it("Should throw error for both delay and maxRetries are higher than the limit", () => {
try {
const options = new RetryHandlerOptions(1000, 1000);
throw new Error("Something wrong with the delay and maxRetries max limit validation");
} catch (error) {
assert.equal(error.name, "MaxLimitExceeded");
}
});
it("Should throw error for delay is higher than the limit", () => {
try {
const options = new RetryHandlerOptions(1000, 2);
throw new Error("Something wrong with the delay max limit validation");
} catch (error) {
assert.equal(error.name, "MaxLimitExceeded");
}
});
it("Should throw error for maxRetries is higher than the limit", () => {
try {
const options = new RetryHandlerOptions(1, 2000);
throw new Error("Something wrong with the maxRetries max limit validation");
} catch (error) {
assert.equal(error.name, "MaxLimitExceeded");
}
});
it("Should throw error for both delay and maxRetries are negative", () => {
try {
const options = new RetryHandlerOptions(-1, -100);
throw new Error("Something wrong with the delay and maxRetries max limit validation");
} catch (error) {
assert.equal(error.name, "MinExpectationNotMet");
}
});
it("Should throw error for delay is negative", () => {
try {
const options = new RetryHandlerOptions(-5, 2);
throw new Error("Something wrong with the delay max limit validation");
} catch (error) {
assert.equal(error.name, "MinExpectationNotMet");
}
});
it("Should throw error for maxRetries is negative", () => {
try {
const options = new RetryHandlerOptions(1, -10);
throw new Error("Something wrong with the maxRetries max limit validation");
} catch (error) {
assert.equal(error.name, "MinExpectationNotMet");
}
});
it("Should accept all the given values", () => {
try {
const delay: number = 1;
const maxRetries: number = 3;
const shouldRetry: ShouldRetry = (d, a, req, o, res) => {
return false;
};
const options = new RetryHandlerOptions(delay, maxRetries, shouldRetry);
assert.equal(options.delay, delay);
assert.equal(options.maxRetries, maxRetries);
assert.equal(options.shouldRetry, shouldRetry);
} catch (error) {
throw error;
}
});
});
describe("getMaxDelay", () => {
it("Should return the max delay value", () => {
const options = new RetryHandlerOptions();
assert.equal(options.getMaxDelay(), RetryHandlerOptions["MAX_DELAY"]);
});
});
/* tslint:enable: no-string-literal */
});