@edgeiq/edgeiq-api-js 1.7.5 → 1.7.6

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 (113) hide show
  1. package/dist/OIDC/index.js +137 -238
  2. package/dist/OIDC/models.js +1 -2
  3. package/dist/__tests__/auth.test.js +56 -147
  4. package/dist/__tests__/command.test.js +80 -202
  5. package/dist/__tests__/companies.test.js +121 -269
  6. package/dist/__tests__/deviceErrors.test.js +16 -62
  7. package/dist/__tests__/deviceTypes.test.js +78 -200
  8. package/dist/__tests__/devices.test.js +84 -221
  9. package/dist/__tests__/discoveredDevice.test.js +57 -145
  10. package/dist/__tests__/files.test.js +58 -152
  11. package/dist/__tests__/ingestors.test.js +70 -188
  12. package/dist/__tests__/integrations.test.js +95 -235
  13. package/dist/__tests__/lwm2m.test.js +17 -62
  14. package/dist/__tests__/notifications.test.js +16 -62
  15. package/dist/__tests__/pollableAttributes.test.js +60 -162
  16. package/dist/__tests__/rules.test.js +60 -162
  17. package/dist/__tests__/scheduledJobs.test.js +60 -162
  18. package/dist/__tests__/translators.test.js +60 -162
  19. package/dist/__tests__/users.test.js +77 -197
  20. package/dist/auth/index.js +94 -167
  21. package/dist/bulkResponses/index.js +44 -110
  22. package/dist/bulkResponses/models.js +1 -2
  23. package/dist/commandExecutions/index.js +39 -85
  24. package/dist/commandExecutions/models.js +1 -2
  25. package/dist/commands/index.js +196 -342
  26. package/dist/commands/models.js +2 -5
  27. package/dist/companies/index.js +150 -272
  28. package/dist/companies/models.js +1 -2
  29. package/dist/configurations/index.js +172 -310
  30. package/dist/configurations/models.js +1 -2
  31. package/dist/constants.js +69 -85
  32. package/dist/core/ModelClass.js +11 -18
  33. package/dist/core/handleResponseError.js +77 -81
  34. package/dist/core/index.js +30 -38
  35. package/dist/deviceConfigs/index.js +103 -201
  36. package/dist/deviceConfigs/models.js +1 -2
  37. package/dist/deviceErrors/index.js +44 -110
  38. package/dist/deviceErrors/models.js +1 -2
  39. package/dist/deviceLocationObservations/index.js +82 -164
  40. package/dist/deviceLocationObservations/models.js +1 -2
  41. package/dist/deviceTemplates/index.js +105 -203
  42. package/dist/deviceTemplates/models.js +1 -2
  43. package/dist/deviceTransferRequests/index.js +116 -222
  44. package/dist/deviceTransferRequests/models.js +1 -2
  45. package/dist/deviceTypes/index.js +328 -554
  46. package/dist/deviceTypes/models.js +1 -2
  47. package/dist/devices/index.js +630 -971
  48. package/dist/devices/models.js +1 -2
  49. package/dist/discoveredDevices/index.js +190 -328
  50. package/dist/discoveredDevices/models.js +1 -2
  51. package/dist/downstreamSystems/index.js +87 -177
  52. package/dist/downstreamSystems/models.js +1 -2
  53. package/dist/escrowDevices/index.js +103 -201
  54. package/dist/escrowDevices/models.js +1 -2
  55. package/dist/files/index.js +137 -251
  56. package/dist/files/models.js +1 -2
  57. package/dist/filtersParser.js +12 -17
  58. package/dist/gatewayCommands/index.js +103 -201
  59. package/dist/gatewayCommands/models.js +1 -2
  60. package/dist/helpers.js +10 -16
  61. package/dist/index.js +86 -142
  62. package/dist/ingestors/index.js +103 -201
  63. package/dist/ingestors/models.js +1 -2
  64. package/dist/integrations/index.js +159 -273
  65. package/dist/integrations/models.js +1 -2
  66. package/dist/log/models.js +1 -2
  67. package/dist/lwm2m/index.js +23 -72
  68. package/dist/lwm2m/models.js +1 -2
  69. package/dist/models/index.js +1 -2
  70. package/dist/models.js +1 -2
  71. package/dist/notifications/index.js +44 -110
  72. package/dist/notifications/models.js +1 -2
  73. package/dist/pollableAttributes/index.js +87 -177
  74. package/dist/pollableAttributes/models.js +1 -2
  75. package/dist/regions/index.js +72 -154
  76. package/dist/regions/models.js +1 -2
  77. package/dist/reports/index.js +88 -178
  78. package/dist/reports/models.js +1 -2
  79. package/dist/retryOptions/models.js +1 -2
  80. package/dist/rules/index.js +131 -245
  81. package/dist/rules/models.js +1 -2
  82. package/dist/scheduledJobs/index.js +183 -321
  83. package/dist/scheduledJobs/models.js +1 -2
  84. package/dist/secrets/index.js +88 -178
  85. package/dist/secrets/models.js +1 -2
  86. package/dist/settings/index.js +119 -227
  87. package/dist/settings/models.js +1 -2
  88. package/dist/settingsApplicationRecord/index.js +27 -65
  89. package/dist/settingsApplicationRecord/models.js +1 -2
  90. package/dist/softwareUpdates/index.js +194 -350
  91. package/dist/softwareUpdates/models.js +1 -2
  92. package/dist/stats/index.js +64 -126
  93. package/dist/stats/models.js +1 -2
  94. package/dist/systemCommandJobs/index.js +72 -154
  95. package/dist/systemCommandJobs/models.js +1 -2
  96. package/dist/systemCommands/index.js +87 -177
  97. package/dist/systemCommands/models.js +1 -2
  98. package/dist/testConstants.js +57 -71
  99. package/dist/translators/index.js +103 -201
  100. package/dist/translators/models.js +1 -2
  101. package/dist/userTypes/index.js +87 -177
  102. package/dist/userTypes/models.js +1 -2
  103. package/dist/users/index.js +149 -271
  104. package/dist/users/models.js +1 -2
  105. package/dist/workflowActions/index.js +132 -246
  106. package/dist/workflowActions/models.js +1 -2
  107. package/dist/workflowDefinitions/index.js +104 -202
  108. package/dist/workflowDefinitions/models.js +1 -2
  109. package/dist/workflowExecutions/index.js +27 -65
  110. package/dist/workflowExecutions/models.js +1 -2
  111. package/dist/workflows/index.js +39 -85
  112. package/dist/workflows/models.js +1 -2
  113. package/package.json +1 -1
