@oneuptime/common 11.2.1 → 11.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import BadDataException from "../../Types/Exception/BadDataException";
|
|
2
|
+
import Currency from "../../Types/Currency";
|
|
3
|
+
|
|
4
|
+
describe("Currency", () => {
|
|
5
|
+
describe("convertToDecimalPlaces", () => {
|
|
6
|
+
test("rounds to two decimal places by default", () => {
|
|
7
|
+
expect(Currency.convertToDecimalPlaces(1.236)).toBe(1.24);
|
|
8
|
+
expect(Currency.convertToDecimalPlaces(1.231)).toBe(1.23);
|
|
9
|
+
expect(Currency.convertToDecimalPlaces(3.14159)).toBe(3.14);
|
|
10
|
+
expect(Currency.convertToDecimalPlaces(99.994)).toBe(99.99);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("leaves values without fractional digits unchanged", () => {
|
|
14
|
+
expect(Currency.convertToDecimalPlaces(0)).toBe(0);
|
|
15
|
+
expect(Currency.convertToDecimalPlaces(100)).toBe(100);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("rounds negative values", () => {
|
|
19
|
+
expect(Currency.convertToDecimalPlaces(-1.236)).toBe(-1.24);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("honours a custom number of decimal places", () => {
|
|
23
|
+
expect(Currency.convertToDecimalPlaces(1.23456, 3)).toBe(1.235);
|
|
24
|
+
expect(Currency.convertToDecimalPlaces(1.26, 1)).toBe(1.3);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("ceils the value when decimalPlaces is 0", () => {
|
|
28
|
+
expect(Currency.convertToDecimalPlaces(1.1, 0)).toBe(2);
|
|
29
|
+
expect(Currency.convertToDecimalPlaces(5, 0)).toBe(5);
|
|
30
|
+
expect(Currency.convertToDecimalPlaces(4.0001, 0)).toBe(5);
|
|
31
|
+
expect(Currency.convertToDecimalPlaces(-2.5, 0)).toBe(-2);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("throws BadDataException when decimalPlaces is negative", () => {
|
|
35
|
+
expect(() => {
|
|
36
|
+
Currency.convertToDecimalPlaces(1.5, -1);
|
|
37
|
+
}).toThrowError(BadDataException);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("returns a number", () => {
|
|
41
|
+
expect(typeof Currency.convertToDecimalPlaces(1.236)).toBe("number");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import BadDataException from "../../../Types/Exception/BadDataException";
|
|
2
|
+
import MonitorType, {
|
|
3
|
+
MonitorTypeCategory,
|
|
4
|
+
MonitorTypeHelper,
|
|
5
|
+
MonitorTypeProps,
|
|
6
|
+
} from "../../../Types/Monitor/MonitorType";
|
|
7
|
+
|
|
8
|
+
describe("MonitorTypeHelper", () => {
|
|
9
|
+
describe("getMonitorTypeCategories", () => {
|
|
10
|
+
test("returns a non-empty list of categories with labels and types", () => {
|
|
11
|
+
const categories: Array<MonitorTypeCategory> =
|
|
12
|
+
MonitorTypeHelper.getMonitorTypeCategories();
|
|
13
|
+
|
|
14
|
+
expect(Array.isArray(categories)).toBe(true);
|
|
15
|
+
expect(categories.length).toBeGreaterThan(0);
|
|
16
|
+
|
|
17
|
+
for (const category of categories) {
|
|
18
|
+
expect(typeof category.label).toBe("string");
|
|
19
|
+
expect(category.label.length).toBeGreaterThan(0);
|
|
20
|
+
expect(Array.isArray(category.monitorTypes)).toBe(true);
|
|
21
|
+
expect(category.monitorTypes.length).toBeGreaterThan(0);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("getAllMonitorTypeProps", () => {
|
|
27
|
+
test("returns props with a unique monitorType, title and description each", () => {
|
|
28
|
+
const props: Array<MonitorTypeProps> =
|
|
29
|
+
MonitorTypeHelper.getAllMonitorTypeProps();
|
|
30
|
+
|
|
31
|
+
expect(props.length).toBeGreaterThan(0);
|
|
32
|
+
|
|
33
|
+
const seen: Set<MonitorType> = new Set<MonitorType>();
|
|
34
|
+
for (const prop of props) {
|
|
35
|
+
expect(typeof prop.title).toBe("string");
|
|
36
|
+
expect(prop.title.length).toBeGreaterThan(0);
|
|
37
|
+
expect(typeof prop.description).toBe("string");
|
|
38
|
+
expect(prop.description.length).toBeGreaterThan(0);
|
|
39
|
+
expect(seen.has(prop.monitorType)).toBe(false);
|
|
40
|
+
seen.add(prop.monitorType);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("isTelemetryMonitor", () => {
|
|
46
|
+
test.each([
|
|
47
|
+
MonitorType.Logs,
|
|
48
|
+
MonitorType.Metrics,
|
|
49
|
+
MonitorType.Traces,
|
|
50
|
+
MonitorType.Exceptions,
|
|
51
|
+
MonitorType.Profiles,
|
|
52
|
+
MonitorType.Kubernetes,
|
|
53
|
+
MonitorType.Docker,
|
|
54
|
+
MonitorType.Host,
|
|
55
|
+
MonitorType.Podman,
|
|
56
|
+
MonitorType.DockerSwarm,
|
|
57
|
+
MonitorType.Proxmox,
|
|
58
|
+
MonitorType.Ceph,
|
|
59
|
+
])("returns true for %s", (monitorType: MonitorType) => {
|
|
60
|
+
expect(MonitorTypeHelper.isTelemetryMonitor(monitorType)).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test.each([MonitorType.Manual, MonitorType.Website, MonitorType.API])(
|
|
64
|
+
"returns false for %s",
|
|
65
|
+
(monitorType: MonitorType) => {
|
|
66
|
+
expect(MonitorTypeHelper.isTelemetryMonitor(monitorType)).toBe(false);
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("isManualMonitor", () => {
|
|
72
|
+
test("returns true only for Manual", () => {
|
|
73
|
+
expect(MonitorTypeHelper.isManualMonitor(MonitorType.Manual)).toBe(true);
|
|
74
|
+
expect(MonitorTypeHelper.isManualMonitor(MonitorType.Website)).toBe(
|
|
75
|
+
false,
|
|
76
|
+
);
|
|
77
|
+
expect(MonitorTypeHelper.isManualMonitor(MonitorType.API)).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("getTitle", () => {
|
|
82
|
+
test("returns the configured title", () => {
|
|
83
|
+
expect(MonitorTypeHelper.getTitle(MonitorType.API)).toBe("API");
|
|
84
|
+
expect(MonitorTypeHelper.getTitle(MonitorType.Docker)).toBe(
|
|
85
|
+
"Docker Container",
|
|
86
|
+
);
|
|
87
|
+
expect(MonitorTypeHelper.getTitle(MonitorType.Server)).toBe(
|
|
88
|
+
"Server / VM",
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("throws BadDataException for a type without props", () => {
|
|
93
|
+
expect(() => {
|
|
94
|
+
MonitorTypeHelper.getTitle("NonExistent" as MonitorType);
|
|
95
|
+
}).toThrowError(BadDataException);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("getDescription", () => {
|
|
100
|
+
test("returns a non-empty description for a known type", () => {
|
|
101
|
+
expect(
|
|
102
|
+
MonitorTypeHelper.getDescription(MonitorType.Ping).length,
|
|
103
|
+
).toBeGreaterThan(0);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("throws BadDataException for a type without props", () => {
|
|
107
|
+
expect(() => {
|
|
108
|
+
MonitorTypeHelper.getDescription("NonExistent" as MonitorType);
|
|
109
|
+
}).toThrowError(BadDataException);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("isProbableMonitor", () => {
|
|
114
|
+
test.each([
|
|
115
|
+
MonitorType.API,
|
|
116
|
+
MonitorType.Website,
|
|
117
|
+
MonitorType.IP,
|
|
118
|
+
MonitorType.Ping,
|
|
119
|
+
MonitorType.Port,
|
|
120
|
+
MonitorType.SSLCertificate,
|
|
121
|
+
MonitorType.SyntheticMonitor,
|
|
122
|
+
MonitorType.CustomJavaScriptCode,
|
|
123
|
+
MonitorType.SNMP,
|
|
124
|
+
MonitorType.DNS,
|
|
125
|
+
MonitorType.DNSSEC,
|
|
126
|
+
MonitorType.Domain,
|
|
127
|
+
MonitorType.ExternalStatusPage,
|
|
128
|
+
])("returns true for %s", (monitorType: MonitorType) => {
|
|
129
|
+
expect(MonitorTypeHelper.isProbableMonitor(monitorType)).toBe(true);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test.each([
|
|
133
|
+
MonitorType.Manual,
|
|
134
|
+
MonitorType.Logs,
|
|
135
|
+
MonitorType.Server,
|
|
136
|
+
MonitorType.IncomingRequest,
|
|
137
|
+
])("returns false for %s", (monitorType: MonitorType) => {
|
|
138
|
+
expect(MonitorTypeHelper.isProbableMonitor(monitorType)).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe("doesMonitorTypeHaveInterval", () => {
|
|
143
|
+
test("mirrors isProbableMonitor", () => {
|
|
144
|
+
const types: Array<MonitorType> = [
|
|
145
|
+
MonitorType.API,
|
|
146
|
+
MonitorType.Manual,
|
|
147
|
+
MonitorType.Logs,
|
|
148
|
+
MonitorType.DNS,
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
for (const monitorType of types) {
|
|
152
|
+
expect(MonitorTypeHelper.doesMonitorTypeHaveInterval(monitorType)).toBe(
|
|
153
|
+
MonitorTypeHelper.isProbableMonitor(monitorType),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("getActiveMonitorTypes", () => {
|
|
160
|
+
test("includes Server and excludes Manual", () => {
|
|
161
|
+
const active: Array<MonitorType> =
|
|
162
|
+
MonitorTypeHelper.getActiveMonitorTypes();
|
|
163
|
+
|
|
164
|
+
expect(active).toContain(MonitorType.Server);
|
|
165
|
+
expect(active).not.toContain(MonitorType.Manual);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("doesMonitorTypeHaveDocumentation", () => {
|
|
170
|
+
test.each([
|
|
171
|
+
MonitorType.IncomingRequest,
|
|
172
|
+
MonitorType.IncomingEmail,
|
|
173
|
+
MonitorType.Server,
|
|
174
|
+
])("returns true for %s", (monitorType: MonitorType) => {
|
|
175
|
+
expect(
|
|
176
|
+
MonitorTypeHelper.doesMonitorTypeHaveDocumentation(monitorType),
|
|
177
|
+
).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("returns false for other types", () => {
|
|
181
|
+
expect(
|
|
182
|
+
MonitorTypeHelper.doesMonitorTypeHaveDocumentation(MonitorType.API),
|
|
183
|
+
).toBe(false);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe("doesMonitorTypeHaveCriteria", () => {
|
|
188
|
+
test("returns false only for Manual", () => {
|
|
189
|
+
expect(
|
|
190
|
+
MonitorTypeHelper.doesMonitorTypeHaveCriteria(MonitorType.Manual),
|
|
191
|
+
).toBe(false);
|
|
192
|
+
expect(
|
|
193
|
+
MonitorTypeHelper.doesMonitorTypeHaveCriteria(MonitorType.API),
|
|
194
|
+
).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe("doesMonitorTypeHaveGraphs", () => {
|
|
199
|
+
test("returns true for graphable types and false otherwise", () => {
|
|
200
|
+
expect(
|
|
201
|
+
MonitorTypeHelper.doesMonitorTypeHaveGraphs(MonitorType.Website),
|
|
202
|
+
).toBe(true);
|
|
203
|
+
expect(
|
|
204
|
+
MonitorTypeHelper.doesMonitorTypeHaveGraphs(MonitorType.Server),
|
|
205
|
+
).toBe(true);
|
|
206
|
+
expect(
|
|
207
|
+
MonitorTypeHelper.doesMonitorTypeHaveGraphs(MonitorType.Manual),
|
|
208
|
+
).toBe(false);
|
|
209
|
+
expect(
|
|
210
|
+
MonitorTypeHelper.doesMonitorTypeHaveGraphs(MonitorType.Logs),
|
|
211
|
+
).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|