@ndustrial/contxt-sdk 4.3.4 → 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.
Files changed (169) 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 +3 -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 +19 -13
  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 +3 -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/.envrc +0 -0
  108. package/.huskyrc.js +0 -11
  109. package/.nycrc +0 -12
  110. package/esm/assets/assetAttributes.js +0 -574
  111. package/esm/assets/assetAttributes.js.map +0 -1
  112. package/esm/assets/assetMetrics.js +0 -690
  113. package/esm/assets/assetMetrics.js.map +0 -1
  114. package/esm/assets/assetTypes.js +0 -273
  115. package/esm/assets/assetTypes.js.map +0 -1
  116. package/esm/assets/index.js +0 -283
  117. package/esm/assets/index.js.map +0 -1
  118. package/esm/facilities/costCenters.js +0 -306
  119. package/esm/facilities/costCenters.js.map +0 -1
  120. package/esm/facilities/groupings.js +0 -323
  121. package/esm/facilities/groupings.js.map +0 -1
  122. package/esm/facilities/index.js +0 -343
  123. package/esm/facilities/index.js.map +0 -1
  124. package/esm/health/index.js +0 -229
  125. package/esm/health/index.js.map +0 -1
  126. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
  127. package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  128. package/esm/utils/facilities/index.js +0 -4
  129. package/esm/utils/facilities/index.js.map +0 -1
  130. package/lib/assets/assetAttributes.js +0 -588
  131. package/lib/assets/assetAttributes.js.map +0 -1
  132. package/lib/assets/assetMetrics.js +0 -705
  133. package/lib/assets/assetMetrics.js.map +0 -1
  134. package/lib/assets/assetTypes.js +0 -287
  135. package/lib/assets/assetTypes.js.map +0 -1
  136. package/lib/assets/index.js +0 -302
  137. package/lib/assets/index.js.map +0 -1
  138. package/lib/facilities/costCenters.js +0 -316
  139. package/lib/facilities/costCenters.js.map +0 -1
  140. package/lib/facilities/groupings.js +0 -333
  141. package/lib/facilities/groupings.js.map +0 -1
  142. package/lib/facilities/index.js +0 -360
  143. package/lib/facilities/index.js.map +0 -1
  144. package/lib/health/index.js +0 -232
  145. package/lib/health/index.js.map +0 -1
  146. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
  147. package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
  148. package/lib/utils/facilities/index.js +0 -15
  149. package/lib/utils/facilities/index.js.map +0 -1
  150. package/src/assets/assetAttributes.js +0 -619
  151. package/src/assets/assetAttributes.spec.js +0 -1143
  152. package/src/assets/assetMetrics.js +0 -736
  153. package/src/assets/assetMetrics.spec.js +0 -1180
  154. package/src/assets/assetTypes.js +0 -260
  155. package/src/assets/assetTypes.spec.js +0 -556
  156. package/src/assets/index.js +0 -271
  157. package/src/assets/index.spec.js +0 -515
  158. package/src/facilities/costCenters.js +0 -295
  159. package/src/facilities/costCenters.spec.js +0 -529
  160. package/src/facilities/groupings.js +0 -320
  161. package/src/facilities/groupings.spec.js +0 -567
  162. package/src/facilities/index.js +0 -343
  163. package/src/facilities/index.spec.js +0 -551
  164. package/src/health/index.js +0 -200
  165. package/src/health/index.spec.js +0 -501
  166. package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
  167. package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
  168. package/src/utils/facilities/index.js +0 -3
  169. package/tmp/package.json +0 -11
@@ -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;
@@ -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
- });