@@ -1,15 +1,3 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,193 +7,83 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
8
  });
21
9
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var __1 = require("..");
51
- var __2 = require("..");
52
- var constants_1 = require("../constants");
53
- var helpers_1 = require("../helpers");
54
- var testConstants_1 = require("../testConstants");
55
- describe('Device Types', function () {
56
- __1.EdgeIQAPI.init(testConstants_1.stageURL);
57
- it('Given an authenticated user', function () { return __awaiter(void 0, void 0, void 0, function () {
58
- var result;
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
61
- case 0: return [4, __2.Authentication.login(testConstants_1.TestAuth.username, testConstants_1.TestAuth.pass)];
62
- case 1:
63
- result = _a.sent();
64
- expect(result.session_token).not.toBeNull();
65
- return [2];
66
- }
67
- });
68
- }); });
69
- var testDevice = testConstants_1.EmptyDevice;
70
- var deviceType = testConstants_1.EmptyDeviceType;
71
- var deviceType2 = testConstants_1.EmptyDeviceType;
72
- it('Creates a device type', function () { return __awaiter(void 0, void 0, void 0, function () {
73
- var result;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
76
- case 0: return [4, __1.DeviceTypes.create(testConstants_1.TestDeviceType)];
77
- case 1:
78
- result = _a.sent();
79
- expect(result._id).not.toBeNull();
80
- expect(result.name).toBe(testConstants_1.TestDeviceType.name);
81
- deviceType = result;
82
- return [2];
83
- }
84
- });
85
- }); });
86
- it('Prepare a device to assign a device type', function () { return __awaiter(void 0, void 0, void 0, function () {
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
89
- case 0: return [4, __1.Devices.create(__assign(__assign({}, testConstants_1.TestDevice), { device_type_id: deviceType._id }))];
90
- case 1:
91
- testDevice = _a.sent();
92
- expect(testDevice._id).not.toBeNull();
93
- return [2];
94
- }
95
- });
96
- }); });
97
- it('Creates a second device type', function () { return __awaiter(void 0, void 0, void 0, function () {
98
- var result;
99
- return __generator(this, function (_a) {
100
- switch (_a.label) {
101
- case 0: return [4, __1.DeviceTypes.create(testConstants_1.TestDeviceType2)];
102
- case 1:
103
- result = _a.sent();
104
- expect(result._id).not.toBeNull();
105
- expect(result.name).toBe(testConstants_1.TestDeviceType2.name);
106
- deviceType2 = result;
107
- return [2];
108
- }
109
- });
110
- }); });
111
- it('Gets the first device type created by _id', function () { return __awaiter(void 0, void 0, void 0, function () {
112
- var result;
113
- return __generator(this, function (_a) {
114
- switch (_a.label) {
115
- case 0: return [4, __1.DeviceTypes.getOneById(deviceType._id)];
116
- case 1:
117
- result = _a.sent();
118
- expect(result.name).toBe(deviceType.name);
119
- return [2];
120
- }
121
- });
122
- }); });
123
- it('Updates a device type', function () { return __awaiter(void 0, void 0, void 0, function () {
124
- var result;
125
- return __generator(this, function (_a) {
126
- switch (_a.label) {
127
- case 0:
128
- if (!deviceType._id) return [3, 2];
129
- return [4, __1.DeviceTypes.update(__assign(__assign({}, deviceType), { name: testConstants_1.NewTestDeviceTypeName }))];
130
- case 1:
131
- result = _a.sent();
132
- expect(result.name).toBe(testConstants_1.NewTestDeviceTypeName);
133
- _a.label = 2;
134
- case 2: return [2];
135
- }
136
- });
137
- }); });
138
- it('List the device types created', function () { return __awaiter(void 0, void 0, void 0, function () {
139
- var filters, result;
140
- return __generator(this, function (_a) {
141
- switch (_a.label) {
142
- case 0:
143
- filters = {
144
- name: {
145
- operator: 'like',
146
- value: testConstants_1.TestDeviceType.name,
147
- },
148
- };
149
- return [4, __1.DeviceTypes.list(filters)];
150
- case 1:
151
- result = _a.sent();
152
- expect(result.deviceTypes).toBeDefined();
153
- expect(result.deviceTypes).toBeInstanceOf(Array);
154
- expect(result.deviceTypes).toHaveLength(3);
155
- expect(result.pagination.page).toBe(constants_1.DefaultPagination.page);
156
- expect(result.pagination.total).toBe(3);
157
- expect(result.pagination.itemsPerPage).toBe(constants_1.DefaultPagination.itemsPerPage);
158
- return [2];
159
- }
160
- });
161
- }); });
162
- it('Throw an error after a delete attempt of a deviceType with devices', function () { return __awaiter(void 0, void 0, void 0, function () {
163
- var error_1;
164
- return __generator(this, function (_a) {
165
- switch (_a.label) {
166
- case 0:
167
- _a.trys.push([0, 2, , 3]);
168
- return [4, __1.DeviceTypes.delete(deviceType._id)];
169
- case 1:
170
- _a.sent();
171
- return [3, 3];
172
- case 2:
173
- error_1 = _a.sent();
174
- if ((0, helpers_1.isApiError)(error_1)) {
175
- expect(error_1.message).toBe("Device Type currently in use by Device(s): [" + testDevice._id + "]");
176
- }
177
- return [3, 3];
178
- case 3: return [2];
179
- }
180
- });
181
- }); });
182
- it('Deletes the device types created', function () { return __awaiter(void 0, void 0, void 0, function () {
183
- var result, result, result;
184
- return __generator(this, function (_a) {
185
- switch (_a.label) {
186
- case 0:
187
- if (!testDevice._id) return [3, 2];
188
- return [4, __1.Devices.delete(testDevice._id)];
189
- case 1:
190
- result = _a.sent();
191
- expect(result).toBe((0, helpers_1.getReturnDeleteMessage)('device'));
192
- _a.label = 2;
193
- case 2:
194
- if (!deviceType._id) return [3, 4];
195
- return [4, __1.DeviceTypes.delete(deviceType._id)];
196
- case 3:
197
- result = _a.sent();
198
- expect(result).toBe((0, helpers_1.getReturnDeleteMessage)('device type'));
199
- _a.label = 4;
200
- case 4:
201
- if (!deviceType2._id) return [3, 6];
202
- return [4, __1.DeviceTypes.delete(deviceType2._id)];
203
- case 5:
204
- result = _a.sent();
205
- expect(result).toBe((0, helpers_1.getReturnDeleteMessage)('device type'));
206
- _a.label = 6;
207
- case 6: return [2];
10
+ import { EdgeIQAPI, DeviceTypes, Devices } from '..';
11
+ import { Authentication } from '..';
12
+ import { DefaultPagination } from '../constants';
13
+ import { getReturnDeleteMessage, isApiError } from '../helpers';
14
+ import { TestAuth, TestDeviceType, TestDeviceType2, EmptyDeviceType, NewTestDeviceTypeName, stageURL, TestDevice, EmptyDevice, } from '../testConstants';
15
+ describe('Device Types', () => {
16
+ EdgeIQAPI.init(stageURL);
17
+ it('Given an authenticated user', () => __awaiter(void 0, void 0, void 0, function* () {
18
+ const result = yield Authentication.login(TestAuth.username, TestAuth.pass);
19
+ expect(result.session_token).not.toBeNull();
20
+ }));
21
+ let testDevice = EmptyDevice;
22
+ let deviceType = EmptyDeviceType;
23
+ let deviceType2 = EmptyDeviceType;
24
+ it('Creates a device type', () => __awaiter(void 0, void 0, void 0, function* () {
25
+ const result = yield DeviceTypes.create(TestDeviceType);
26
+ expect(result._id).not.toBeNull();
27
+ expect(result.name).toBe(TestDeviceType.name);
28
+ deviceType = result;
29
+ }));
30
+ it('Prepare a device to assign a device type', () => __awaiter(void 0, void 0, void 0, function* () {
31
+ testDevice = yield Devices.create(Object.assign(Object.assign({}, TestDevice), { device_type_id: deviceType._id }));
32
+ expect(testDevice._id).not.toBeNull();
33
+ }));
34
+ it('Creates a second device type', () => __awaiter(void 0, void 0, void 0, function* () {
35
+ const result = yield DeviceTypes.create(TestDeviceType2);
36
+ expect(result._id).not.toBeNull();
37
+ expect(result.name).toBe(TestDeviceType2.name);
38
+ deviceType2 = result;
39
+ }));
40
+ it('Gets the first device type created by _id', () => __awaiter(void 0, void 0, void 0, function* () {
41
+ const result = yield DeviceTypes.getOneById(deviceType._id);
42
+ expect(result.name).toBe(deviceType.name);
43
+ }));
44
+ it('Updates a device type', () => __awaiter(void 0, void 0, void 0, function* () {
45
+ if (deviceType._id) {
46
+ const result = yield DeviceTypes.update(Object.assign(Object.assign({}, deviceType), { name: NewTestDeviceTypeName }));
47
+ expect(result.name).toBe(NewTestDeviceTypeName);
48
+ }
49
+ }));
50
+ it('List the device types created', () => __awaiter(void 0, void 0, void 0, function* () {
51
+ const filters = {
52
+ name: {
53
+ operator: 'like',
54
+ value: TestDeviceType.name,
55
+ },
56
+ };
57
+ const result = yield DeviceTypes.list(filters);
58
+ expect(result.deviceTypes).toBeDefined();
59
+ expect(result.deviceTypes).toBeInstanceOf(Array);
60
+ expect(result.deviceTypes).toHaveLength(3);
61
+ expect(result.pagination.page).toBe(DefaultPagination.page);
62
+ expect(result.pagination.total).toBe(3);
63
+ expect(result.pagination.itemsPerPage).toBe(DefaultPagination.itemsPerPage);
64
+ }));
65
+ it('Throw an error after a delete attempt of a deviceType with devices', () => __awaiter(void 0, void 0, void 0, function* () {
66
+ try {
67
+ yield DeviceTypes.delete(deviceType._id);
68
+ }
69
+ catch (error) {
70
+ if (isApiError(error)) {
71
+ expect(error.message).toBe(`Device Type currently in use by Device(s): [${testDevice._id}]`);
208
72
  }
209
- });
210
- }); });
73
+ }
74
+ }));
75
+ it('Deletes the device types created', () => __awaiter(void 0, void 0, void 0, function* () {
76
+ if (testDevice._id) {
77
+ const result = yield Devices.delete(testDevice._id);
78
+ expect(result).toBe(getReturnDeleteMessage('device'));
79
+ }
80
+ if (deviceType._id) {
81
+ const result = yield DeviceTypes.delete(deviceType._id);
82
+ expect(result).toBe(getReturnDeleteMessage('device type'));
83
+ }
84
+ if (deviceType2._id) {
85
+ const result = yield DeviceTypes.delete(deviceType2._id);
86
+ expect(result).toBe(getReturnDeleteMessage('device type'));
87
+ }
88
+ }));
211
89
  });
@@ -1,15 +1,3 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,214 +7,89 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
8
  });
