@northern.tech/testing 0.8.1 → 0.8.4

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.
Files changed (71) hide show
  1. package/dist/mockData.cjs +1302 -0
  2. package/dist/mockData.cjs.map +1 -0
  3. package/dist/mockData.d.cts +662 -0
  4. package/dist/mockData.d.ts +662 -0
  5. package/dist/mockData.js +1280 -0
  6. package/dist/mockData.js.map +1 -0
  7. package/dist/public/baseTestConfig.json +17 -0
  8. package/dist/requestHandlers/deploymentHandlers.cjs +193 -0
  9. package/dist/requestHandlers/deploymentHandlers.cjs.map +1 -0
  10. package/dist/requestHandlers/deploymentHandlers.d.cts +7 -0
  11. package/dist/requestHandlers/deploymentHandlers.d.ts +7 -0
  12. package/dist/requestHandlers/deploymentHandlers.js +191 -0
  13. package/dist/requestHandlers/deploymentHandlers.js.map +1 -0
  14. package/dist/requestHandlers/deviceHandlers.cjs +432 -0
  15. package/dist/requestHandlers/deviceHandlers.cjs.map +1 -0
  16. package/dist/requestHandlers/deviceHandlers.d.cts +22 -0
  17. package/dist/requestHandlers/deviceHandlers.d.ts +22 -0
  18. package/dist/requestHandlers/deviceHandlers.js +428 -0
  19. package/dist/requestHandlers/deviceHandlers.js.map +1 -0
  20. package/dist/requestHandlers/monitorHandlers.cjs +23 -0
  21. package/dist/requestHandlers/monitorHandlers.cjs.map +1 -0
  22. package/dist/requestHandlers/monitorHandlers.d.cts +7 -0
  23. package/dist/requestHandlers/monitorHandlers.d.ts +7 -0
  24. package/dist/requestHandlers/monitorHandlers.js +21 -0
  25. package/dist/requestHandlers/monitorHandlers.js.map +1 -0
  26. package/dist/requestHandlers/organizationHandlers.cjs +312 -0
  27. package/dist/requestHandlers/organizationHandlers.cjs.map +1 -0
  28. package/dist/requestHandlers/organizationHandlers.d.cts +7 -0
  29. package/dist/requestHandlers/organizationHandlers.d.ts +7 -0
  30. package/dist/requestHandlers/organizationHandlers.js +310 -0
  31. package/dist/requestHandlers/organizationHandlers.js.map +1 -0
  32. package/dist/requestHandlers/releaseHandlers.cjs +161 -0
  33. package/dist/requestHandlers/releaseHandlers.cjs.map +1 -0
  34. package/dist/requestHandlers/releaseHandlers.d.cts +7 -0
  35. package/dist/requestHandlers/releaseHandlers.d.ts +7 -0
  36. package/dist/requestHandlers/releaseHandlers.js +159 -0
  37. package/dist/requestHandlers/releaseHandlers.js.map +1 -0
  38. package/dist/requestHandlers/requestHandlers.cjs +28 -0
  39. package/dist/requestHandlers/requestHandlers.cjs.map +1 -0
  40. package/dist/requestHandlers/requestHandlers.d.cts +6 -0
  41. package/dist/requestHandlers/requestHandlers.d.ts +7 -0
  42. package/dist/requestHandlers/requestHandlers.js +27 -0
  43. package/dist/requestHandlers/requestHandlers.js.map +1 -0
  44. package/dist/requestHandlers/userHandlers.cjs +141 -0
  45. package/dist/requestHandlers/userHandlers.cjs.map +1 -0
  46. package/dist/requestHandlers/userHandlers.d.cts +7 -0
  47. package/dist/requestHandlers/userHandlers.d.ts +7 -0
  48. package/dist/requestHandlers/userHandlers.js +139 -0
  49. package/dist/requestHandlers/userHandlers.js.map +1 -0
  50. package/dist/setupTests.cjs +173 -0
  51. package/dist/setupTests.cjs.map +1 -0
  52. package/dist/setupTests.d.cts +79 -0
  53. package/dist/setupTests.d.ts +79 -0
  54. package/dist/setupTests.js +135 -0
  55. package/dist/setupTests.js.map +1 -0
  56. package/dist/theme/light.cjs +9 -0
  57. package/dist/theme/light.cjs.map +1 -0
  58. package/dist/theme/light.d.cts +7 -0
  59. package/dist/theme/light.d.ts +7 -0
  60. package/dist/theme/light.js +8 -0
  61. package/dist/theme/light.js.map +1 -0
  62. package/dist/theme/mui.d.cjs +0 -0
  63. package/dist/theme/mui.d.cts +11 -0
  64. package/dist/theme/mui.d.ts +11 -0
  65. package/dist/utils.cjs +21 -0
  66. package/dist/utils.cjs.map +1 -0
  67. package/dist/utils.d.cts +8 -0
  68. package/dist/utils.d.ts +8 -0
  69. package/dist/utils.js +18 -0
  70. package/dist/utils.js.map +1 -0
  71. package/package.json +6 -6
