@ndustrial/contxt-sdk 4.3.6 → 5.1.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.
- package/.gitattributes +1 -0
- package/CHANGELOG.md +8 -0
- package/docs/Facilities.md +0 -144
- package/docs/FacilityGroupings.md +0 -160
- package/docs/Nionic.md +63 -0
- package/docs/README.md +3 -29
- package/docs/Typedefs.md +0 -101
- package/esm/config/audiences.js +13 -13
- package/esm/config/audiences.js.map +1 -1
- package/esm/index.js +3 -6
- package/esm/index.js.map +1 -1
- package/esm/nionic/index.js +126 -0
- package/esm/nionic/index.js.map +1 -0
- package/lib/config/audiences.js +13 -13
- package/lib/config/audiences.js.map +1 -1
- package/lib/index.js +19 -13
- package/lib/index.js.map +1 -1
- package/lib/nionic/index.js +130 -0
- package/lib/nionic/index.js.map +1 -0
- package/meta.yaml +11 -0
- package/package.json +9 -10
- package/src/bus/index.spec.js +3 -2
- package/src/bus/webSocketConnection.spec.js +31 -31
- package/src/config/audiences.js +13 -13
- package/src/config/index.spec.js +6 -6
- package/src/coordinator/applications.spec.js +8 -8
- package/src/coordinator/consent.spec.js +1 -1
- package/src/coordinator/edgeNodes.spec.js +3 -3
- package/src/coordinator/organizations.spec.js +4 -4
- package/src/coordinator/permissions.spec.js +4 -4
- package/src/coordinator/roles.spec.js +3 -3
- package/src/coordinator/users.spec.js +14 -15
- package/src/events/index.spec.js +16 -16
- package/src/files/index.spec.js +7 -7
- package/src/index.js +3 -6
- package/src/index.spec.js +8 -22
- package/src/iot/feeds.spec.js +4 -4
- package/src/iot/fieldCategories.spec.js +4 -4
- package/src/iot/fieldGroupings.spec.js +5 -5
- package/src/iot/outputs.spec.js +6 -6
- package/src/nionic/index.js +151 -0
- package/src/request.spec.js +3 -3
- package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
- package/src/sessionTypes/index.spec.js +3 -3
- package/src/sessionTypes/machineAuth.spec.js +3 -3
- package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
- package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
- package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
- package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
- package/src/utils/url/stringifyParams.spec.js +2 -3
- package/support/fixtures/factories/IOSDevice.js +3 -3
- package/support/fixtures/factories/applicationGrouping.js +4 -4
- package/support/fixtures/factories/applicationModule.js +2 -2
- package/support/fixtures/factories/asset.js +1 -1
- package/support/fixtures/factories/assetAttribute.js +2 -2
- package/support/fixtures/factories/assetAttributeValue.js +2 -2
- package/support/fixtures/factories/assetMetric.js +1 -1
- package/support/fixtures/factories/assetMetricValue.js +3 -3
- package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
- package/support/fixtures/factories/assetType.js +1 -1
- package/support/fixtures/factories/authResults.js +3 -3
- package/support/fixtures/factories/channel.js +1 -1
- package/support/fixtures/factories/contxtApplication.js +5 -5
- package/support/fixtures/factories/contxtOrganization.js +2 -2
- package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
- package/support/fixtures/factories/contxtProject.js +2 -2
- package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
- package/support/fixtures/factories/contxtRole.js +3 -3
- package/support/fixtures/factories/contxtRoleApplication.js +1 -1
- package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
- package/support/fixtures/factories/contxtUser.js +2 -2
- package/support/fixtures/factories/contxtUserApplication.js +1 -1
- package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
- package/support/fixtures/factories/contxtUserPermissions.js +5 -5
- package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
- package/support/fixtures/factories/contxtUserRole.js +2 -2
- package/support/fixtures/factories/costCenter.js +2 -2
- package/support/fixtures/factories/costCenterFacility.js +3 -3
- package/support/fixtures/factories/edgeNode.js +1 -1
- package/support/fixtures/factories/event.js +5 -5
- package/support/fixtures/factories/eventType.js +4 -4
- package/support/fixtures/factories/eventUser.js +5 -5
- package/support/fixtures/factories/facility.js +4 -4
- package/support/fixtures/factories/facilityGrouping.js +3 -3
- package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
- package/support/fixtures/factories/facilityInfo.js +2 -2
- package/support/fixtures/factories/facilityTag.js +1 -1
- package/support/fixtures/factories/feedStatus.js +1 -1
- package/support/fixtures/factories/feedType.js +1 -1
- package/support/fixtures/factories/feeds.js +5 -5
- package/support/fixtures/factories/fieldCategory.js +3 -3
- package/support/fixtures/factories/fieldGrouping.js +4 -4
- package/support/fixtures/factories/fieldGroupingField.js +3 -3
- package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
- package/support/fixtures/factories/file.js +1 -1
- package/support/fixtures/factories/fileUploadInfo.js +1 -1
- package/support/fixtures/factories/organization.js +1 -1
- package/support/fixtures/factories/outputField.js +10 -10
- package/support/fixtures/factories/outputFieldData.js +1 -1
- package/support/fixtures/factories/owner.js +2 -2
- package/support/fixtures/factories/paginationMetadata.js +2 -2
- package/support/fixtures/factories/triggeredEvent.js +4 -4
- package/support/fixtures/factories/userEventSubscription.js +1 -1
- package/support/fixtures/factories/userMobileNumber.js +1 -1
- package/support/fixtures/factories/userPermissionsMap.js +2 -2
- package/.huskyrc.js +0 -11
- package/.nycrc +0 -12
- package/esm/assets/assetAttributes.js +0 -574
- package/esm/assets/assetAttributes.js.map +0 -1
- package/esm/assets/assetMetrics.js +0 -690
- package/esm/assets/assetMetrics.js.map +0 -1
- package/esm/assets/assetTypes.js +0 -273
- package/esm/assets/assetTypes.js.map +0 -1
- package/esm/assets/index.js +0 -283
- package/esm/assets/index.js.map +0 -1
- package/esm/facilities/costCenters.js +0 -306
- package/esm/facilities/costCenters.js.map +0 -1
- package/esm/facilities/groupings.js +0 -323
- package/esm/facilities/groupings.js.map +0 -1
- package/esm/facilities/index.js +0 -343
- package/esm/facilities/index.js.map +0 -1
- package/esm/health/index.js +0 -229
- package/esm/health/index.js.map +0 -1
- package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
- package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
- package/esm/utils/facilities/index.js +0 -4
- package/esm/utils/facilities/index.js.map +0 -1
- package/lib/assets/assetAttributes.js +0 -588
- package/lib/assets/assetAttributes.js.map +0 -1
- package/lib/assets/assetMetrics.js +0 -705
- package/lib/assets/assetMetrics.js.map +0 -1
- package/lib/assets/assetTypes.js +0 -287
- package/lib/assets/assetTypes.js.map +0 -1
- package/lib/assets/index.js +0 -302
- package/lib/assets/index.js.map +0 -1
- package/lib/facilities/costCenters.js +0 -316
- package/lib/facilities/costCenters.js.map +0 -1
- package/lib/facilities/groupings.js +0 -333
- package/lib/facilities/groupings.js.map +0 -1
- package/lib/facilities/index.js +0 -360
- package/lib/facilities/index.js.map +0 -1
- package/lib/health/index.js +0 -232
- package/lib/health/index.js.map +0 -1
- package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
- package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
- package/lib/utils/facilities/index.js +0 -15
- package/lib/utils/facilities/index.js.map +0 -1
- package/src/assets/assetAttributes.js +0 -619
- package/src/assets/assetAttributes.spec.js +0 -1143
- package/src/assets/assetMetrics.js +0 -736
- package/src/assets/assetMetrics.spec.js +0 -1180
- package/src/assets/assetTypes.js +0 -260
- package/src/assets/assetTypes.spec.js +0 -556
- package/src/assets/index.js +0 -271
- package/src/assets/index.spec.js +0 -515
- package/src/facilities/costCenters.js +0 -295
- package/src/facilities/costCenters.spec.js +0 -529
- package/src/facilities/groupings.js +0 -320
- package/src/facilities/groupings.spec.js +0 -567
- package/src/facilities/index.js +0 -343
- package/src/facilities/index.spec.js +0 -551
- package/src/health/index.js +0 -200
- package/src/health/index.spec.js +0 -501
- package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
- package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
- 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
|
-
});
|