21
9
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var __1 = require("..");
51
- var constants_1 = require("../constants");
52
- var helpers_1 = require("../helpers");
53
- var testConstants_1 = require("../testConstants");
54
- describe('Devices', function () {
55
- __1.EdgeIQAPI.init(testConstants_1.stageURL);
56
- it('Given an authenticated user', function () { return __awaiter(void 0, void 0, void 0, function () {
57
- var result;
58
- return __generator(this, function (_a) {
59
- switch (_a.label) {
60
- case 0: return [4, __1.Authentication.login(testConstants_1.TestAuth.username, testConstants_1.TestAuth.pass)];
61
- case 1:
62
- result = _a.sent();
63
- expect(result.session_token).not.toBeNull();
64
- return [2];
65
- }
66
- });
67
- }); });
68
- var targetDeviceType;
69
- it('Given a device type', function () { return __awaiter(void 0, void 0, void 0, function () {
70
- var deviceTypeOptions, dtresult;
71
- return __generator(this, function (_a) {
72
- switch (_a.label) {
73
- case 0:
74
- deviceTypeOptions = JSON.parse(JSON.stringify(testConstants_1.TestDeviceType));
75
- deviceTypeOptions.name = 'js_sdk_discovered_device_test_device_type';
76
- return [4, __1.DeviceTypes.create(testConstants_1.TestDeviceType)];
77
- case 1:
78
- dtresult = _a.sent();
79
- expect(dtresult._id).not.toBeNull();
80
- targetDeviceType = dtresult;
81
- return [2];
82
- }
83
- });
84
- }); });
85
- var device = testConstants_1.EmptyDevice;
86
- var device2 = testConstants_1.EmptyDevice;
87
- it('Creates a device', function () { return __awaiter(void 0, void 0, void 0, function () {
88
- var result;
89
- return __generator(this, function (_a) {
90
- switch (_a.label) {
91
- case 0: return [4, __1.Devices.create(__assign(__assign({}, testConstants_1.TestDevice), { device_type_id: targetDeviceType._id }))];
92
- case 1:
93
- result = _a.sent();
94
- expect(result._id).not.toBeNull();
95
- expect(result.unique_id).toBe(testConstants_1.TestDevice.unique_id);
96
- device = result;
97
- return [2];
98
- }
99
- });
100
- }); });
101
- it('Device already exists', function () { return __awaiter(void 0, void 0, void 0, function () {
102
- var error_1;
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
- case 0:
106
- _a.trys.push([0, 2, , 3]);
107
- return [4, __1.Devices.create(__assign(__assign({}, testConstants_1.TestDevice), { device_type_id: targetDeviceType._id }))];
108
- case 1:
109
- _a.sent();
110
- return [3, 3];
111
- case 2:
112
- error_1 = _a.sent();
113
- if ((0, helpers_1.isApiError)(error_1)) {
114
- expect(error_1.message).toBe(constants_1.ResponseErrorsMessages.deviceId(testConstants_1.TestDevice.unique_id));
115
- }
116
- return [3, 3];
117
- case 3: return [2];
118
- }
119
- });
120
- }); });
121
- it('Creates a second device', function () { return __awaiter(void 0, void 0, void 0, function () {
122
- var result;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0: return [4, __1.Devices.create(__assign(__assign({}, testConstants_1.TestDevice2), { device_type_id: targetDeviceType._id }))];
126
- case 1:
127
- result = _a.sent();
128
- expect(result._id).not.toBeNull();
129
- expect(result.unique_id).toBe(testConstants_1.TestDevice2.unique_id);
130
- device2 = result;
131
- return [2];
132
- }
133
- });
134
- }); });
135
- it('Gets the first device created by _id', function () { return __awaiter(void 0, void 0, void 0, function () {
136
- var result;
137
- return __generator(this, function (_a) {
138
- switch (_a.label) {
139
- case 0: return [4, __1.Devices.getOneById(device._id)];
140
- case 1:
141
- result = _a.sent();
142
- expect(result.unique_id).toBe(device.unique_id);
143
- return [2];
144
- }
145
- });
146
- }); });
147
- it('Gets the second device created by unique_id', function () { return __awaiter(void 0, void 0, void 0, function () {
148
- var result;
149
- return __generator(this, function (_a) {
150
- switch (_a.label) {
151
- case 0: return [4, __1.Devices.getOneByUniqueId(device2.unique_id)];
152
- case 1:
153
- result = _a.sent();
154
- expect(result.unique_id).toBe(device2.unique_id);
155
- return [2];
156
- }
157
- });
158
- }); });
159
- it('Updates a device', function () { return __awaiter(void 0, void 0, void 0, function () {
160
- var result;
161
- return __generator(this, function (_a) {
162
- switch (_a.label) {
163
- case 0:
164
- if (!device._id) return [3, 2];
165
- return [4, __1.Devices.update(__assign(__assign({}, device), { name: testConstants_1.NewTestDeviceName }))];
166
- case 1:
167
- result = _a.sent();
168
- expect(result.name).toBe(testConstants_1.NewTestDeviceName);
169
- _a.label = 2;
170
- case 2: return [2];
171
- }
172
- });
173
- }); });
174
- it('List the devices created', function () { return __awaiter(void 0, void 0, void 0, function () {
175
- var filters, result;
176
- return __generator(this, function (_a) {
177
- switch (_a.label) {
178
- case 0:
179
- filters = {
180
- unique_id: {
181
- operator: 'like',
182
- value: testConstants_1.TestDevice.unique_id,
183
- },
184
- };
185
- return [4, __1.Devices.list(filters)];
186
- case 1:
187
- result = _a.sent();
188
- expect(result.devices).toBeDefined();
189
- expect(result.devices).toBeInstanceOf(Array);
190
- expect(result.devices).toHaveLength(2);
191
- expect(result.pagination.page).toBe(constants_1.DefaultPagination.page);
192
- expect(result.pagination.total).toBe(2);
193
- expect(result.pagination.itemsPerPage).toBe(constants_1.DefaultPagination.itemsPerPage);
194
- return [2];
195
- }
196
- });
197
- }); });
198
- it('Delete the devices created', function () { return __awaiter(void 0, void 0, void 0, function () {
199
- var result, result;
200
- return __generator(this, function (_a) {
201
- switch (_a.label) {
202
- case 0:
203
- if (!device._id) return [3, 2];
204
- return [4, __1.Devices.delete(device._id)];
205
- case 1:
206
- result = _a.sent();
207
- expect(result).toBe((0, helpers_1.getReturnDeleteMessage)('device'));
208
- _a.label = 2;
209
- case 2:
210
- if (!device2._id) return [3, 4];
211
- return [4, __1.Devices.delete(device2._id)];
212
- case 3:
213
- result = _a.sent();
214
- expect(result).toBe((0, helpers_1.getReturnDeleteMessage)('device'));
215
- _a.label = 4;
216
- case 4: return [2];
217
- }
218
- });
219
- }); });
220
- it('cleans up', function () { return __awaiter(void 0, void 0, void 0, function () {
221
- var dtresult;
222
- return __generator(this, function (_a) {
223
- switch (_a.label) {
224
- case 0: return [4, __1.DeviceTypes.delete(targetDeviceType._id)];
225
- case 1:
226
- dtresult = _a.sent();
227
- expect(dtresult).toBe((0, helpers_1.getReturnDeleteMessage)('device type'));
228
- return [2];
10
+ import { EdgeIQAPI, Authentication, Devices, DeviceTypes, } from '..';
11
+ import { DefaultPagination, ResponseErrorsMessages } from '../constants';
12
+ import { getReturnDeleteMessage, isApiError } from '../helpers';
13
+ import { TestAuth, TestDevice, NewTestDeviceName, TestDevice2, EmptyDevice, TestDeviceType, stageURL, } from '../testConstants';
14
+ describe('Devices', () => {
15
+ EdgeIQAPI.init(stageURL);
16
+ it('Given an authenticated user', () => __awaiter(void 0, void 0, void 0, function* () {
17
+ const result = yield Authentication.login(TestAuth.username, TestAuth.pass);
18
+ expect(result.session_token).not.toBeNull();
19
+ }));
20
+ let targetDeviceType;
21
+ it('Given a device type', () => __awaiter(void 0, void 0, void 0, function* () {
22
+ const deviceTypeOptions = JSON.parse(JSON.stringify(TestDeviceType));
23
+ deviceTypeOptions.name = 'js_sdk_discovered_device_test_device_type';
24
+ const dtresult = yield DeviceTypes.create(TestDeviceType);
25
+ expect(dtresult._id).not.toBeNull();
26
+ targetDeviceType = dtresult;
27
+ }));
28
+ let device = EmptyDevice;
29
+ let device2 = EmptyDevice;
30
+ it('Creates a device', () => __awaiter(void 0, void 0, void 0, function* () {
31
+ const result = yield Devices.create(Object.assign(Object.assign({}, TestDevice), { device_type_id: targetDeviceType._id }));
32
+ expect(result._id).not.toBeNull();
33
+ expect(result.unique_id).toBe(TestDevice.unique_id);
34
+ device = result;
35
+ }));
36
+ it('Device already exists', () => __awaiter(void 0, void 0, void 0, function* () {
37
+ try {
38
+ yield Devices.create(Object.assign(Object.assign({}, TestDevice), { device_type_id: targetDeviceType._id }));
39
+ }
40
+ catch (error) {
41
+ if (isApiError(error)) {
42
+ expect(error.message).toBe(ResponseErrorsMessages.deviceId(TestDevice.unique_id));
229
43
  }
230
- });
231
- }); });
44
+ }
45
+ }));
46
+ it('Creates a second device', () => __awaiter(void 0, void 0, void 0, function* () {
47
+ const result = yield Devices.create(Object.assign(Object.assign({}, TestDevice2), { device_type_id: targetDeviceType._id }));
48
+ expect(result._id).not.toBeNull();
49
+ expect(result.unique_id).toBe(TestDevice2.unique_id);
50
+ device2 = result;
51
+ }));
52
+ it('Gets the first device created by _id', () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const result = yield Devices.getOneById(device._id);
54
+ expect(result.unique_id).toBe(device.unique_id);
55
+ }));
56
+ it('Gets the second device created by unique_id', () => __awaiter(void 0, void 0, void 0, function* () {
57
+ const result = yield Devices.getOneByUniqueId(device2.unique_id);
58
+ expect(result.unique_id).toBe(device2.unique_id);
59
+ }));
60
+ it('Updates a device', () => __awaiter(void 0, void 0, void 0, function* () {
61
+ if (device._id) {
62
+ const result = yield Devices.update(Object.assign(Object.assign({}, device), { name: NewTestDeviceName }));
63
+ expect(result.name).toBe(NewTestDeviceName);
64
+ }
65
+ }));
66
+ it('List the devices created', () => __awaiter(void 0, void 0, void 0, function* () {
67
+ const filters = {
68
+ unique_id: {
69
+ operator: 'like',
70
+ value: TestDevice.unique_id,
71
+ },
72
+ };
73
+ const result = yield Devices.list(filters);
74
+ expect(result.devices).toBeDefined();
75
+ expect(result.devices).toBeInstanceOf(Array);
76
+ expect(result.devices).toHaveLength(2);
77
+ expect(result.pagination.page).toBe(DefaultPagination.page);
78
+ expect(result.pagination.total).toBe(2);
79
+ expect(result.pagination.itemsPerPage).toBe(DefaultPagination.itemsPerPage);
80
+ }));
81
+ it('Delete the devices created', () => __awaiter(void 0, void 0, void 0, function* () {
82
+ if (device._id) {
83
+ const result = yield Devices.delete(device._id);
84
+ expect(result).toBe(getReturnDeleteMessage('device'));
85
+ }
86
+ if (device2._id) {
87
+ const result = yield Devices.delete(device2._id);
88
+ expect(result).toBe(getReturnDeleteMessage('device'));
89
+ }
90
+ }));
91
+ it('cleans up', () => __awaiter(void 0, void 0, void 0, function* () {
92
+ const dtresult = yield DeviceTypes.delete(targetDeviceType._id);
93
+ expect(dtresult).toBe(getReturnDeleteMessage('device type'));
94
+ }));
232
95
  });