@@ -0,0 +1,428 @@
1
+ import { defaultCreationDate, defaultMacAddress, mockApiResponses } from "../mockData.js";
2
+ import { DEVICE_FILTERING_OPTIONS, DEVICE_STATES, deviceAuthV2, deviceConfig, deviceConnect, headerNames, inventoryApiUrl, inventoryApiUrlV2, iotManagerBaseURL } from "@northern.tech/utils/constants";
3
+ import { HttpResponse, http } from "msw";
4
+ //#region src/requestHandlers/deviceHandlers.ts
5
+ const defaultDeviceId = "a1";
6
+ const deviceAuthDevice = {
7
+ id: "a1",
8
+ identity_data: { mac: defaultMacAddress },
9
+ status: "accepted",
10
+ decommissioning: false,
11
+ created_ts: defaultCreationDate,
12
+ updated_ts: "2019-01-01T09:25:00.000Z",
13
+ auth_sets: [{
14
+ id: "auth1",
15
+ identity_data: { mac: defaultMacAddress },
16
+ pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
17
+ ts: defaultCreationDate,
18
+ status: "accepted"
19
+ }]
20
+ };
21
+ const checkInTimeExact = "2019-01-01T10:25:00.000Z";
22
+ const updatedTime = "2019-01-01T09:25:00.000Z";
23
+ const inventoryDevice = {
24
+ id: "a1",
25
+ attributes: [
26
+ {
27
+ name: "network_interfaces",
28
+ value: ["eth0", "wlan0"],
29
+ scope: "inventory"
30
+ },
31
+ {
32
+ name: "kernel",
33
+ value: "Linux version 4.19.75-v7l+",
34
+ scope: "inventory"
35
+ },
36
+ {
37
+ name: "artifact_name",
38
+ value: "raspotifyInstaller",
39
+ scope: "inventory"
40
+ },
41
+ {
42
+ name: "ipv6_wlan0",
43
+ value: "fe80::68d9:8453:3e9c:7c80/64",
44
+ scope: "inventory"
45
+ },
46
+ {
47
+ name: "mac_eth0",
48
+ value: defaultMacAddress,
49
+ scope: "inventory"
50
+ },
51
+ {
52
+ name: "rootfs_type",
53
+ value: "ext4",
54
+ scope: "inventory"
55
+ },
56
+ {
57
+ name: "mender_bootloader_integration",
58
+ value: "unknown",
59
+ scope: "inventory"
60
+ },
61
+ {
62
+ name: "cpu_model",
63
+ value: "ARMv7 Processor rev 3 (v7l)",
64
+ scope: "inventory"
65
+ },
66
+ {
67
+ name: "hostname",
68
+ value: "raspberrypi",
69
+ scope: "inventory"
70
+ },
71
+ {
72
+ name: "mender_client_version",
73
+ value: "2.1.0",
74
+ scope: "inventory"
75
+ },
76
+ {
77
+ name: "ipv4_wlan0",
78
+ value: "192.168.10.141/24",
79
+ scope: "inventory"
80
+ },
81
+ {
82
+ name: "device_type",
83
+ value: "raspberrypi4",
84
+ scope: "inventory"
85
+ },
86
+ {
87
+ name: "mem_total_kB",
88
+ value: "1986024",
89
+ scope: "inventory"
90
+ },
91
+ {
92
+ name: "mac_wlan0",
93
+ value: "dc:a6:32:12:ad:c0",
94
+ scope: "inventory"
95
+ },
96
+ {
97
+ name: "os",
98
+ value: "Raspbian GNU/Linux 10 (buster)",
99
+ scope: "inventory"
100
+ },
101
+ {
102
+ name: "created_ts",
103
+ value: defaultCreationDate,
104
+ scope: "system"
105
+ },
106
+ {
107
+ name: "updated_ts",
108
+ value: updatedTime,
109
+ scope: "system"
110
+ },
111
+ {
112
+ name: "status",
113
+ value: "accepted",
114
+ scope: "identity"
115
+ },
116
+ {
117
+ name: "mac",
118
+ value: defaultMacAddress,
119
+ scope: "identity"
120
+ },
121
+ {
122
+ name: "group",
123
+ value: "test",
124
+ scope: "system"
125
+ }
126
+ ],
127
+ check_in_time: checkInTimeExact,
128
+ updated_ts: updatedTime
129
+ };
130
+ const deviceAttributes = [
131
+ {
132
+ name: "status",
133
+ scope: "identity",
134
+ count: 5
135
+ },
136
+ {
137
+ name: "created_ts",
138
+ scope: "system",
139
+ count: 5
140
+ },
141
+ {
142
+ name: "updated_ts",
143
+ scope: "system",
144
+ count: 5
145
+ },
146
+ {
147
+ name: "mac",
148
+ scope: "identity",
149
+ count: 1
150
+ },
151
+ {
152
+ name: "artifact_name",
153
+ scope: "inventory",
154
+ count: 1
155
+ },
156
+ {
157
+ name: "cpu_model",
158
+ scope: "inventory",
159
+ count: 1
160
+ },
161
+ {
162
+ name: "device_type",
163
+ scope: "inventory",
164
+ count: 1
165
+ },
166
+ {
167
+ name: "hostname",
168
+ scope: "inventory",
169
+ count: 1
170
+ },
171
+ {
172
+ name: "ipv4_wlan0",
173
+ scope: "inventory",
174
+ count: 1
175
+ },
176
+ {
177
+ name: "ipv6_wlan0",
178
+ scope: "inventory",
179
+ count: 1
180
+ },
181
+ {
182
+ name: "kernel",
183
+ scope: "inventory",
184
+ count: 1
185
+ },
186
+ {
187
+ name: "mac_eth0",
188
+ scope: "inventory",
189
+ count: 1
190
+ },
191
+ {
192
+ name: "mac_wlan0",
193
+ scope: "inventory",
194
+ count: 1
195
+ },
196
+ {
197
+ name: "mem_total_kB",
198
+ scope: "inventory",
199
+ count: 1
200
+ },
201
+ {
202
+ name: "mender_bootloader_integration",
203
+ scope: "inventory",
204
+ count: 1
205
+ },
206
+ {
207
+ name: "mender_client_version",
208
+ scope: "inventory",
209
+ count: 1
210
+ },
211
+ {
212
+ name: "network_interfaces",
213
+ scope: "inventory",
214
+ count: 1
215
+ },
216
+ {
217
+ name: "os",
218
+ scope: "inventory",
219
+ count: 1
220
+ },
221
+ {
222
+ name: "rootfs_type",
223
+ scope: "inventory",
224
+ count: 1
225
+ },
226
+ {
227
+ name: "group",
228
+ scope: "system",
229
+ count: 1
230
+ }
231
+ ];
232
+ const searchHandler = async ({ request }) => {
233
+ const { page, per_page, filters } = await request.json();
234
+ if ([
235
+ page,
236
+ per_page,
237
+ filters
238
+ ].some((item) => !item)) return new HttpResponse(null, { status: 509 });
239
+ const status = filters.find((filter) => filter.scope === "identity" && filter.attribute === "status" && Object.values(DEVICE_STATES).includes(filter.value))?.value || "";
240
+ if (!status || filters.length > 1) {
241
+ if (filters.find((filter) => filter.attribute === "group" && filter.value.includes(Object.keys(mockApiResponses.devices.groups.byId)[0]))) return new HttpResponse(JSON.stringify([inventoryDevice, {
242
+ ...inventoryDevice,
243
+ id: "b1"
244
+ }]), { headers: { [headerNames.total]: 2 } });
245
+ if (filters.find((filter) => filter.scope === "monitor" && [
246
+ "failed_last_update",
247
+ "alerts",
248
+ "auth_request"
249
+ ].includes(filter.attribute))) return new HttpResponse(JSON.stringify([inventoryDevice]), { headers: { [headerNames.total]: 4 } });
250
+ return new HttpResponse(JSON.stringify([]), { headers: { [headerNames.total]: 0 } });
251
+ }
252
+ let deviceList = Array.from({ length: mockApiResponses.devices.byStatus[status].total }, (_, index) => ({
253
+ ...inventoryDevice,
254
+ attributes: [...inventoryDevice.attributes, {
255
+ name: "test-count",
256
+ value: index,
257
+ scope: "system"
258
+ }],
259
+ id: `${String.fromCharCode("a".charCodeAt(0) + index)}1`
260
+ }));
261
+ deviceList = deviceList.slice((page - 1) * per_page, page * per_page);
262
+ return new HttpResponse(JSON.stringify(deviceList), { headers: { [headerNames.total]: mockApiResponses.devices.byStatus[status].total } });
263
+ };
264
+ const deviceHandlers = [
265
+ http.delete(`${deviceAuthV2}/devices/:deviceId/auth/:authId`, ({ params: { authId, deviceId } }) => {
266
+ if (mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId)) return new HttpResponse(null, { status: 200 });
267
+ return new HttpResponse(null, { status: 501 });
268
+ }),
269
+ http.delete(`${deviceAuthV2}/devices/:deviceId`, ({ params: { deviceId } }) => {
270
+ if (mockApiResponses.devices.byId[deviceId]) return new HttpResponse(null, { status: 200 });
271
+ return new HttpResponse(null, { status: 502 });
272
+ }),
273
+ http.delete(`${inventoryApiUrl}/groups/:group`, ({ params: { group } }) => {
274
+ if (mockApiResponses.devices.groups.byId[group]) return new HttpResponse(null, { status: 200 });
275
+ return new HttpResponse(null, { status: 515 });
276
+ }),
277
+ http.delete(`${inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {
278
+ const deviceIds = await request.json();
279
+ if (mockApiResponses.devices.groups.byId[group] && deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) return new HttpResponse(null, { status: 200 });
280
+ return new HttpResponse(null, { status: 503 });
281
+ }),
282
+ http.delete(`${inventoryApiUrlV2}/filters/:filterId`, ({ params: { filterId } }) => {
283
+ if (Object.values(mockApiResponses.devices.groups.byId).find((group) => group.id === filterId)) return new HttpResponse(null, { status: 200 });
284
+ return new HttpResponse(null, { status: 504 });
285
+ }),
286
+ http.get(`${deviceAuthV2}/devices`, ({ request }) => {
287
+ const { searchParams } = new URL(request.url);
288
+ const deviceIds = searchParams.getAll("id");
289
+ if (deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) return HttpResponse.json(deviceIds.map((id) => ({
290
+ ...deviceAuthDevice,
291
+ id
292
+ })));
293
+ return new HttpResponse(null, { status: 505 });
294
+ }),
295
+ http.get(`${deviceAuthV2}/limits/devices`, () => HttpResponse.json(mockApiResponses.devices.limits)),
296
+ http.get(`${inventoryApiUrl}/devices/:deviceId`, ({ params: { deviceId } }) => {
297
+ if (mockApiResponses.devices.byId[deviceId]) return HttpResponse.json(inventoryDevice);
298
+ return new HttpResponse(null, { status: 506 });
299
+ }),
300
+ http.put(`${inventoryApiUrl}/devices/:deviceId/tags`, async ({ params: { deviceId }, request }) => {
301
+ const tags = await request.json();
302
+ if (!mockApiResponses.devices.byId[deviceId] && !Array.isArray(tags) && !tags.every((item) => item.name && item.value)) return new HttpResponse(null, { status: 506 });
303
+ return HttpResponse.json(tags);
304
+ }),
305
+ http.get(`${inventoryApiUrl}/groups`, () => {
306
+ const groups = Object.entries(mockApiResponses.devices.groups.byId).reduce((accu, [groupName, group]) => {
307
+ if (!group.id) accu.push(groupName);
308
+ return accu;
309
+ }, []);
310
+ return HttpResponse.json(groups);
311
+ }),
312
+ http.get(`${inventoryApiUrlV2}/filters/attributes`, () => HttpResponse.json(deviceAttributes)),
313
+ http.get(`${inventoryApiUrlV2}/filters`, () => HttpResponse.json([{
314
+ id: "filter1",
315
+ name: "testGroupDynamic",
316
+ terms: [
317
+ {
318
+ scope: "identity",
319
+ attribute: "id",
320
+ type: "$in",
321
+ value: ["a1"]
322
+ },
323
+ {
324
+ scope: "identity",
325
+ attribute: "mac",
326
+ type: "$exists",
327
+ value: false
328
+ },
329
+ {
330
+ scope: "identity",
331
+ attribute: "kernel",
332
+ type: "$exists",
333
+ value: true
334
+ }
335
+ ]
336
+ }])),
337
+ http.patch(`${inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {
338
+ const deviceIds = await request.json();
339
+ if (!!group && deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) return new HttpResponse(null, { status: 200 });
340
+ return new HttpResponse(null, { status: 508 });
341
+ }),
342
+ http.post(`${deviceAuthV2}/devices`, async ({ request }) => {
343
+ const authset = await request.json();
344
+ if (Object.values(mockApiResponses.devices.byId).some((device) => device.auth_sets.some((deviceAuthSet) => deviceAuthSet.pubkey == authset.pubkey || deviceAuthSet.identity_data == authset.identity_data))) return new HttpResponse(null, { status: 409 });
345
+ return new HttpResponse(null, { status: 200 });
346
+ }),
347
+ http.post(`${inventoryApiUrlV2}/filters/search`, searchHandler),
348
+ http.post(`${inventoryApiUrlV2}/filters`, async ({ request }) => {
349
+ const { name, terms } = await request.json();
350
+ if ([name, terms].some((item) => !item) || mockApiResponses.devices.groups[name] || !terms.every((term) => DEVICE_FILTERING_OPTIONS[term.type] && [
351
+ "identity",
352
+ "inventory",
353
+ "system"
354
+ ].includes(term.scope) && !!term.value && !!term.attribute)) return new HttpResponse(null, { status: 510 });
355
+ return new HttpResponse(JSON.stringify({}), { headers: { location: "find/me/here/createdFilterId" } });
356
+ }),
357
+ http.get(`${inventoryApiUrlV2}/statistics`, async () => HttpResponse.json({ devices_by_status: {
358
+ accepted: {
359
+ standard: mockApiResponses.devices.byStatus.accepted.total,
360
+ micro: 0,
361
+ system: 0
362
+ },
363
+ pending: {
364
+ standard: mockApiResponses.devices.byStatus.pending.total,
365
+ micro: 0,
366
+ system: 0
367
+ }
368
+ } })),
369
+ http.put(`${deviceAuthV2}/devices/:deviceId/auth/:authId/status`, async ({ params: { authId, deviceId }, request }) => {
370
+ const { status } = await request.json();
371
+ if (mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId) && DEVICE_STATES[status]) return new HttpResponse(null, { status: 200 });
372
+ return new HttpResponse(null, { status: 511 });
373
+ }),
374
+ http.get(`${deviceConfig}/:deviceId`, ({ params: { deviceId } }) => {
375
+ if (deviceId === "testId") return new HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
376
+ if (mockApiResponses.devices.byId[deviceId]) return HttpResponse.json({
377
+ configured: {
378
+ test: true,
379
+ something: "else",
380
+ aNumber: 42
381
+ },
382
+ deployment_id: "config1",
383
+ reported: {
384
+ test: true,
385
+ something: "else",
386
+ aNumber: 42
387
+ },
388
+ updated_ts: updatedTime,
389
+ reported_ts: "2019-01-01T09:25:01.000Z"
390
+ });
391
+ return new HttpResponse(null, { status: 512 });
392
+ }),
393
+ http.put(`${deviceConfig}/:deviceId`, async ({ params: { deviceId }, request }) => {
394
+ if ((await request.text()).includes("evilValue")) return new HttpResponse(null, { status: 418 });
395
+ return new HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 201 : 513 });
396
+ }),
397
+ http.post(`${deviceConfig}/:deviceId/deploy`, ({ params: { deviceId } }) => {
398
+ if (mockApiResponses.devices.byId[deviceId]) return HttpResponse.json({ deployment_id: "config1" });
399
+ return new HttpResponse(null, { status: 514 });
400
+ }),
401
+ http.get(`${deviceConnect}/devices/:deviceId`, ({ params: { deviceId } }) => {
402
+ if (deviceId === "testId") return new HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
403
+ if (mockApiResponses.devices.byId[deviceId]) return HttpResponse.json({
404
+ status: "connected",
405
+ updated_ts: mockApiResponses.devices.byId[deviceId].updated_ts
406
+ });
407
+ return new HttpResponse(null, { status: 512 });
408
+ }),
409
+ http.post(`${deviceConnect}/devices/:deviceId/:action`, ({ params: { deviceId, action } }) => {
410
+ if (["check-update", "send-inventory"].includes(action) && mockApiResponses.devices.byId[deviceId]) return new HttpResponse(null, { status: 202 });
411
+ return new HttpResponse(null, { status: 518 });
412
+ }),
413
+ http.get(`${iotManagerBaseURL}/devices/:deviceId/state`, ({ params: { deviceId } }) => {
414
+ if (mockApiResponses.devices.byId[deviceId]) return HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });
415
+ return new HttpResponse(null, { status: 515 });
416
+ }),
417
+ http.put(`${iotManagerBaseURL}/devices/:deviceId/state/:integrationId`, async ({ params: { deviceId }, request }) => {
418
+ const body = await request.json();
419
+ if (mockApiResponses.devices.byId[deviceId] && body) return HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });
420
+ return new HttpResponse(null, { status: 516 });
421
+ }),
422
+ http.put(`${deviceConnect}/devices/:deviceId/upload`, ({ params: { deviceId } }) => new HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 200 : 517 })),
423
+ http.get(`${deviceAuthV2}/license`, () => HttpResponse.text("test,report"))
424
+ ];
425
+ //#endregion
426
+ export { defaultDeviceId, deviceHandlers, inventoryDevice };
427
+
428
+ //# sourceMappingURL=deviceHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceHandlers.js","names":[],"sources":["../../src/requestHandlers/deviceHandlers.ts"],"sourcesContent":["// Copyright 2020 Northern.tech AS\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//@ts-nocheck\nimport {\n DEVICE_FILTERING_OPTIONS,\n DEVICE_STATES,\n deviceAuthV2,\n deviceConfig,\n deviceConnect,\n headerNames,\n inventoryApiUrl,\n inventoryApiUrlV2,\n iotManagerBaseURL\n} from '@northern.tech/utils/constants';\nimport { HttpResponse, http } from 'msw';\n\nimport { defaultCreationDate, defaultMacAddress, mockApiResponses } from '../mockData';\n\nexport const defaultDeviceId = 'a1';\n\nconst deviceAuthDevice = {\n id: defaultDeviceId,\n identity_data: { mac: defaultMacAddress },\n status: 'accepted',\n decommissioning: false,\n created_ts: defaultCreationDate,\n updated_ts: '2019-01-01T09:25:00.000Z',\n auth_sets: [\n {\n id: 'auth1',\n identity_data: { mac: defaultMacAddress },\n pubkey: '-----BEGIN PUBLIC KEY-----\\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\\n-----END PUBLIC KEY-----\\n',\n ts: defaultCreationDate,\n status: 'accepted'\n }\n ]\n};\n\nconst checkInTimeExact = '2019-01-01T10:25:00.000Z';\nconst updatedTime = '2019-01-01T09:25:00.000Z';\n\nexport const inventoryDevice = {\n id: defaultDeviceId,\n attributes: [\n { name: 'network_interfaces', value: ['eth0', 'wlan0'], scope: 'inventory' },\n { name: 'kernel', value: 'Linux version 4.19.75-v7l+', scope: 'inventory' },\n { name: 'artifact_name', value: 'raspotifyInstaller', scope: 'inventory' },\n { name: 'ipv6_wlan0', value: 'fe80::68d9:8453:3e9c:7c80/64', scope: 'inventory' },\n { name: 'mac_eth0', value: defaultMacAddress, scope: 'inventory' },\n { name: 'rootfs_type', value: 'ext4', scope: 'inventory' },\n { name: 'mender_bootloader_integration', value: 'unknown', scope: 'inventory' },\n { name: 'cpu_model', value: 'ARMv7 Processor rev 3 (v7l)', scope: 'inventory' },\n { name: 'hostname', value: 'raspberrypi', scope: 'inventory' },\n { name: 'mender_client_version', value: '2.1.0', scope: 'inventory' },\n { name: 'ipv4_wlan0', value: '192.168.10.141/24', scope: 'inventory' },\n { name: 'device_type', value: 'raspberrypi4', scope: 'inventory' },\n { name: 'mem_total_kB', value: '1986024', scope: 'inventory' },\n { name: 'mac_wlan0', value: 'dc:a6:32:12:ad:c0', scope: 'inventory' },\n { name: 'os', value: 'Raspbian GNU/Linux 10 (buster)', scope: 'inventory' },\n { name: 'created_ts', value: defaultCreationDate, scope: 'system' },\n { name: 'updated_ts', value: updatedTime, scope: 'system' },\n { name: 'status', value: 'accepted', scope: 'identity' },\n { name: 'mac', value: defaultMacAddress, scope: 'identity' },\n { name: 'group', value: 'test', scope: 'system' }\n ],\n check_in_time: checkInTimeExact,\n updated_ts: updatedTime\n};\n\nconst deviceAttributes = [\n { name: 'status', scope: 'identity', count: 5 },\n { name: 'created_ts', scope: 'system', count: 5 },\n { name: 'updated_ts', scope: 'system', count: 5 },\n { name: 'mac', scope: 'identity', count: 1 },\n { name: 'artifact_name', scope: 'inventory', count: 1 },\n { name: 'cpu_model', scope: 'inventory', count: 1 },\n { name: 'device_type', scope: 'inventory', count: 1 },\n { name: 'hostname', scope: 'inventory', count: 1 },\n { name: 'ipv4_wlan0', scope: 'inventory', count: 1 },\n { name: 'ipv6_wlan0', scope: 'inventory', count: 1 },\n { name: 'kernel', scope: 'inventory', count: 1 },\n { name: 'mac_eth0', scope: 'inventory', count: 1 },\n { name: 'mac_wlan0', scope: 'inventory', count: 1 },\n { name: 'mem_total_kB', scope: 'inventory', count: 1 },\n { name: 'mender_bootloader_integration', scope: 'inventory', count: 1 },\n { name: 'mender_client_version', scope: 'inventory', count: 1 },\n { name: 'network_interfaces', scope: 'inventory', count: 1 },\n { name: 'os', scope: 'inventory', count: 1 },\n { name: 'rootfs_type', scope: 'inventory', count: 1 },\n { name: 'group', scope: 'system', count: 1 }\n];\n\nconst searchHandler = async ({ request }) => {\n const { page, per_page, filters } = await request.json();\n if ([page, per_page, filters].some(item => !item)) {\n return new HttpResponse(null, { status: 509 });\n }\n const filter = filters.find(filter => filter.scope === 'identity' && filter.attribute === 'status' && Object.values(DEVICE_STATES).includes(filter.value));\n const status = filter?.value || '';\n if (!status || filters.length > 1) {\n if (filters.find(filter => filter.attribute === 'group' && filter.value.includes(Object.keys(mockApiResponses.devices.groups.byId)[0]))) {\n return new HttpResponse(JSON.stringify([inventoryDevice, { ...inventoryDevice, id: 'b1' }]), {\n headers: { [headerNames.total]: 2 }\n });\n }\n if (filters.find(filter => filter.scope === 'monitor' && ['failed_last_update', 'alerts', 'auth_request'].includes(filter.attribute))) {\n return new HttpResponse(JSON.stringify([inventoryDevice]), { headers: { [headerNames.total]: 4 } });\n }\n return new HttpResponse(JSON.stringify([]), { headers: { [headerNames.total]: 0 } });\n }\n let deviceList = Array.from({ length: mockApiResponses.devices.byStatus[status].total }, (_, index) => ({\n ...inventoryDevice,\n attributes: [...inventoryDevice.attributes, { name: 'test-count', value: index, scope: 'system' }],\n id: `${String.fromCharCode('a'.charCodeAt(0) + index)}1`\n }));\n deviceList = deviceList.slice((page - 1) * per_page, page * per_page);\n return new HttpResponse(JSON.stringify(deviceList), { headers: { [headerNames.total]: mockApiResponses.devices.byStatus[status].total } });\n};\n\nexport const deviceHandlers = [\n http.delete(`${deviceAuthV2}/devices/:deviceId/auth/:authId`, ({ params: { authId, deviceId } }) => {\n if (mockApiResponses.devices.byId[deviceId].auth_sets.find(authSet => authSet.id === authId)) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 501 });\n }),\n http.delete(`${deviceAuthV2}/devices/:deviceId`, ({ params: { deviceId } }) => {\n if (mockApiResponses.devices.byId[deviceId]) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 502 });\n }),\n http.delete(`${inventoryApiUrl}/groups/:group`, ({ params: { group } }) => {\n if (mockApiResponses.devices.groups.byId[group]) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 515 });\n }),\n http.delete(`${inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {\n const deviceIds = await request.json();\n if (mockApiResponses.devices.groups.byId[group] && deviceIds.every(id => !!mockApiResponses.devices.byId[id])) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 503 });\n }),\n http.delete(`${inventoryApiUrlV2}/filters/:filterId`, ({ params: { filterId } }) => {\n if (Object.values(mockApiResponses.devices.groups.byId).find(group => group.id === filterId)) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 504 });\n }),\n http.get(`${deviceAuthV2}/devices`, ({ request }) => {\n const { searchParams } = new URL(request.url);\n const deviceIds = searchParams.getAll('id');\n if (deviceIds.every(id => !!mockApiResponses.devices.byId[id])) {\n return HttpResponse.json(deviceIds.map(id => ({ ...deviceAuthDevice, id })));\n }\n return new HttpResponse(null, { status: 505 });\n }),\n http.get(`${deviceAuthV2}/limits/devices`, () => HttpResponse.json(mockApiResponses.devices.limits)),\n http.get(`${inventoryApiUrl}/devices/:deviceId`, ({ params: { deviceId } }) => {\n if (mockApiResponses.devices.byId[deviceId]) {\n return HttpResponse.json(inventoryDevice);\n }\n return new HttpResponse(null, { status: 506 });\n }),\n http.put(`${inventoryApiUrl}/devices/:deviceId/tags`, async ({ params: { deviceId }, request }) => {\n const tags = await request.json();\n if (!mockApiResponses.devices.byId[deviceId] && !Array.isArray(tags) && !tags.every(item => item.name && item.value)) {\n return new HttpResponse(null, { status: 506 });\n }\n return HttpResponse.json(tags);\n }),\n http.get(`${inventoryApiUrl}/groups`, () => {\n const groups = Object.entries(mockApiResponses.devices.groups.byId).reduce((accu, [groupName, group]) => {\n if (!group.id) {\n accu.push(groupName);\n }\n return accu;\n }, []);\n return HttpResponse.json(groups);\n }),\n http.get(`${inventoryApiUrlV2}/filters/attributes`, () => HttpResponse.json(deviceAttributes)),\n http.get(`${inventoryApiUrlV2}/filters`, () =>\n HttpResponse.json([\n {\n id: 'filter1',\n name: 'testGroupDynamic',\n terms: [\n { scope: 'identity', attribute: 'id', type: '$in', value: [defaultDeviceId] },\n { scope: 'identity', attribute: 'mac', type: '$exists', value: false },\n { scope: 'identity', attribute: 'kernel', type: '$exists', value: true }\n ]\n }\n ])\n ),\n http.patch(`${inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {\n const deviceIds = await request.json();\n if (!!group && deviceIds.every(id => !!mockApiResponses.devices.byId[id])) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 508 });\n }),\n http.post(`${deviceAuthV2}/devices`, async ({ request }) => {\n const authset = await request.json();\n if (\n Object.values(mockApiResponses.devices.byId).some(device =>\n device.auth_sets.some(deviceAuthSet => deviceAuthSet.pubkey == authset.pubkey || deviceAuthSet.identity_data == authset.identity_data)\n )\n ) {\n return new HttpResponse(null, { status: 409 });\n }\n return new HttpResponse(null, { status: 200 });\n }),\n http.post(`${inventoryApiUrlV2}/filters/search`, searchHandler),\n http.post(`${inventoryApiUrlV2}/filters`, async ({ request }) => {\n const { name, terms } = await request.json();\n if (\n [name, terms].some(item => !item) ||\n mockApiResponses.devices.groups[name] ||\n !terms.every(term => DEVICE_FILTERING_OPTIONS[term.type] && ['identity', 'inventory', 'system'].includes(term.scope) && !!term.value && !!term.attribute)\n ) {\n return new HttpResponse(null, { status: 510 });\n }\n return new HttpResponse(JSON.stringify({}), { headers: { location: 'find/me/here/createdFilterId' } });\n }),\n http.get(`${inventoryApiUrlV2}/statistics`, async () =>\n HttpResponse.json({\n devices_by_status: {\n accepted: { standard: mockApiResponses.devices.byStatus.accepted.total, micro: 0, system: 0 },\n pending: { standard: mockApiResponses.devices.byStatus.pending.total, micro: 0, system: 0 }\n }\n })\n ),\n http.put(`${deviceAuthV2}/devices/:deviceId/auth/:authId/status`, async ({ params: { authId, deviceId }, request }) => {\n const { status } = await request.json();\n if (mockApiResponses.devices.byId[deviceId].auth_sets.find(authSet => authSet.id === authId) && DEVICE_STATES[status]) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 511 });\n }),\n http.get(`${deviceConfig}/:deviceId`, ({ params: { deviceId } }) => {\n if (deviceId === 'testId') {\n return new HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });\n }\n if (mockApiResponses.devices.byId[deviceId]) {\n return HttpResponse.json({\n configured: { test: true, something: 'else', aNumber: 42 },\n deployment_id: 'config1',\n reported: { test: true, something: 'else', aNumber: 42 },\n updated_ts: updatedTime,\n reported_ts: '2019-01-01T09:25:01.000Z'\n });\n }\n return new HttpResponse(null, { status: 512 });\n }),\n http.put(`${deviceConfig}/:deviceId`, async ({ params: { deviceId }, request }) => {\n const body = await request.text();\n if (body.includes('evilValue')) {\n return new HttpResponse(null, { status: 418 });\n }\n return new HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 201 : 513 });\n }),\n http.post(`${deviceConfig}/:deviceId/deploy`, ({ params: { deviceId } }) => {\n if (mockApiResponses.devices.byId[deviceId]) {\n return HttpResponse.json({ deployment_id: 'config1' });\n }\n return new HttpResponse(null, { status: 514 });\n }),\n http.get(`${deviceConnect}/devices/:deviceId`, ({ params: { deviceId } }) => {\n if (deviceId === 'testId') {\n return new HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });\n }\n if (mockApiResponses.devices.byId[deviceId]) {\n return HttpResponse.json({ status: 'connected', updated_ts: mockApiResponses.devices.byId[deviceId].updated_ts });\n }\n return new HttpResponse(null, { status: 512 });\n }),\n http.post(`${deviceConnect}/devices/:deviceId/:action`, ({ params: { deviceId, action } }) => {\n if (['check-update', 'send-inventory'].includes(action) && mockApiResponses.devices.byId[deviceId]) {\n return new HttpResponse(null, { status: 202 });\n }\n return new HttpResponse(null, { status: 518 });\n }),\n http.get(`${iotManagerBaseURL}/devices/:deviceId/state`, ({ params: { deviceId } }) => {\n if (mockApiResponses.devices.byId[deviceId]) {\n return HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });\n }\n return new HttpResponse(null, { status: 515 });\n }),\n http.put(`${iotManagerBaseURL}/devices/:deviceId/state/:integrationId`, async ({ params: { deviceId }, request }) => {\n const body = await request.json();\n if (mockApiResponses.devices.byId[deviceId] && body) {\n return HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });\n }\n return new HttpResponse(null, { status: 516 });\n }),\n http.put(\n `${deviceConnect}/devices/:deviceId/upload`,\n ({ params: { deviceId } }) => new HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 200 : 517 })\n ),\n http.get(`${deviceAuthV2}/license`, () => HttpResponse.text('test,report'))\n];\n"],"mappings":";;;;AA6BA,MAAa,kBAAkB;AAE/B,MAAM,mBAAmB;CACvB,IAAA;CACA,eAAe,EAAE,KAAK,mBAAmB;CACzC,QAAQ;CACR,iBAAiB;CACjB,YAAY;CACZ,YAAY;CACZ,WAAW,CACT;EACE,IAAI;EACJ,eAAe,EAAE,KAAK,mBAAmB;EACzC,QAAQ;EACR,IAAI;EACJ,QAAQ;EACT,CACF;CACF;AAED,MAAM,mBAAmB;AACzB,MAAM,cAAc;AAEpB,MAAa,kBAAkB;CAC7B,IAAA;CACA,YAAY;EACV;GAAE,MAAM;GAAsB,OAAO,CAAC,QAAQ,QAAQ;GAAE,OAAO;GAAa;EAC5E;GAAE,MAAM;GAAU,OAAO;GAA8B,OAAO;GAAa;EAC3E;GAAE,MAAM;GAAiB,OAAO;GAAsB,OAAO;GAAa;EAC1E;GAAE,MAAM;GAAc,OAAO;GAAgC,OAAO;GAAa;EACjF;GAAE,MAAM;GAAY,OAAO;GAAmB,OAAO;GAAa;EAClE;GAAE,MAAM;GAAe,OAAO;GAAQ,OAAO;GAAa;EAC1D;GAAE,MAAM;GAAiC,OAAO;GAAW,OAAO;GAAa;EAC/E;GAAE,MAAM;GAAa,OAAO;GAA+B,OAAO;GAAa;EAC/E;GAAE,MAAM;GAAY,OAAO;GAAe,OAAO;GAAa;EAC9D;GAAE,MAAM;GAAyB,OAAO;GAAS,OAAO;GAAa;EACrE;GAAE,MAAM;GAAc,OAAO;GAAqB,OAAO;GAAa;EACtE;GAAE,MAAM;GAAe,OAAO;GAAgB,OAAO;GAAa;EAClE;GAAE,MAAM;GAAgB,OAAO;GAAW,OAAO;GAAa;EAC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K,YAAY,MAAM,KAAK,CAAC,CACtH;CACD,KAAK,IAAI,GAAG,aAAa,iBAAiB,aAAa,KAAK,cAAc,CAAC;CAC5E"}
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_mockData = require("../mockData.cjs");
3
+ require("../setupTests.cjs");
4
+ let _northern_tech_utils_constants = require("@northern.tech/utils/constants");
5
+ let msw = require("msw");
6
+ //#region src/requestHandlers/monitorHandlers.ts
7
+ const monitorHandlers = [
8
+ msw.http.get(`${_northern_tech_utils_constants.monitorApiUrlv1}/devices/:id/alerts`, () => new msw.HttpResponse(JSON.stringify([]), { headers: { [_northern_tech_utils_constants.headerNames.total]: 1 } })),
9
+ msw.http.get(`${_northern_tech_utils_constants.monitorApiUrlv1}/devices/:id/alerts/latest`, () => msw.HttpResponse.json([])),
10
+ msw.http.get(`${_northern_tech_utils_constants.monitorApiUrlv1}/devices/:id/config`, ({ params: { id } }) => {
11
+ if (id === require_mockData.mockApiResponses.devices.byId.a1.id) return msw.HttpResponse.json([{ something: "here" }]);
12
+ return msw.HttpResponse.json([]);
13
+ }),
14
+ msw.http.put(`${_northern_tech_utils_constants.monitorApiUrlv1}/settings/global/channel/alerts/:channel/status`, async ({ params: { channel }, request }) => {
15
+ const { enabled } = await request.json();
16
+ if (Object.keys(_northern_tech_utils_constants.alertChannels).includes(channel) && enabled !== void 0) return new msw.HttpResponse(null, { status: 200 });
17
+ return new msw.HttpResponse(null, { status: 590 });
18
+ })
19
+ ];
20
+ //#endregion
21
+ exports.monitorHandlers = monitorHandlers;
22
+
23
+ //# sourceMappingURL=monitorHandlers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitorHandlers.cjs","names":["http","monitorApiUrlv1","HttpResponse","headerNames","mockApiResponses","alertChannels"],"sources":["../../src/requestHandlers/monitorHandlers.ts"],"sourcesContent":["// Copyright 2021 Northern.tech AS\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//@ts-nocheck\nimport { alertChannels, headerNames, monitorApiUrlv1 } from '@northern.tech/utils/constants';\nimport { HttpResponse, http } from 'msw';\n\nimport { mockApiResponses } from '../mockData';\n\nexport const monitorHandlers = [\n http.get(`${monitorApiUrlv1}/devices/:id/alerts`, () => new HttpResponse(JSON.stringify([]), { headers: { [headerNames.total]: 1 } })),\n http.get(`${monitorApiUrlv1}/devices/:id/alerts/latest`, () => HttpResponse.json([])),\n http.get(`${monitorApiUrlv1}/devices/:id/config`, ({ params: { id } }) => {\n if (id === mockApiResponses.devices.byId.a1.id) {\n return HttpResponse.json([{ something: 'here' }]);\n }\n return HttpResponse.json([]);\n }),\n http.put(`${monitorApiUrlv1}/settings/global/channel/alerts/:channel/status`, async ({ params: { channel }, request }) => {\n const { enabled } = await request.json();\n if (Object.keys(alertChannels).includes(channel) && enabled !== undefined) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 590 });\n })\n];\n"],"mappings":";;;;;;AAmBA,MAAa,kBAAkB;CAC7BA,IAAAA,KAAK,IAAI,GAAGC,+BAAAA,gBAAgB,4BAA4B,IAAIC,IAAAA,aAAa,KAAK,UAAU,EAAE,CAAC,EAAE,EAAE,SAAS,GAAGC,+BAAAA,YAAY,QAAQ,GAAG,EAAE,CAAC,CAAC;CACtIH,IAAAA,KAAK,IAAI,GAAGC,+BAAAA,gBAAgB,mCAAmCC,IAAAA,aAAa,KAAK,EAAE,CAAC,CAAC;CACrFF,IAAAA,KAAK,IAAI,GAAGC,+BAAAA,gBAAgB,uBAAuB,EAAE,QAAQ,EAAE,WAAW;AACxE,MAAI,OAAOG,iBAAAA,iBAAiB,QAAQ,KAAK,GAAG,GAC1C,QAAOF,IAAAA,aAAa,KAAK,CAAC,EAAE,WAAW,QAAQ,CAAC,CAAC;AAEnD,SAAOA,IAAAA,aAAa,KAAK,EAAE,CAAC;GAC5B;CACFF,IAAAA,KAAK,IAAI,GAAGC,+BAAAA,gBAAgB,kDAAkD,OAAO,EAAE,QAAQ,EAAE,WAAW,cAAc;EACxH,MAAM,EAAE,YAAY,MAAM,QAAQ,MAAM;AACxC,MAAI,OAAO,KAAKI,+BAAAA,cAAc,CAAC,SAAS,QAAQ,IAAI,YAAY,KAAA,EAC9D,QAAO,IAAIH,IAAAA,aAAa,MAAM,EAAE,QAAQ,KAAK,CAAC;AAEhD,SAAO,IAAIA,IAAAA,aAAa,MAAM,EAAE,QAAQ,KAAK,CAAC;GAC9C;CACH"}
@@ -0,0 +1,7 @@
1
+ import * as _$msw from "msw";
2
+
3
+ //#region src/requestHandlers/monitorHandlers.d.ts
4
+ declare const monitorHandlers: _$msw.HttpHandler[];
5
+ //#endregion
6
+ export { monitorHandlers };
7
+ //# sourceMappingURL=monitorHandlers.d.cts.map
@@ -0,0 +1,7 @@
1
+ import * as _$msw from "msw";
2
+
3
+ //#region src/requestHandlers/monitorHandlers.d.ts
4
+ declare const monitorHandlers: _$msw.HttpHandler[];
5
+ //#endregion
6
+ export { monitorHandlers };
7
+ //# sourceMappingURL=monitorHandlers.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { mockApiResponses } from "../mockData.js";
2
+ import { alertChannels, headerNames, monitorApiUrlv1 } from "@northern.tech/utils/constants";
3
+ import { HttpResponse, http } from "msw";
4
+ //#region src/requestHandlers/monitorHandlers.ts
5
+ const monitorHandlers = [
6
+ http.get(`${monitorApiUrlv1}/devices/:id/alerts`, () => new HttpResponse(JSON.stringify([]), { headers: { [headerNames.total]: 1 } })),
7
+ http.get(`${monitorApiUrlv1}/devices/:id/alerts/latest`, () => HttpResponse.json([])),
8
+ http.get(`${monitorApiUrlv1}/devices/:id/config`, ({ params: { id } }) => {
9
+ if (id === mockApiResponses.devices.byId.a1.id) return HttpResponse.json([{ something: "here" }]);
10
+ return HttpResponse.json([]);
11
+ }),
12
+ http.put(`${monitorApiUrlv1}/settings/global/channel/alerts/:channel/status`, async ({ params: { channel }, request }) => {
13
+ const { enabled } = await request.json();
14
+ if (Object.keys(alertChannels).includes(channel) && enabled !== void 0) return new HttpResponse(null, { status: 200 });
15
+ return new HttpResponse(null, { status: 590 });
16
+ })
17
+ ];
18
+ //#endregion
19
+ export { monitorHandlers };
20
+
21
+ //# sourceMappingURL=monitorHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitorHandlers.js","names":[],"sources":["../../src/requestHandlers/monitorHandlers.ts"],"sourcesContent":["// Copyright 2021 Northern.tech AS\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//@ts-nocheck\nimport { alertChannels, headerNames, monitorApiUrlv1 } from '@northern.tech/utils/constants';\nimport { HttpResponse, http } from 'msw';\n\nimport { mockApiResponses } from '../mockData';\n\nexport const monitorHandlers = [\n http.get(`${monitorApiUrlv1}/devices/:id/alerts`, () => new HttpResponse(JSON.stringify([]), { headers: { [headerNames.total]: 1 } })),\n http.get(`${monitorApiUrlv1}/devices/:id/alerts/latest`, () => HttpResponse.json([])),\n http.get(`${monitorApiUrlv1}/devices/:id/config`, ({ params: { id } }) => {\n if (id === mockApiResponses.devices.byId.a1.id) {\n return HttpResponse.json([{ something: 'here' }]);\n }\n return HttpResponse.json([]);\n }),\n http.put(`${monitorApiUrlv1}/settings/global/channel/alerts/:channel/status`, async ({ params: { channel }, request }) => {\n const { enabled } = await request.json();\n if (Object.keys(alertChannels).includes(channel) && enabled !== undefined) {\n return new HttpResponse(null, { status: 200 });\n }\n return new HttpResponse(null, { status: 590 });\n })\n];\n"],"mappings":";;;;AAmBA,MAAa,kBAAkB;CAC7B,KAAK,IAAI,GAAG,gBAAgB,4BAA4B,IAAI,aAAa,KAAK,UAAU,EAAE,CAAC,EAAE,EAAE,SAAS,GAAG,YAAY,QAAQ,GAAG,EAAE,CAAC,CAAC;CACtI,KAAK,IAAI,GAAG,gBAAgB,mCAAmC,aAAa,KAAK,EAAE,CAAC,CAAC;CACrF,KAAK,IAAI,GAAG,gBAAgB,uBAAuB,EAAE,QAAQ,EAAE,WAAW;AACxE,MAAI,OAAO,iBAAiB,QAAQ,KAAK,GAAG,GAC1C,QAAO,aAAa,KAAK,CAAC,EAAE,WAAW,QAAQ,CAAC,CAAC;AAEnD,SAAO,aAAa,KAAK,EAAE,CAAC;GAC5B;CACF,KAAK,IAAI,GAAG,gBAAgB,kDAAkD,OAAO,EAAE,QAAQ,EAAE,WAAW,cAAc;EACxH,MAAM,EAAE,YAAY,MAAM,QAAQ,MAAM;AACxC,MAAI,OAAO,KAAK,cAAc,CAAC,SAAS,QAAQ,IAAI,YAAY,KAAA,EAC9D,QAAO,IAAI,aAAa,MAAM,EAAE,QAAQ,KAAK,CAAC;AAEhD,SAAO,IAAI,aAAa,MAAM,EAAE,QAAQ,KAAK,CAAC;GAC9C;CACH"}