@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,567 +0,0 @@
1
- import omit from 'lodash.omit';
2
- import FacilityGroupings from './groupings';
3
- import * as objectUtils from '../utils/objects';
4
-
5
- describe('Facilities/Groupings', function() {
6
- let baseRequest;
7
- let baseSdk;
8
- let expectedHost;
9
-
10
- beforeEach(function() {
11
- baseRequest = {
12
- delete: sinon.stub().resolves(),
13
- get: sinon.stub().resolves(),
14
- post: sinon.stub().resolves(),
15
- put: sinon.stub().resolves()
16
- };
17
- baseSdk = {
18
- config: {
19
- audiences: {
20
- facilities: fixture.build('audience')
21
- }
22
- }
23
- };
24
- expectedHost = faker.internet.url();
25
- });
26
-
27
- afterEach(function() {
28
- sinon.restore();
29
- });
30
-
31
- describe('constructor', function() {
32
- let facilityGroupings;
33
-
34
- beforeEach(function() {
35
- facilityGroupings = new FacilityGroupings(
36
- baseSdk,
37
- baseRequest,
38
- expectedHost
39
- );
40
- });
41
-
42
- it('sets a base url for the class instance', function() {
43
- expect(facilityGroupings._baseUrl).to.equal(expectedHost);
44
- });
45
-
46
- it('appends the supplied request module to the class instance', function() {
47
- expect(facilityGroupings._request).to.equal(baseRequest);
48
- });
49
-
50
- it('appends the supplied sdk to the class instance', function() {
51
- expect(facilityGroupings._sdk).to.equal(baseSdk);
52
- });
53
- });
54
-
55
- describe('addFacility', function() {
56
- context('when all required information is supplied', function() {
57
- let expectedFacilityId;
58
- let expectedGroupingFacility;
59
- let expectedGroupingId;
60
- let promise;
61
- let rawGroupingFacility;
62
- let request;
63
- let toCamelCase;
64
-
65
- beforeEach(function() {
66
- expectedGroupingFacility = fixture.build('facilityGroupingFacility');
67
- expectedFacilityId = expectedGroupingFacility.facilityId;
68
- expectedGroupingId = expectedGroupingFacility.facilityGroupingId;
69
- rawGroupingFacility = fixture.build('facilityGroupingFacility', {
70
- fromServer: true
71
- });
72
-
73
- request = {
74
- ...baseRequest,
75
- post: sinon.stub().resolves(rawGroupingFacility)
76
- };
77
- toCamelCase = sinon
78
- .stub(objectUtils, 'toCamelCase')
79
- .returns(expectedGroupingFacility);
80
-
81
- const facilityGroupings = new FacilityGroupings(
82
- baseSdk,
83
- request,
84
- expectedHost
85
- );
86
-
87
- promise = facilityGroupings.addFacility(
88
- expectedGroupingId,
89
- expectedFacilityId
90
- );
91
- });
92
-
93
- it('creates the new facility grouping <--> facility relationship', function() {
94
- expect(request.post).to.be.calledWith(
95
- `${expectedHost}/groupings/${expectedGroupingId}/facility/${expectedFacilityId}`
96
- );
97
- });
98
-
99
- it('formats the returning facility grouping facility object', function() {
100
- return promise.then(() => {
101
- expect(toCamelCase).to.be.calledWith(rawGroupingFacility);
102
- });
103
- });
104
-
105
- it('returns a fulfilled promise with the new facility information', function() {
106
- return expect(promise).to.be.fulfilled.and.to.eventually.equal(
107
- expectedGroupingFacility
108
- );
109
- });
110
- });
111
-
112
- context('when there is missing required information', function() {
113
- ['facilityGroupingId', 'facilityId'].forEach(function(field) {
114
- it(`it throws an error when ${field} is missing`, function() {
115
- const groupingFacility = fixture.build('facilityGroupingFacility');
116
- delete groupingFacility[field];
117
-
118
- const facilityGroupings = new FacilityGroupings(
119
- baseSdk,
120
- baseRequest,
121
- expectedHost
122
- );
123
- const promise = facilityGroupings.addFacility(
124
- groupingFacility.facilityGroupingId,
125
- groupingFacility.facilityId
126
- );
127
-
128
- return expect(promise).to.be.rejectedWith(
129
- `A ${field} is required to create a relationship between a facility grouping and a facility.`
130
- );
131
- });
132
- });
133
- });
134
- });
135
-
136
- describe('create', function() {
137
- context('when all required information is supplied', function() {
138
- let expectedGrouping;
139
- let formattedGroupingFromServer;
140
- let formattedGroupingToServer;
141
- let initialGrouping;
142
- let promise;
143
- let request;
144
- let toCamelCase;
145
- let toSnakeCase;
146
-
147
- beforeEach(function() {
148
- initialGrouping = fixture.build('facilityGrouping');
149
- formattedGroupingToServer = fixture.build('facilityGrouping', null, {
150
- fromServer: true
151
- });
152
- formattedGroupingFromServer = fixture.build('facilityGrouping', null, {
153
- fromServer: true
154
- });
155
- expectedGrouping = fixture.build('facilityGrouping', null, {
156
- fromServer: true
157
- });
158
-
159
- request = {
160
- ...baseRequest,
161
- post: sinon.stub().resolves(formattedGroupingFromServer)
162
- };
163
- toCamelCase = sinon
164
- .stub(objectUtils, 'toCamelCase')
165
- .returns(expectedGrouping);
166
- toSnakeCase = sinon
167
- .stub(objectUtils, 'toSnakeCase')
168
- .returns(formattedGroupingToServer);
169
-
170
- const facilityGroupings = new FacilityGroupings(
171
- baseSdk,
172
- request,
173
- expectedHost
174
- );
175
-
176
- promise = facilityGroupings.create(initialGrouping);
177
- });
178
-
179
- it('formats the submitted facility grouping object to send to the server', function() {
180
- expect(toSnakeCase).to.be.calledWith(initialGrouping);
181
- });
182
-
183
- it('creates a new facility grouping', function() {
184
- expect(request.post).to.be.deep.calledWith(
185
- `${expectedHost}/groupings`,
186
- formattedGroupingToServer
187
- );
188
- });
189
-
190
- it('formats the returned facility grouping object', function() {
191
- return promise.then(() => {
192
- expect(toCamelCase).to.be.calledWith(formattedGroupingFromServer);
193
- });
194
- });
195
-
196
- it('returns a fulfilled promise with the new facility grouping information', function() {
197
- return expect(promise).to.be.fulfilled.and.to.eventually.equal(
198
- expectedGrouping
199
- );
200
- });
201
- });
202
-
203
- context('when there is missing required information', function() {
204
- ['name', 'organizationId'].forEach(function(field) {
205
- it(`it throws an error when ${field} is missing`, function() {
206
- const facilityGrouping = fixture.build('facilityGrouping');
207
- const facilityGroupings = new FacilityGroupings(
208
- baseSdk,
209
- baseRequest,
210
- expectedHost
211
- );
212
- const promise = facilityGroupings.create(
213
- omit(facilityGrouping, [field])
214
- );
215
-
216
- return expect(promise).to.be.rejectedWith(
217
- `A ${field} is required to create a new facility grouping.`
218
- );
219
- });
220
- });
221
- });
222
- });
223
-
224
- describe('delete', function() {
225
- context('when all required information is supplied', function() {
226
- let expectedFacilityGroupingId;
227
- let promise;
228
-
229
- beforeEach(function() {
230
- expectedFacilityGroupingId = fixture.build('facilityGrouping').id;
231
-
232
- const facilityGroupings = new FacilityGroupings(
233
- baseSdk,
234
- baseRequest,
235
- expectedHost
236
- );
237
- promise = facilityGroupings.delete(expectedFacilityGroupingId);
238
- });
239
-
240
- it('requests to delete the facility grouping', function() {
241
- expect(baseRequest.delete).to.be.calledWith(
242
- `${expectedHost}/groupings/${expectedFacilityGroupingId}`
243
- );
244
- });
245
-
246
- it('returns a fulfilled promise', function() {
247
- return expect(promise).to.be.fulfilled;
248
- });
249
- });
250
-
251
- context('when there is missing required information', function() {
252
- it(`it throws an error when the facility grouping id is missing`, function() {
253
- const expectedErrorMessage = `A facility grouping id is required for deleting a facility grouping.`;
254
-
255
- const facilityGroupings = new FacilityGroupings(
256
- baseSdk,
257
- baseRequest,
258
- expectedHost
259
- );
260
- const promise = facilityGroupings.delete();
261
-
262
- return expect(promise).to.be.rejectedWith(expectedErrorMessage);
263
- });
264
- });
265
- });
266
-
267
- describe('getAll', function() {
268
- let expectedGrouping;
269
- let toCamelCase;
270
- let groupingsFromServer;
271
- let promise;
272
- let request;
273
-
274
- beforeEach(function() {
275
- const numberOfGroupings = faker.random.number({ min: 1, max: 10 });
276
- expectedGrouping = fixture.buildList(
277
- 'facilityGrouping',
278
- numberOfGroupings
279
- );
280
- groupingsFromServer = fixture.buildList(
281
- 'facilityGrouping',
282
- numberOfGroupings
283
- );
284
-
285
- request = {
286
- ...baseRequest,
287
- get: sinon.stub().resolves(groupingsFromServer)
288
- };
289
- toCamelCase = sinon
290
- .stub(objectUtils, 'toCamelCase')
291
- .returns(expectedGrouping);
292
-
293
- const facilityGroupings = new FacilityGroupings(
294
- baseSdk,
295
- request,
296
- expectedHost
297
- );
298
- promise = facilityGroupings.getAll();
299
- });
300
-
301
- it('gets a list of facility groupings', function() {
302
- expect(request.get).to.be.calledWith(`${expectedHost}/groupings`);
303
- });
304
-
305
- it('formats the list of facility groupings', function() {
306
- return promise.then(() => {
307
- expect(toCamelCase).to.be.calledWith(groupingsFromServer);
308
- });
309
- });
310
-
311
- it('returns a fulfilled promise with the facility groupings', function() {
312
- return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal(
313
- expectedGrouping
314
- );
315
- });
316
- });
317
-
318
- describe('getAllByOrganizationId', function() {
319
- context('when all required information is provided', function() {
320
- let expectedGrouping;
321
- let expectedOrganizationId;
322
- let toCamelCase;
323
- let groupingsFromServer;
324
- let promise;
325
- let request;
326
-
327
- beforeEach(function() {
328
- const numberOfGroupings = faker.random.number({ min: 1, max: 10 });
329
- expectedGrouping = fixture.buildList(
330
- 'facilityGrouping',
331
- numberOfGroupings
332
- );
333
- groupingsFromServer = fixture.buildList(
334
- 'facilityGrouping',
335
- numberOfGroupings
336
- );
337
- expectedOrganizationId = fixture.build('organization').id;
338
-
339
- request = {
340
- ...baseRequest,
341
- get: sinon.stub().resolves(groupingsFromServer)
342
- };
343
- toCamelCase = sinon
344
- .stub(objectUtils, 'toCamelCase')
345
- .returns(expectedGrouping);
346
-
347
- const facilityGroupings = new FacilityGroupings(
348
- baseSdk,
349
- request,
350
- expectedHost
351
- );
352
- promise = facilityGroupings.getAllByOrganizationId(
353
- expectedOrganizationId
354
- );
355
- });
356
-
357
- it('gets a list of facility groupings', function() {
358
- expect(request.get).to.be.calledWith(
359
- `${expectedHost}/organizations/${expectedOrganizationId}/groupings`
360
- );
361
- });
362
-
363
- it('formats the list of facility groupings', function() {
364
- return promise.then(() => {
365
- expect(toCamelCase).to.be.calledWith(groupingsFromServer);
366
- });
367
- });
368
-
369
- it('returns a fulfilled promise with the facility groupings', function() {
370
- return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal(
371
- expectedGrouping
372
- );
373
- });
374
- });
375
-
376
- context('when there is missing required information', function() {
377
- it('returns a rejected promise with an error when no organizationId is provided', function() {
378
- const facilityGroupings = new FacilityGroupings(
379
- baseSdk,
380
- baseRequest,
381
- expectedHost
382
- );
383
- const promise = facilityGroupings.getAllByOrganizationId();
384
-
385
- return expect(promise).to.be.rejectedWith(
386
- `An organization id is required for getting a list of an organization's facility groupings`
387
- );
388
- });
389
- });
390
- });
391
-
392
- describe('removeFacility', function() {
393
- context('when all required information is supplied', function() {
394
- let facilityGroupingFacility;
395
- let promise;
396
-
397
- beforeEach(function() {
398
- facilityGroupingFacility = fixture.build('facilityGroupingFacility');
399
-
400
- const facilityGroupings = new FacilityGroupings(
401
- baseSdk,
402
- baseRequest,
403
- expectedHost
404
- );
405
- promise = facilityGroupings.removeFacility(
406
- facilityGroupingFacility.facilityGroupingId,
407
- facilityGroupingFacility.facilityId
408
- );
409
- });
410
-
411
- it('requests to remove the facility', function() {
412
- const facilityGroupingId = facilityGroupingFacility.facilityGroupingId;
413
- const facilityId = facilityGroupingFacility.facilityId;
414
-
415
- expect(baseRequest.delete).to.be.calledWith(
416
- `${expectedHost}/groupings/${facilityGroupingId}/facility/${facilityId}`
417
- );
418
- });
419
-
420
- it('returns a fulfilled promise', function() {
421
- return expect(promise).to.be.fulfilled;
422
- });
423
- });
424
-
425
- context('when there is missing required information', function() {
426
- ['facilityGroupingId', 'facilityId'].forEach(function(field) {
427
- it(`it throws an error when ${field} is missing`, function() {
428
- const expectedErrorMessage = `A ${field} is required to remove a relationship between a facility grouping and a facility.`;
429
- const groupingFacility = fixture.build('facilityGroupingFacility');
430
- delete groupingFacility[field];
431
-
432
- const facilityGroupings = new FacilityGroupings(
433
- baseSdk,
434
- baseRequest,
435
- expectedHost
436
- );
437
- const promise = facilityGroupings.removeFacility(
438
- groupingFacility.facilityGroupingId,
439
- groupingFacility.facilityId
440
- );
441
-
442
- return expect(promise).to.be.rejectedWith(expectedErrorMessage);
443
- });
444
- });
445
- });
446
- });
447
-
448
- describe('update', function() {
449
- context('when all required information is available', function() {
450
- let toSnakeCase;
451
- let formattedGroupingFromServer;
452
- let formattedUpdateToServer;
453
- let groupingFromServer;
454
- let promise;
455
- let request;
456
- let toCamelCase;
457
- let update;
458
-
459
- beforeEach(function() {
460
- formattedGroupingFromServer = fixture.build('facilityGrouping');
461
- groupingFromServer = fixture.build(
462
- 'facilityGrouping',
463
- formattedGroupingFromServer,
464
- {
465
- fromServer: true
466
- }
467
- );
468
- update = omit(formattedGroupingFromServer, [
469
- 'createdAt',
470
- 'id',
471
- 'organizationId',
472
- 'ownerId',
473
- 'updatedAt'
474
- ]);
475
- formattedUpdateToServer = fixture.build('facilityGrouping', update, {
476
- fromServer: true
477
- });
478
-
479
- request = {
480
- ...baseRequest,
481
- put: sinon.stub().resolves(groupingFromServer)
482
- };
483
- toCamelCase = sinon
484
- .stub(objectUtils, 'toCamelCase')
485
- .returns(formattedGroupingFromServer);
486
- toSnakeCase = sinon
487
- .stub(objectUtils, 'toSnakeCase')
488
- .returns(formattedUpdateToServer);
489
-
490
- const facilityGroupings = new FacilityGroupings(
491
- baseSdk,
492
- request,
493
- expectedHost
494
- );
495
- promise = facilityGroupings.update(
496
- formattedGroupingFromServer.id,
497
- update
498
- );
499
- });
500
-
501
- it('formats the facility grouping update for the server', function() {
502
- expect(toSnakeCase).to.be.calledWith(update, {
503
- excludeKeys: ['id', 'organizationId', 'ownerId']
504
- });
505
- });
506
-
507
- it('updates the facility groupings', function() {
508
- expect(request.put).to.be.calledWith(
509
- `${expectedHost}/groupings/${formattedGroupingFromServer.id}`,
510
- formattedUpdateToServer
511
- );
512
- });
513
-
514
- it('formats the returned facility grouping', function() {
515
- return promise.then(() => {
516
- expect(toCamelCase).to.be.calledWith(groupingFromServer);
517
- });
518
- });
519
-
520
- it('returns a fulfilled promise with the updated facility grouping', function() {
521
- return expect(promise).to.be.fulfilled.and.to.eventually.equal(
522
- formattedGroupingFromServer
523
- );
524
- });
525
- });
526
-
527
- context(
528
- 'when there is missing or malformed required information',
529
- function() {
530
- let facilityGroupings;
531
-
532
- beforeEach(function() {
533
- facilityGroupings = new FacilityGroupings(baseSdk, baseRequest);
534
- });
535
-
536
- it('throws an error when there is no provided facility grouping id', function() {
537
- const groupingUpdate = fixture.build('facilityGrouping');
538
- const promise = facilityGroupings.update(null, groupingUpdate);
539
-
540
- return expect(promise).to.be.rejectedWith(
541
- 'A facility grouping id is required to update a facility grouping.'
542
- );
543
- });
544
-
545
- it('throws an error when there is no update provided', function() {
546
- const groupingUpdate = fixture.build('facilityGrouping');
547
- const promise = facilityGroupings.update(groupingUpdate.id);
548
-
549
- return expect(promise).to.be.rejectedWith(
550
- 'An update is required to update a facility grouping'
551
- );
552
- });
553
-
554
- it('throws an error when the update is not an object', function() {
555
- const groupingUpdate = fixture.build('facilityGrouping');
556
- const promise = facilityGroupings.update(groupingUpdate.id, [
557
- groupingUpdate
558
- ]);
559
-
560
- return expect(promise).to.be.rejectedWith(
561
- 'The facility grouping update must be a well-formed object with the data you wish to update.'
562
- );
563
- });
564
- }
565
- );
566
- });
567
- });