@ndustrial/contxt-sdk 4.3.6 → 5.2.0

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 (167) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +8 -0
  3. package/CODEOWNERS +1 -0
  4. package/docs/Facilities.md +0 -144
  5. package/docs/FacilityGroupings.md +0 -160
  6. package/docs/Nionic.md +63 -0
  7. package/docs/README.md +3 -29
  8. package/docs/Typedefs.md +0 -101
  9. package/esm/config/audiences.js +13 -13
  10. package/esm/config/audiences.js.map +1 -1
  11. package/esm/index.js +4 -6
  12. package/esm/index.js.map +1 -1
  13. package/esm/nionic/index.js +126 -0
  14. package/esm/nionic/index.js.map +1 -0
  15. package/lib/config/audiences.js +13 -13
  16. package/lib/config/audiences.js.map +1 -1
  17. package/lib/index.js +10 -15
  18. package/lib/index.js.map +1 -1
  19. package/lib/nionic/index.js +130 -0
  20. package/lib/nionic/index.js.map +1 -0
  21. package/meta.yaml +11 -0
  22. package/package.json +9 -10
  23. package/src/bus/index.spec.js +3 -2
  24. package/src/bus/webSocketConnection.spec.js +31 -31
  25. package/src/config/audiences.js +13 -13
  26. package/src/config/index.spec.js +6 -6
  27. package/src/coordinator/applications.spec.js +8 -8
  28. package/src/coordinator/consent.spec.js +1 -1
  29. package/src/coordinator/edgeNodes.spec.js +3 -3
  30. package/src/coordinator/organizations.spec.js +4 -4
  31. package/src/coordinator/permissions.spec.js +4 -4
  32. package/src/coordinator/roles.spec.js +3 -3
  33. package/src/coordinator/users.spec.js +14 -15
  34. package/src/events/index.spec.js +16 -16
  35. package/src/files/index.spec.js +7 -7
  36. package/src/index.js +4 -6
  37. package/src/index.spec.js +8 -22
  38. package/src/iot/feeds.spec.js +4 -4
  39. package/src/iot/fieldCategories.spec.js +4 -4
  40. package/src/iot/fieldGroupings.spec.js +5 -5
  41. package/src/iot/outputs.spec.js +6 -6
  42. package/src/nionic/index.js +151 -0
  43. package/src/request.spec.js +3 -3
  44. package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
  45. package/src/sessionTypes/index.spec.js +3 -3
  46. package/src/sessionTypes/machineAuth.spec.js +3 -3
  47. package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
  48. package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
  49. package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
  50. package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
  51. package/src/utils/url/stringifyParams.spec.js +2 -3
  52. package/support/fixtures/factories/IOSDevice.js +3 -3
  53. package/support/fixtures/factories/applicationGrouping.js +4 -4
  54. package/support/fixtures/factories/applicationModule.js +2 -2
  55. package/support/fixtures/factories/asset.js +1 -1
  56. package/support/fixtures/factories/assetAttribute.js +2 -2
  57. package/support/fixtures/factories/assetAttributeValue.js +2 -2
  58. package/support/fixtures/factories/assetMetric.js +1 -1
  59. package/support/fixtures/factories/assetMetricValue.js +3 -3
  60. package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
  61. package/support/fixtures/factories/assetType.js +1 -1
  62. package/support/fixtures/factories/authResults.js +3 -3
  63. package/support/fixtures/factories/channel.js +1 -1
  64. package/support/fixtures/factories/contxtApplication.js +5 -5
  65. package/support/fixtures/factories/contxtOrganization.js +2 -2
  66. package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
  67. package/support/fixtures/factories/contxtProject.js +2 -2
  68. package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
  69. package/support/fixtures/factories/contxtRole.js +3 -3
  70. package/support/fixtures/factories/contxtRoleApplication.js +1 -1
  71. package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
  72. package/support/fixtures/factories/contxtUser.js +2 -2
  73. package/support/fixtures/factories/contxtUserApplication.js +1 -1
  74. package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
  75. package/support/fixtures/factories/contxtUserPermissions.js +5 -5
  76. package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
  77. package/support/fixtures/factories/contxtUserRole.js +2 -2
  78. package/support/fixtures/factories/costCenter.js +2 -2
  79. package/support/fixtures/factories/costCenterFacility.js +3 -3
  80. package/support/fixtures/factories/edgeNode.js +1 -1
  81. package/support/fixtures/factories/event.js +5 -5
  82. package/support/fixtures/factories/eventType.js +4 -4
  83. package/support/fixtures/factories/eventUser.js +5 -5
  84. package/support/fixtures/factories/facility.js +4 -4
  85. package/support/fixtures/factories/facilityGrouping.js +3 -3
  86. package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
  87. package/support/fixtures/factories/facilityInfo.js +2 -2
  88. package/support/fixtures/factories/facilityTag.js +1 -1
  89. package/support/fixtures/factories/feedStatus.js +1 -1
  90. package/support/fixtures/factories/feedType.js +1 -1
  91. package/support/fixtures/factories/feeds.js +5 -5
  92. package/support/fixtures/factories/fieldCategory.js +3 -3
  93. package/support/fixtures/factories/fieldGrouping.js +4 -4
  94. package/support/fixtures/factories/fieldGroupingField.js +3 -3
  95. package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
  96. package/support/fixtures/factories/file.js +1 -1
  97. package/support/fixtures/factories/fileUploadInfo.js +1 -1
  98. package/support/fixtures/factories/organization.js +1 -1
  99. package/support/fixtures/factories/outputField.js +10 -10
  100. package/support/fixtures/factories/outputFieldData.js +1 -1
  101. package/support/fixtures/factories/owner.js +2 -2
  102. package/support/fixtures/factories/paginationMetadata.js +2 -2
  103. package/support/fixtures/factories/triggeredEvent.js +4 -4
  104. package/support/fixtures/factories/userEventSubscription.js +1 -1
  105. package/support/fixtures/factories/userMobileNumber.js +1 -1
  106. package/support/fixtures/factories/userPermissionsMap.js +2 -2
  107. package/.huskyrc.js +0 -11
  108. package/.nycrc +0 -12
  109. package/esm/assets/assetAttributes.js +0 -574
  110. package/esm/assets/assetAttributes.js.map +0 -1
  111. package/esm/assets/assetMetrics.js +0 -690
  112. package/esm/assets/assetMetrics.js.map +0 -1
  113. package/esm/assets/assetTypes.js +0 -273
  114. package/esm/assets/assetTypes.js.map +0 -1
  115. package/esm/assets/index.js +0 -283
  116. package/esm/assets/index.js.map +0 -1
  117. package/esm/facilities/costCenters.js +0 -306
  118. package/esm/facilities/costCenters.js.map +0 -1
  119. package/esm/facilities/groupings.js +0 -323
  120. package/esm/facilities/groupings.js.map +0 -1
  121. package/esm/facilities/index.js +0 -343
  122. package/esm/facilities/index.js.map +0 -1
  123. package/esm/health/index.js +0 -229
  124. package/esm/health/index.js.map +0 -1
  125. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
  126. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  127. package/esm/utils/facilities/index.js +0 -4
  128. package/esm/utils/facilities/index.js.map +0 -1
  129. package/lib/assets/assetAttributes.js +0 -588
  130. package/lib/assets/assetAttributes.js.map +0 -1
  131. package/lib/assets/assetMetrics.js +0 -705
  132. package/lib/assets/assetMetrics.js.map +0 -1
  133. package/lib/assets/assetTypes.js +0 -287
  134. package/lib/assets/assetTypes.js.map +0 -1
  135. package/lib/assets/index.js +0 -302
  136. package/lib/assets/index.js.map +0 -1
  137. package/lib/facilities/costCenters.js +0 -316
  138. package/lib/facilities/costCenters.js.map +0 -1
  139. package/lib/facilities/groupings.js +0 -333
  140. package/lib/facilities/groupings.js.map +0 -1
  141. package/lib/facilities/index.js +0 -360
  142. package/lib/facilities/index.js.map +0 -1
  143. package/lib/health/index.js +0 -232
  144. package/lib/health/index.js.map +0 -1
  145. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
  146. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  147. package/lib/utils/facilities/index.js +0 -15
  148. package/lib/utils/facilities/index.js.map +0 -1
  149. package/src/assets/assetAttributes.js +0 -619
  150. package/src/assets/assetAttributes.spec.js +0 -1143
  151. package/src/assets/assetMetrics.js +0 -736
  152. package/src/assets/assetMetrics.spec.js +0 -1180
  153. package/src/assets/assetTypes.js +0 -260
  154. package/src/assets/assetTypes.spec.js +0 -556
  155. package/src/assets/index.js +0 -271
  156. package/src/assets/index.spec.js +0 -515
  157. package/src/facilities/costCenters.js +0 -295
  158. package/src/facilities/costCenters.spec.js +0 -529
  159. package/src/facilities/groupings.js +0 -320
  160. package/src/facilities/groupings.spec.js +0 -567
  161. package/src/facilities/index.js +0 -343
  162. package/src/facilities/index.spec.js +0 -551
  163. package/src/health/index.js +0 -200
  164. package/src/health/index.spec.js +0 -501
  165. package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
  166. package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
  167. package/src/utils/facilities/index.js +0 -3
