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