@ndustrial/contxt-sdk 4.3.5 → 5.1.1

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