@@ -1,551 +0,0 @@
1
- import omit from 'lodash.omit';
2
- import Facilities from './index';
3
- import * as facilitiesUtils from '../utils/facilities';
4
- import * as objectUtils from '../utils/objects';
5
-
6
- describe('Facilities', function() {
7
- let baseRequest;
8
- let baseSdk;
9
- let expectedHost;
10
-
11
- beforeEach(function() {
12
- baseRequest = {
13
- delete: sinon.stub().resolves(),
14
- get: sinon.stub().resolves(),
15
- post: sinon.stub().resolves(),
16
- put: sinon.stub().resolves()
17
- };
18
- baseSdk = {
19
- config: {
20
- audiences: {
21
- facilities: fixture.build('audience')
22
- }
23
- }
24
- };
25
- expectedHost = faker.internet.url();
26
- });
27
-
28
- afterEach(function() {
29
- sinon.restore();
30
- });
31
-
32
- describe('constructor', function() {
33
- let facilities;
34
-
35
- beforeEach(function() {
36
- facilities = new Facilities(baseSdk, baseRequest);
37
- });
38
-
39
- it('sets a base url for the class instance', function() {
40
- expect(facilities._baseUrl).to.equal(
41
- `${baseSdk.config.audiences.facilities.host}/v1`
42
- );
43
- });
44
-
45
- it('appends the supplied request module to the class instance', function() {
46
- expect(facilities._request).to.equal(baseRequest);
47
- });
48
-
49
- it('appends the supplied sdk to the class instance', function() {
50
- expect(facilities._sdk).to.equal(baseSdk);
51
- });
52
- });
53
-
54
- describe('create', function() {
55
- context('when all required information is supplied', function() {
56
- let expectedFacility;
57
- let formattedFacility;
58
- let initialFacility;
59
- let promise;
60
- let rawFacility;
61
- let request;
62
- let toCamelCase;
63
- let toSnakeCase;
64
-
65
- beforeEach(function() {
66
- expectedFacility = fixture.build('facility', null, {
67
- fromServer: true
68
- });
69
- formattedFacility = fixture.build('facility', null, {
70
- fromServer: true
71
- });
72
- initialFacility = fixture.build('facility');
73
- rawFacility = fixture.build('facility', null, {
74
- fromServer: true
75
- });
76
-
77
- request = {
78
- ...baseRequest,
79
- post: sinon.stub().resolves(rawFacility)
80
- };
81
- toCamelCase = sinon
82
- .stub(objectUtils, 'toCamelCase')
83
- .returns(expectedFacility);
84
- toSnakeCase = sinon
85
- .stub(objectUtils, 'toSnakeCase')
86
- .returns(formattedFacility);
87
-
88
- const facilities = new Facilities(baseSdk, request);
89
- facilities._baseUrl = expectedHost;
90
-
91
- promise = facilities.create(initialFacility);
92
- });
93
-
94
- it('formats the submitted facility object to send to the server', function() {
95
- expect(toSnakeCase).to.be.calledWith(initialFacility);
96
- });
97
-
98
- it('creates a new facility', function() {
99
- expect(request.post).to.be.deep.calledWith(
100
- `${expectedHost}/facilities`,
101
- formattedFacility
102
- );
103
- });
104
-
105
- it('formats the returned facility object', function() {
106
- return promise.then(() => {
107
- expect(toCamelCase).to.be.calledWith(rawFacility);
108
- });
109
- });
110
-
111
- it('returns a fulfilled promise with the new facility information', function() {
112
- return expect(promise).to.be.fulfilled.and.to.eventually.equal(
113
- expectedFacility
114
- );
115
- });
116
- });
117
-
118
- context('when there is missing required information', function() {
119
- ['organizationId', 'name', 'timezone'].forEach(function(field) {
120
- it(`it throws an error when ${field} is missing`, function() {
121
- const facility = fixture.build('facility');
122
- const initialFacility = {
123
- ...facility,
124
- organizationId: facility.organizationId
125
- };
126
- const facilities = new Facilities(baseSdk, baseRequest);
127
- const promise = facilities.create(omit(initialFacility, [field]));
128
-
129
- return expect(promise).to.be.rejectedWith(
130
- `A ${field} is required to create a new facility.`
131
- );
132
- });
133
- });
134
- });
135
- });
136
-
137
- describe('createOrUpdateInfo', function() {
138
- context('when all required information is available', function() {
139
- let facilityId;
140
- let facilityInfoUpdate;
141
- let promise;
142
-
143
- beforeEach(function() {
144
- facilityId = fixture.build('facility').id;
145
- facilityInfoUpdate = fixture.build('facilityInfo');
146
-
147
- const facilities = new Facilities(baseSdk, baseRequest);
148
- facilities._baseUrl = expectedHost;
149
-
150
- promise = facilities.createOrUpdateInfo(facilityId, facilityInfoUpdate);
151
- });
152
-
153
- it('updates the facility', function() {
154
- expect(baseRequest.post).to.be.calledWith(
155
- `${expectedHost}/facilities/${facilityId}/info`,
156
- facilityInfoUpdate,
157
- {
158
- params: {
159
- should_update: true
160
- }
161
- }
162
- );
163
- });
164
-
165
- it('returns a fulfilled promise', function() {
166
- return expect(promise).to.be.fulfilled;
167
- });
168
- });
169
-
170
- context(
171
- 'when there is missing or malformed required information',
172
- function() {
173
- let facilities;
174
-
175
- beforeEach(function() {
176
- facilities = new Facilities(baseSdk, baseRequest);
177
- });
178
-
179
- it('throws an error when there is no provided facility ID', function() {
180
- const facilityInfoUpdate = fixture.build('facilityInfo');
181
- const promise = facilities.createOrUpdateInfo(
182
- null,
183
- facilityInfoUpdate
184
- );
185
-
186
- return expect(promise).to.be.rejectedWith(
187
- "A facility ID is required to update a facility's info."
188
- );
189
- });
190
-
191
- it('throws an error when there is no update provided', function() {
192
- const facility = fixture.build('facility');
193
- const promise = facilities.createOrUpdateInfo(facility.id);
194
-
195
- return expect(promise).to.be.rejectedWith(
196
- "An update is required to update a facility's info."
197
- );
198
- });
199
-
200
- it('throws an error when the update is not an object', function() {
201
- const facility = fixture.build('facility');
202
- const promise = facilities.createOrUpdateInfo(facility.id, [
203
- facility.info
204
- ]);
205
-
206
- return expect(promise).to.be.rejectedWith(
207
- 'The facility info update must be a well-formed object with the data you wish to update.'
208
- );
209
- });
210
- }
211
- );
212
- });
213
-
214
- describe('delete', function() {
215
- context('the facility ID is provided', function() {
216
- let facility;
217
- let promise;
218
-
219
- beforeEach(function() {
220
- facility = fixture.build('facility');
221
-
222
- const facilities = new Facilities(baseSdk, baseRequest);
223
- facilities._baseUrl = expectedHost;
224
-
225
- promise = facilities.delete(facility.id);
226
- });
227
-
228
- it('requests to delete the facility', function() {
229
- expect(baseRequest.delete).to.be.calledWith(
230
- `${expectedHost}/facilities/${facility.id}`
231
- );
232
- });
233
-
234
- it('returns a resolved promise', function() {
235
- return expect(promise).to.be.fulfilled;
236
- });
237
- });
238
-
239
- context('the facility ID is not provided', function() {
240
- it('throws an error', function() {
241
- const facilities = new Facilities(baseSdk, baseRequest);
242
- const promise = facilities.delete();
243
-
244
- return expect(promise).to.be.rejectedWith(
245
- 'A facility ID is required for deleting a facility'
246
- );
247
- });
248
- });
249
- });
250
-
251
- describe('get', function() {
252
- context('the facility ID is provided', function() {
253
- let expectedFacilityId;
254
- let formatFacilityWithInfoFromServer;
255
- let formattedFacility;
256
- let promise;
257
- let rawFacility;
258
- let request;
259
-
260
- beforeEach(function() {
261
- expectedFacilityId = faker.random.number();
262
- rawFacility = fixture.build('facility', null, {
263
- fromServer: true
264
- });
265
- formattedFacility = fixture.build('facility', {
266
- id: rawFacility.id
267
- });
268
-
269
- formatFacilityWithInfoFromServer = sinon
270
- .stub(facilitiesUtils, 'formatFacilityWithInfoFromServer')
271
- .returns(formattedFacility);
272
- request = {
273
- ...baseRequest,
274
- get: sinon.stub().resolves(rawFacility)
275
- };
276
-
277
- const facilities = new Facilities(baseSdk, request);
278
- facilities._baseUrl = expectedHost;
279
-
280
- promise = facilities.get(expectedFacilityId);
281
- });
282
-
283
- it('gets the facility from the server', function() {
284
- expect(request.get).to.be.calledWith(
285
- `${expectedHost}/facilities/${expectedFacilityId}`
286
- );
287
- });
288
-
289
- it('formats the facility object', function() {
290
- return promise.then(() => {
291
- expect(formatFacilityWithInfoFromServer).to.be.calledWith(
292
- rawFacility
293
- );
294
- });
295
- });
296
-
297
- it('returns the requested facility', function() {
298
- return expect(promise).to.be.fulfilled.and.to.eventually.equal(
299
- formattedFacility
300
- );
301
- });
302
- });
303
-
304
- context('the facility ID is not provided', function() {
305
- it('throws an error', function() {
306
- const facilities = new Facilities(baseSdk, baseRequest);
307
- const promise = facilities.get();
308
-
309
- return expect(promise).to.be.rejectedWith(
310
- 'A facility ID is required for getting information about a facility'
311
- );
312
- });
313
- });
314
- });
315
-
316
- describe('getAll', function() {
317
- let formatFacilityWithInfoFromServer;
318
- let formattedFacilities;
319
- let promise;
320
- let rawFacilities;
321
- let request;
322
-
323
- beforeEach(function() {
324
- const numberOfFacilities = faker.random.number({
325
- min: 1,
326
- max: 10
327
- });
328
- formattedFacilities = fixture.buildList('facility', numberOfFacilities);
329
- rawFacilities = fixture.buildList('facility', numberOfFacilities, null, {
330
- fromServer: true
331
- });
332
-
333
- formatFacilityWithInfoFromServer = sinon
334
- .stub(facilitiesUtils, 'formatFacilityWithInfoFromServer')
335
- .callsFake((facility) => {
336
- const index = rawFacilities.indexOf(facility);
337
- return formattedFacilities[index];
338
- });
339
- request = {
340
- ...baseRequest,
341
- get: sinon.stub().resolves(rawFacilities)
342
- };
343
-
344
- const facilities = new Facilities(baseSdk, request);
345
- facilities._baseUrl = expectedHost;
346
-
347
- promise = facilities.getAll();
348
- });
349
-
350
- it('gets a list of facilities from the server', function() {
351
- expect(request.get).to.be.calledWith(`${expectedHost}/facilities`);
352
- });
353
-
354
- it('formats the facility object', function() {
355
- return promise.then(() => {
356
- expect(formatFacilityWithInfoFromServer).to.have.callCount(
357
- rawFacilities.length
358
- );
359
-
360
- rawFacilities.forEach((facility) => {
361
- expect(formatFacilityWithInfoFromServer).to.be.calledWith(facility);
362
- });
363
- });
364
- });
365
-
366
- it('returns a list of facilities', function() {
367
- return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal(
368
- formattedFacilities
369
- );
370
- });
371
- });
372
-
373
- describe('getAllByOrganizationId', function() {
374
- context('the organization ID is provided', function() {
375
- let expectedOrganizationId;
376
- let formatFacilityWithInfoFromServer;
377
- let formattedFacilities;
378
- let initialOptions;
379
- let promise;
380
- let rawFacilities;
381
- let rawFacilityOptions;
382
- let request;
383
- let toSnakeCase;
384
-
385
- beforeEach(function() {
386
- expectedOrganizationId = faker.random.number();
387
- const numberOfFacilities = faker.random.number({
388
- min: 1,
389
- max: 10
390
- });
391
- formattedFacilities = fixture.buildList('facility', numberOfFacilities);
392
- rawFacilities = fixture.buildList(
393
- 'facility',
394
- numberOfFacilities,
395
- null,
396
- {
397
- fromServer: true
398
- }
399
- );
400
- initialOptions = faker.helpers.createTransaction();
401
- rawFacilityOptions = faker.helpers.createTransaction();
402
-
403
- formatFacilityWithInfoFromServer = sinon
404
- .stub(facilitiesUtils, 'formatFacilityWithInfoFromServer')
405
- .callsFake((facility) => {
406
- const index = rawFacilities.indexOf(facility);
407
- return formattedFacilities[index];
408
- });
409
- request = {
410
- ...baseRequest,
411
- get: sinon.stub().resolves(rawFacilities)
412
- };
413
- toSnakeCase = sinon
414
- .stub(objectUtils, 'toSnakeCase')
415
- .returns(rawFacilityOptions);
416
-
417
- const facilities = new Facilities(baseSdk, request);
418
- facilities._baseUrl = expectedHost;
419
-
420
- promise = facilities.getAllByOrganizationId(
421
- expectedOrganizationId,
422
- initialOptions
423
- );
424
- });
425
-
426
- it('gets options that are in a format suitable for the API', function() {
427
- expect(toSnakeCase).to.be.calledWith(initialOptions);
428
- });
429
-
430
- it('gets a list of facilities for an organization from the server', function() {
431
- expect(request.get).to.be.calledWith(
432
- `${expectedHost}/organizations/${expectedOrganizationId}/facilities`,
433
- {
434
- params: rawFacilityOptions
435
- }
436
- );
437
- });
438
-
439
- it('formats the facility object', function() {
440
- return promise.then(() => {
441
- expect(formatFacilityWithInfoFromServer).to.have.callCount(
442
- rawFacilities.length
443
- );
444
-
445
- rawFacilities.forEach((facility) => {
446
- expect(formatFacilityWithInfoFromServer).to.be.calledWith(facility);
447
- });
448
- });
449
- });
450
-
451
- it('returns a list of facilities', function() {
452
- return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal(
453
- formattedFacilities
454
- );
455
- });
456
- });
457
-
458
- context('the organization id is not provided', function() {
459
- it('throws an error', function() {
460
- const facilities = new Facilities(baseSdk, baseRequest);
461
- const promise = facilities.getAllByOrganizationId();
462
-
463
- return expect(promise).to.be.rejectedWith(
464
- "An organization ID is required for getting a list of an organization's facilities"
465
- );
466
- });
467
- });
468
- });
469
-
470
- describe('update', function() {
471
- context('when all required information is available', function() {
472
- let facilityUpdate;
473
- let formattedFacility;
474
- let promise;
475
- let toSnakeCase;
476
-
477
- beforeEach(function() {
478
- facilityUpdate = fixture.build('facility');
479
- formattedFacility = fixture.build('facility', null, {
480
- fromServer: true
481
- });
482
-
483
- toSnakeCase = sinon
484
- .stub(objectUtils, 'toSnakeCase')
485
- .returns(formattedFacility);
486
-
487
- const facilities = new Facilities(baseSdk, baseRequest);
488
- facilities._baseUrl = expectedHost;
489
-
490
- promise = facilities.update(facilityUpdate.id, facilityUpdate);
491
- });
492
-
493
- it('formats the data into the right format', function() {
494
- expect(toSnakeCase).to.be.calledWith(facilityUpdate, {
495
- excludeKeys: ['id', 'organizationId']
496
- });
497
- });
498
-
499
- it('updates the facility', function() {
500
- expect(baseRequest.put).to.be.calledWith(
501
- `${expectedHost}/facilities/${facilityUpdate.id}`,
502
- formattedFacility
503
- );
504
- });
505
-
506
- it('returns a fulfilled promise', function() {
507
- return expect(promise).to.be.fulfilled;
508
- });
509
- });
510
-
511
- context(
512
- 'when there is missing or malformed required information',
513
- function() {
514
- let facilities;
515
-
516
- beforeEach(function() {
517
- facilities = new Facilities(baseSdk, baseRequest);
518
- });
519
-
520
- it('throws an error when there is no provided facility id', function() {
521
- const facilityUpdate = fixture.build('facility');
522
- const promise = facilities.update(null, facilityUpdate);
523
-
524
- return expect(promise).to.be.rejectedWith(
525
- 'A facility ID is required to update a facility.'
526
- );
527
- });
528
-
529
- it('throws an error when there is no update provided', function() {
530
- const facilityUpdate = fixture.build('facility');
531
- const promise = facilities.update(facilityUpdate.id);
532
-
533
- return expect(promise).to.be.rejectedWith(
534
- 'An update is required to update a facility.'
535
- );
536
- });
537
-
538
- it('throws an error when the update is not an object', function() {
539
- const facilityUpdate = fixture.build('facility');
540
- const promise = facilities.update(facilityUpdate.id, [
541
- facilityUpdate
542
- ]);
543
-
544
- return expect(promise).to.be.rejectedWith(
545
- 'The facility update must be a well-formed object with the data you wish to update.'
546
- );
547
- });
548
- }
549
- );
550
- });
551
- });