@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
package/src/health/index.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { formatPaginatedDataFromServer } from '../utils/pagination';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {Object} HealthStatus
|
|
5
|
-
* @property {string} status A health status of value 'healthy' or 'unhealthy'
|
|
6
|
-
* @property {string} timestamp ISO 8601 Extended Format date/time string
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {Object} HealthAsset
|
|
11
|
-
* @augments Asset
|
|
12
|
-
* @property {HealthStatus} health
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @interface PaginatedResponse
|
|
17
|
-
* @template RecordType
|
|
18
|
-
* @typedef {Object} PaginatedResponse
|
|
19
|
-
* @property {Object} _metadata Metadata about the pagination settings
|
|
20
|
-
* @property {number} _metadata.offset Offset of records in subsequent queries
|
|
21
|
-
* @property {number} _metadata.totalRecords Total number of asset types found
|
|
22
|
-
* @property {Array.<RecordType>} records
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {PaginatedResponse.<HealthAsset>} HealthAssetPaginatedResponse
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @typedef {PaginatedResponse.<HealthStatus>} HealthStatusPaginatedResponse
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Module that provides access to the Contxt Health Service
|
|
35
|
-
*
|
|
36
|
-
* @typicalname contxtSdk.health
|
|
37
|
-
*/
|
|
38
|
-
class Health {
|
|
39
|
-
/**
|
|
40
|
-
* @param {Object} sdk An instance of the SDK so the module can communicate with other modules
|
|
41
|
-
* @param {Object} request An instance of the request module tied to this module's audience.
|
|
42
|
-
* @param {string} [organizationId] The organization ID to be used in tenant url requests
|
|
43
|
-
*/
|
|
44
|
-
constructor(sdk, request, organizationId = null) {
|
|
45
|
-
const baseUrl = `${sdk.config.audiences.health.host}/v1`;
|
|
46
|
-
|
|
47
|
-
this._baseUrl = baseUrl;
|
|
48
|
-
this._request = request;
|
|
49
|
-
this._sdk = sdk;
|
|
50
|
-
|
|
51
|
-
this._organizationId = organizationId;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The health status option constants
|
|
56
|
-
* @enum {string}
|
|
57
|
-
* @static
|
|
58
|
-
* @example
|
|
59
|
-
* console.log(Health.GOOD) //healthy
|
|
60
|
-
* console.log(Health.BAD) //unhealthy
|
|
61
|
-
*/
|
|
62
|
-
static status = {
|
|
63
|
-
GOOD: 'healthy',
|
|
64
|
-
BAD: 'unhealthy'
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Gets all of an organization's assets and their most recent health status
|
|
69
|
-
*
|
|
70
|
-
* API Endpoint: '/:organizationId/assets'
|
|
71
|
-
* Method: GET
|
|
72
|
-
*
|
|
73
|
-
* @param {Object} options
|
|
74
|
-
* @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
|
|
75
|
-
* @param {PaginationOptions} [paginationOptions]
|
|
76
|
-
* @returns {Promise}
|
|
77
|
-
* @fulfill {HealthAssetPaginatedResponse} Information about all contxt applications
|
|
78
|
-
* @reject {Error}
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* contxtSdk.health
|
|
82
|
-
* .getAll({
|
|
83
|
-
* organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'
|
|
84
|
-
* }, {
|
|
85
|
-
* limit: 50,
|
|
86
|
-
* offset: 100
|
|
87
|
-
* })
|
|
88
|
-
* .then((healthAssetRecords) => console.log(healthAssetRecords))
|
|
89
|
-
* .catch((err) => console.log(err));
|
|
90
|
-
*/
|
|
91
|
-
getAll({ organizationId = this._organizationId }, paginationOptions) {
|
|
92
|
-
if (!organizationId) {
|
|
93
|
-
return Promise.reject(new Error('An organization ID is required'));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return this._request
|
|
97
|
-
.get(`${this._baseUrl}/${organizationId}/assets`, {
|
|
98
|
-
params: paginationOptions
|
|
99
|
-
})
|
|
100
|
-
.then((response) => formatPaginatedDataFromServer(response));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Gets a list of health statuses for a single asset
|
|
105
|
-
*
|
|
106
|
-
* API Endpoint: '/:organizationId/assets/:assetId'
|
|
107
|
-
* Method: GET
|
|
108
|
-
*
|
|
109
|
-
* @param {Object} options
|
|
110
|
-
* @param {string} options.assetId The asset id to get the health for
|
|
111
|
-
* @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
|
|
112
|
-
* @param {PaginationOptions} [paginationOptions]
|
|
113
|
-
* @returns {Promise}
|
|
114
|
-
* @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications
|
|
115
|
-
* @reject {Error}
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* contxtSdk.health
|
|
119
|
-
* .getByAssetId({
|
|
120
|
-
* assetId: '9859f22d-cc45-4015-8674-1671f54d1888',
|
|
121
|
-
* organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83'
|
|
122
|
-
* }, {
|
|
123
|
-
* limit: 50,
|
|
124
|
-
* offset: 100
|
|
125
|
-
* })
|
|
126
|
-
* .then((healthStatusRecords) => console.log(healthStatusRecords))
|
|
127
|
-
* .catch((err) => console.log(err));
|
|
128
|
-
*/
|
|
129
|
-
getByAssetId(
|
|
130
|
-
{ assetId, organizationId = this._organizationId },
|
|
131
|
-
paginationOptions
|
|
132
|
-
) {
|
|
133
|
-
if (!assetId) {
|
|
134
|
-
return Promise.reject(new Error('An asset ID is required'));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (!organizationId) {
|
|
138
|
-
return Promise.reject(new Error('An organization ID is required'));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return this._request
|
|
142
|
-
.get(`${this._baseUrl}/${organizationId}/assets/${assetId}`, {
|
|
143
|
-
params: paginationOptions
|
|
144
|
-
})
|
|
145
|
-
.then((response) => formatPaginatedDataFromServer(response));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Creates a new health status entry for an asset
|
|
150
|
-
*
|
|
151
|
-
* API Endpoint: '/:organizationId/assets/:assetId'
|
|
152
|
-
* Method: POST
|
|
153
|
-
*
|
|
154
|
-
* @param {Object} options
|
|
155
|
-
* @param {string} options.assetId The asset id to get the health for
|
|
156
|
-
* @param {string} [options.organizationId] The organization id that owns the assets. Required if an organization id isn't set on the module instance.
|
|
157
|
-
* @param {string} options.status The health of the asset. One of type Health.status.GOOD or Health.status.BAD
|
|
158
|
-
* @param {string} [options.timestamp] Defaults to now. ISO 8601 Extended Format date/time string
|
|
159
|
-
* @returns {Promise}
|
|
160
|
-
* @fulfill {HealthStatusPaginatedResponse} Information about all contxt applications
|
|
161
|
-
* @reject {Error}
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* contxtSdk.health
|
|
165
|
-
* .post({
|
|
166
|
-
* assetId: '9859f22d-cc45-4015-8674-1671f54d1888',
|
|
167
|
-
* organizationId: 'bd900b6e-a319-492f-aa95-9715891b9a83',
|
|
168
|
-
* status: contxtSdk.health.status.GOOD
|
|
169
|
-
* })
|
|
170
|
-
* .then((healthStatus) => console.log(healthStatus))
|
|
171
|
-
* .catch((err) => console.log(err));
|
|
172
|
-
*/
|
|
173
|
-
post({ assetId, organizationId = this._organizationId, status, timestamp }) {
|
|
174
|
-
if (!assetId) {
|
|
175
|
-
return Promise.reject(new Error('An asset ID is required'));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (!organizationId) {
|
|
179
|
-
return Promise.reject(new Error('An organization ID is required'));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (!Object.values(Health.status).includes(status)) {
|
|
183
|
-
return Promise.reject(
|
|
184
|
-
new Error(
|
|
185
|
-
`Status must equal one of: ${Object.values(Health.status).join(', ')}`
|
|
186
|
-
)
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return this._request.post(
|
|
191
|
-
`${this._baseUrl}/${organizationId}/assets/${assetId}`,
|
|
192
|
-
{
|
|
193
|
-
status,
|
|
194
|
-
timestamp
|
|
195
|
-
}
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export default Health;
|
package/src/health/index.spec.js
DELETED
|
@@ -1,501 +0,0 @@
|
|
|
1
|
-
import Health from './index';
|
|
2
|
-
import * as paginationUtils from '../utils/pagination';
|
|
3
|
-
|
|
4
|
-
describe('Health', function() {
|
|
5
|
-
let baseRequest;
|
|
6
|
-
let baseSdk;
|
|
7
|
-
|
|
8
|
-
beforeEach(function() {
|
|
9
|
-
baseRequest = {
|
|
10
|
-
delete: sinon.stub().resolves(),
|
|
11
|
-
get: sinon.stub().resolves(),
|
|
12
|
-
post: sinon.stub().resolves(),
|
|
13
|
-
put: sinon.stub().resolves()
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
baseSdk = {
|
|
17
|
-
config: {
|
|
18
|
-
audiences: {
|
|
19
|
-
health: fixture.build('audience')
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(function() {
|
|
26
|
-
sinon.restore();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('constructor', function() {
|
|
30
|
-
let health;
|
|
31
|
-
let organizationId;
|
|
32
|
-
|
|
33
|
-
beforeEach(function() {
|
|
34
|
-
organizationId = fixture.build('organization').id;
|
|
35
|
-
|
|
36
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('sets a base url for the class instance', function() {
|
|
40
|
-
expect(health._baseUrl).to.equal(
|
|
41
|
-
`${baseSdk.config.audiences.health.host}/v1`
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('sets an organizationId for the class instance', function() {
|
|
46
|
-
expect(health._organizationId).to.equal(organizationId);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('appends the supplied request module to the class instance', function() {
|
|
50
|
-
expect(health._request).to.deep.equal(baseRequest);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('appends the supplied sdk to the class instance', function() {
|
|
54
|
-
expect(health._sdk).to.deep.equal(baseSdk);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('getAll', function() {
|
|
59
|
-
context(
|
|
60
|
-
'when the class instance does not have an organizationId',
|
|
61
|
-
function() {
|
|
62
|
-
let health;
|
|
63
|
-
|
|
64
|
-
beforeEach(function() {
|
|
65
|
-
health = new Health(baseSdk, baseRequest);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
context('when getAll is called without an organizationId', function() {
|
|
69
|
-
it('throws an error', function() {
|
|
70
|
-
let promise = health.getAll({
|
|
71
|
-
organizationId: null
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return expect(promise).to.be.rejectedWith(
|
|
75
|
-
'An organization ID is required'
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
context('when getAll is called with an organizationId', function() {
|
|
81
|
-
it('does not throw an error', function() {
|
|
82
|
-
let promise = health.getAll({
|
|
83
|
-
organizationId: fixture.build('organization').id
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return expect(promise).to.be.not.throw;
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
context('when the class instance does have an organizationId', function() {
|
|
93
|
-
let health;
|
|
94
|
-
let organizationId;
|
|
95
|
-
let paginationOptions;
|
|
96
|
-
|
|
97
|
-
beforeEach(function() {
|
|
98
|
-
organizationId = fixture.build('organization').id;
|
|
99
|
-
|
|
100
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
101
|
-
paginationOptions = {
|
|
102
|
-
limit: faker.random.number(),
|
|
103
|
-
offset: faker.random.number(),
|
|
104
|
-
orderBy: faker.random.arrayElement(['asc', 'desc']),
|
|
105
|
-
sortBy: null
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
context('when getAll is called without an organizationId', function() {
|
|
110
|
-
it('calls the api with the class instance organizationId', function() {
|
|
111
|
-
health.getAll({}, paginationOptions);
|
|
112
|
-
|
|
113
|
-
expect(baseRequest.get).to.be.calledWith(
|
|
114
|
-
`${baseSdk.config.audiences.health.host}/v1/${
|
|
115
|
-
health._organizationId
|
|
116
|
-
}/assets`
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
context('when getAll is called with an organizationId', function() {
|
|
122
|
-
it('calls the api with the provided organizationId', function() {
|
|
123
|
-
let organizationId = fixture.build('organization').id;
|
|
124
|
-
health.getAll({
|
|
125
|
-
organizationId
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
expect(baseRequest.get).to.be.calledWith(
|
|
129
|
-
`${
|
|
130
|
-
baseSdk.config.audiences.health.host
|
|
131
|
-
}/v1/${organizationId}/assets`
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
context('when all required parameters are supplied', function() {
|
|
138
|
-
let health;
|
|
139
|
-
let organizationId;
|
|
140
|
-
let paginationOptions;
|
|
141
|
-
let formatPaginatedDataFromServer;
|
|
142
|
-
|
|
143
|
-
beforeEach(function() {
|
|
144
|
-
organizationId = fixture.build('organization').id;
|
|
145
|
-
|
|
146
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
147
|
-
|
|
148
|
-
paginationOptions = {
|
|
149
|
-
limit: faker.random.number(),
|
|
150
|
-
offset: faker.random.number(),
|
|
151
|
-
orderBy: faker.random.arrayElement(['asc', 'desc']),
|
|
152
|
-
sortBy: null
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
formatPaginatedDataFromServer = sinon.stub(
|
|
156
|
-
paginationUtils,
|
|
157
|
-
'formatPaginatedDataFromServer'
|
|
158
|
-
);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('calls the api with the requested pagination options', function() {
|
|
162
|
-
health.getAll({}, paginationOptions);
|
|
163
|
-
|
|
164
|
-
expect(baseRequest.get).to.be.calledWith(
|
|
165
|
-
`${baseSdk.config.audiences.health.host}/v1/${
|
|
166
|
-
health._organizationId
|
|
167
|
-
}/assets`,
|
|
168
|
-
{ params: paginationOptions }
|
|
169
|
-
);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('formats the response with formatPaginatedDataFromServer()', function() {
|
|
173
|
-
let promise = health.getAll({}, paginationOptions);
|
|
174
|
-
|
|
175
|
-
return promise.then(() => {
|
|
176
|
-
expect(formatPaginatedDataFromServer).to.be.called;
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('getByAssetId', function() {
|
|
183
|
-
context(
|
|
184
|
-
'when the class instance does not have an organizationId',
|
|
185
|
-
function() {
|
|
186
|
-
let health;
|
|
187
|
-
let assetId;
|
|
188
|
-
|
|
189
|
-
beforeEach(function() {
|
|
190
|
-
assetId = fixture.build('asset').id;
|
|
191
|
-
health = new Health(baseSdk, baseRequest);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
context(
|
|
195
|
-
'when getByAssetId is called without an organizationId',
|
|
196
|
-
function() {
|
|
197
|
-
it('throws an error', function() {
|
|
198
|
-
let promise = health.getByAssetId({
|
|
199
|
-
assetId,
|
|
200
|
-
organizationId: null
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
return expect(promise).to.be.rejectedWith(
|
|
204
|
-
'An organization ID is required'
|
|
205
|
-
);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
context(
|
|
211
|
-
'when getByAssetId is called with an organizationId',
|
|
212
|
-
function() {
|
|
213
|
-
it('does not throw an error', function() {
|
|
214
|
-
let promise = health.getByAssetId({
|
|
215
|
-
assetId,
|
|
216
|
-
organizationId: fixture.build('organization').id
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
return expect(promise).to.be.not.throw;
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
context('when the class instance does have an organizationId', function() {
|
|
227
|
-
let health;
|
|
228
|
-
let organizationId;
|
|
229
|
-
let paginationOptions;
|
|
230
|
-
let assetId;
|
|
231
|
-
|
|
232
|
-
beforeEach(function() {
|
|
233
|
-
organizationId = fixture.build('organization').id;
|
|
234
|
-
assetId = fixture.build('asset').id;
|
|
235
|
-
|
|
236
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
237
|
-
paginationOptions = {
|
|
238
|
-
limit: faker.random.number(),
|
|
239
|
-
offset: faker.random.number(),
|
|
240
|
-
orderBy: faker.random.arrayElement(['asc', 'desc']),
|
|
241
|
-
sortBy: null
|
|
242
|
-
};
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
context(
|
|
246
|
-
'when getByAssetId is called without an organizationId',
|
|
247
|
-
function() {
|
|
248
|
-
it('calls the api with the class instance organizationId', function() {
|
|
249
|
-
health.getByAssetId({ assetId }, paginationOptions);
|
|
250
|
-
|
|
251
|
-
expect(baseRequest.get).to.be.calledWith(
|
|
252
|
-
`${baseSdk.config.audiences.health.host}/v1/${
|
|
253
|
-
health._organizationId
|
|
254
|
-
}/assets/${assetId}`
|
|
255
|
-
);
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
context('when getByAssetId is called with an organizationId', function() {
|
|
261
|
-
it('calls the api with the provided organizationId', function() {
|
|
262
|
-
health.getByAssetId({
|
|
263
|
-
assetId,
|
|
264
|
-
organizationId
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
expect(baseRequest.get).to.be.calledWith(
|
|
268
|
-
`${
|
|
269
|
-
baseSdk.config.audiences.health.host
|
|
270
|
-
}/v1/${organizationId}/assets/${assetId}`
|
|
271
|
-
);
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
context('when the assetId is not supplied', function() {
|
|
277
|
-
let health;
|
|
278
|
-
let organizationId;
|
|
279
|
-
|
|
280
|
-
beforeEach(function() {
|
|
281
|
-
organizationId = fixture.build('organization').id;
|
|
282
|
-
|
|
283
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it('throws an error', function() {
|
|
287
|
-
let promise = health.getByAssetId({
|
|
288
|
-
organizationId
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
return expect(promise).to.be.rejectedWith('An asset ID is required');
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
context('when all required parameters are supplied', function() {
|
|
296
|
-
let health;
|
|
297
|
-
let assetId;
|
|
298
|
-
let organizationId;
|
|
299
|
-
let paginationOptions;
|
|
300
|
-
let formatPaginatedDataFromServer;
|
|
301
|
-
|
|
302
|
-
beforeEach(function() {
|
|
303
|
-
assetId = fixture.build('asset').id;
|
|
304
|
-
organizationId = fixture.build('organization').id;
|
|
305
|
-
|
|
306
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
307
|
-
|
|
308
|
-
paginationOptions = {
|
|
309
|
-
limit: faker.random.number(),
|
|
310
|
-
offset: faker.random.number(),
|
|
311
|
-
orderBy: faker.random.arrayElement(['asc', 'desc']),
|
|
312
|
-
sortBy: null
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
formatPaginatedDataFromServer = sinon.stub(
|
|
316
|
-
paginationUtils,
|
|
317
|
-
'formatPaginatedDataFromServer'
|
|
318
|
-
);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('calls the api with the requested pagination options', function() {
|
|
322
|
-
health.getByAssetId({ assetId }, paginationOptions);
|
|
323
|
-
|
|
324
|
-
expect(baseRequest.get).to.be.calledWith(
|
|
325
|
-
`${baseSdk.config.audiences.health.host}/v1/${
|
|
326
|
-
health._organizationId
|
|
327
|
-
}/assets/${assetId}`,
|
|
328
|
-
{ params: paginationOptions }
|
|
329
|
-
);
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it('formats the response with formatPaginatedDataFromServer()', function() {
|
|
333
|
-
let promise = health.getByAssetId({ assetId }, paginationOptions);
|
|
334
|
-
|
|
335
|
-
return promise.then(() => {
|
|
336
|
-
expect(formatPaginatedDataFromServer).to.be.called;
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
describe('post', function() {
|
|
343
|
-
context(
|
|
344
|
-
'when the class instance does not have an organizationId',
|
|
345
|
-
function() {
|
|
346
|
-
let health;
|
|
347
|
-
let assetId;
|
|
348
|
-
let status;
|
|
349
|
-
|
|
350
|
-
beforeEach(function() {
|
|
351
|
-
assetId = fixture.build('asset').id;
|
|
352
|
-
status = faker.random.arrayElement(Object.values(Health.status));
|
|
353
|
-
health = new Health(baseSdk, baseRequest);
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
context('when post is called without an organizationId', function() {
|
|
357
|
-
it('throws an error', function() {
|
|
358
|
-
let promise = health.post({
|
|
359
|
-
assetId,
|
|
360
|
-
organizationId: null,
|
|
361
|
-
status
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
return expect(promise).to.be.rejectedWith(
|
|
365
|
-
'An organization ID is required'
|
|
366
|
-
);
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
context('when post is called with an organizationId', function() {
|
|
371
|
-
it('does not throw an error', function() {
|
|
372
|
-
let promise = health.post({
|
|
373
|
-
assetId,
|
|
374
|
-
organizationId: fixture.build('organization').id,
|
|
375
|
-
status
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
return expect(promise).to.be.not.throw;
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
context('when the class instance does have an organizationId', function() {
|
|
385
|
-
let health;
|
|
386
|
-
let organizationId;
|
|
387
|
-
let assetId;
|
|
388
|
-
let status;
|
|
389
|
-
|
|
390
|
-
beforeEach(function() {
|
|
391
|
-
organizationId = fixture.build('organization').id;
|
|
392
|
-
assetId = fixture.build('asset').id;
|
|
393
|
-
status = faker.random.arrayElement(Object.values(Health.status));
|
|
394
|
-
|
|
395
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
context('when post is called without an organizationId', function() {
|
|
399
|
-
it('calls the api with the class instance organizationId', function() {
|
|
400
|
-
health.post({ assetId, status });
|
|
401
|
-
|
|
402
|
-
expect(baseRequest.post).to.be.calledWith(
|
|
403
|
-
`${baseSdk.config.audiences.health.host}/v1/${
|
|
404
|
-
health._organizationId
|
|
405
|
-
}/assets/${assetId}`
|
|
406
|
-
);
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
context('when post is called with an organizationId', function() {
|
|
411
|
-
it('calls the api with the provided organizationId', function() {
|
|
412
|
-
health.post({
|
|
413
|
-
assetId,
|
|
414
|
-
organizationId,
|
|
415
|
-
status
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
expect(baseRequest.post).to.be.calledWith(
|
|
419
|
-
`${
|
|
420
|
-
baseSdk.config.audiences.health.host
|
|
421
|
-
}/v1/${organizationId}/assets/${assetId}`
|
|
422
|
-
);
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
context('when the assetId is not supplied', function() {
|
|
428
|
-
let health;
|
|
429
|
-
let organizationId;
|
|
430
|
-
let status;
|
|
431
|
-
|
|
432
|
-
beforeEach(function() {
|
|
433
|
-
organizationId = fixture.build('organization').id;
|
|
434
|
-
status = faker.random.arrayElement(Object.values(Health.status));
|
|
435
|
-
|
|
436
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
it('throws an error', function() {
|
|
440
|
-
let promise = health.post({
|
|
441
|
-
organizationId,
|
|
442
|
-
status
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
return expect(promise).to.be.rejectedWith('An asset ID is required');
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
context('when the status is not supplied', function() {
|
|
450
|
-
let health;
|
|
451
|
-
let assetId;
|
|
452
|
-
let organizationId;
|
|
453
|
-
|
|
454
|
-
beforeEach(function() {
|
|
455
|
-
organizationId = fixture.build('organization').id;
|
|
456
|
-
assetId = fixture.build('asset').id;
|
|
457
|
-
|
|
458
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
it('throws an error', function() {
|
|
462
|
-
let promise = health.post({
|
|
463
|
-
organizationId,
|
|
464
|
-
assetId
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
return expect(promise).to.be.rejectedWith(
|
|
468
|
-
'Status must equal one of: healthy, unhealthy'
|
|
469
|
-
);
|
|
470
|
-
});
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
context('when all required parameters are supplied', function() {
|
|
474
|
-
let health;
|
|
475
|
-
let assetId;
|
|
476
|
-
let organizationId;
|
|
477
|
-
let status;
|
|
478
|
-
let timestamp;
|
|
479
|
-
|
|
480
|
-
beforeEach(function() {
|
|
481
|
-
assetId = fixture.build('asset').id;
|
|
482
|
-
organizationId = fixture.build('organization').id;
|
|
483
|
-
status = faker.random.arrayElement(Object.values(Health.status));
|
|
484
|
-
timestamp = new Date();
|
|
485
|
-
|
|
486
|
-
health = new Health(baseSdk, baseRequest, organizationId);
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
it('calls the api with the requested pagination options', function() {
|
|
490
|
-
health.post({ assetId, organizationId, status, timestamp });
|
|
491
|
-
|
|
492
|
-
expect(baseRequest.post).to.be.calledWith(
|
|
493
|
-
`${baseSdk.config.audiences.health.host}/v1/${
|
|
494
|
-
health._organizationId
|
|
495
|
-
}/assets/${assetId}`,
|
|
496
|
-
{ status, timestamp }
|
|
497
|
-
);
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
});
|
|
501
|
-
});
|