@webex/internal-plugin-device 2.59.2 → 2.59.3-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.eslintrc.js +6 -6
  2. package/README.md +80 -80
  3. package/babel.config.js +3 -3
  4. package/dist/config.js +27 -27
  5. package/dist/config.js.map +1 -1
  6. package/dist/constants.js.map +1 -1
  7. package/dist/device.js +226 -226
  8. package/dist/device.js.map +1 -1
  9. package/dist/features/feature-collection.js +14 -14
  10. package/dist/features/feature-collection.js.map +1 -1
  11. package/dist/features/feature-model.js +73 -73
  12. package/dist/features/feature-model.js.map +1 -1
  13. package/dist/features/features-model.js +28 -28
  14. package/dist/features/features-model.js.map +1 -1
  15. package/dist/features/index.js.map +1 -1
  16. package/dist/index.js +4 -4
  17. package/dist/index.js.map +1 -1
  18. package/dist/interceptors/device-url.js +8 -8
  19. package/dist/interceptors/device-url.js.map +1 -1
  20. package/dist/metrics.js.map +1 -1
  21. package/jest.config.js +3 -3
  22. package/package.json +17 -16
  23. package/process +1 -1
  24. package/src/config.js +60 -60
  25. package/src/constants.js +23 -23
  26. package/src/device.js +835 -835
  27. package/src/features/feature-collection.js +30 -30
  28. package/src/features/feature-model.js +189 -189
  29. package/src/features/features-model.js +96 -96
  30. package/src/features/index.js +5 -5
  31. package/src/index.js +29 -29
  32. package/src/interceptors/device-url.js +61 -61
  33. package/src/metrics.js +5 -5
  34. package/test/integration/spec/device.js +904 -904
  35. package/test/integration/spec/webex.js +42 -42
  36. package/test/unit/spec/device.js +409 -409
  37. package/test/unit/spec/features/feature-collection.js +24 -24
  38. package/test/unit/spec/features/feature-model.js +255 -255
  39. package/test/unit/spec/features/features-model.js +97 -97
  40. package/test/unit/spec/interceptors/device-url.js +215 -215
  41. package/test/unit/spec/wdm-dto.json +104 -104
@@ -1,97 +1,97 @@
1
- import {assert} from '@webex/test-helper-chai';
2
- import {constants, FeatureModel, FeaturesModel} from '@webex/internal-plugin-device';
3
- import sinon from 'sinon';
4
-
5
- import dto from '../wdm-dto';
6
-
7
- describe('plugin-device', () => {
8
- describe('features-model', () => {
9
- let featuresModel;
10
-
11
- beforeEach(() => {
12
- featuresModel = new FeaturesModel(dto.features);
13
- });
14
-
15
- describe('collections', () => {
16
- it("should have 'developer', 'entitlement' and 'user' keys", () => {
17
- assert.containsAllKeys(featuresModel, ['developer', 'entitlement', 'user']);
18
- });
19
- });
20
-
21
- describe('events', () => {
22
- constants.FEATURE_COLLECTION_NAMES.forEach((collectionName) => {
23
- describe(`when a feature is changed in '${collectionName}'`, () => {
24
- let feature;
25
- let spy;
26
- let value;
27
-
28
- beforeEach(() => {
29
- feature = featuresModel[collectionName].models[0];
30
- spy = sinon.spy();
31
- value = 'testValue';
32
-
33
- featuresModel.on(`change:${collectionName}`, spy);
34
- });
35
-
36
- it('should call the event-mapped function', () => {
37
- feature.value = value;
38
- assert.called(spy);
39
- });
40
- });
41
-
42
- describe(`when a feature is added to '${collectionName}'`, () => {
43
- let collection;
44
- let key;
45
- let model;
46
- let spy;
47
-
48
- beforeEach(() => {
49
- collection = featuresModel[collectionName];
50
- key = 'testKey';
51
- model = new FeatureModel({
52
- ...dto.features[collectionName][0],
53
- key,
54
- });
55
- spy = sinon.spy();
56
-
57
- featuresModel.on(`change:${collectionName}`, spy);
58
- });
59
-
60
- it('should call the event-mapped function', () => {
61
- collection.add(model);
62
- assert.called(spy);
63
- });
64
- });
65
-
66
- describe(`when a feature is removed from '${collectionName}'`, () => {
67
- let collection;
68
- let model;
69
- let spy;
70
-
71
- beforeEach(() => {
72
- collection = featuresModel[collectionName];
73
- model = new FeatureModel(dto.features[collectionName][0]);
74
- spy = sinon.spy();
75
-
76
- featuresModel.on(`change:${collectionName}`, spy);
77
- });
78
-
79
- it('should call the event-mapped function', () => {
80
- collection.remove(model);
81
- assert.called(spy);
82
- });
83
- });
84
- });
85
- });
86
-
87
- describe('#clear()', () => {
88
- it('should clear all of the features', () => {
89
- featuresModel.clear();
90
-
91
- assert.equal(featuresModel.developer.models.length, 0);
92
- assert.equal(featuresModel.entitlement.models.length, 0);
93
- assert.equal(featuresModel.user.models.length, 0);
94
- });
95
- });
96
- });
97
- });
1
+ import {assert} from '@webex/test-helper-chai';
2
+ import {constants, FeatureModel, FeaturesModel} from '@webex/internal-plugin-device';
3
+ import sinon from 'sinon';
4
+
5
+ import dto from '../wdm-dto';
6
+
7
+ describe('plugin-device', () => {
8
+ describe('features-model', () => {
9
+ let featuresModel;
10
+
11
+ beforeEach(() => {
12
+ featuresModel = new FeaturesModel(dto.features);
13
+ });
14
+
15
+ describe('collections', () => {
16
+ it("should have 'developer', 'entitlement' and 'user' keys", () => {
17
+ assert.containsAllKeys(featuresModel, ['developer', 'entitlement', 'user']);
18
+ });
19
+ });
20
+
21
+ describe('events', () => {
22
+ constants.FEATURE_COLLECTION_NAMES.forEach((collectionName) => {
23
+ describe(`when a feature is changed in '${collectionName}'`, () => {
24
+ let feature;
25
+ let spy;
26
+ let value;
27
+
28
+ beforeEach(() => {
29
+ feature = featuresModel[collectionName].models[0];
30
+ spy = sinon.spy();
31
+ value = 'testValue';
32
+
33
+ featuresModel.on(`change:${collectionName}`, spy);
34
+ });
35
+
36
+ it('should call the event-mapped function', () => {
37
+ feature.value = value;
38
+ assert.called(spy);
39
+ });
40
+ });
41
+
42
+ describe(`when a feature is added to '${collectionName}'`, () => {
43
+ let collection;
44
+ let key;
45
+ let model;
46
+ let spy;
47
+
48
+ beforeEach(() => {
49
+ collection = featuresModel[collectionName];
50
+ key = 'testKey';
51
+ model = new FeatureModel({
52
+ ...dto.features[collectionName][0],
53
+ key,
54
+ });
55
+ spy = sinon.spy();
56
+
57
+ featuresModel.on(`change:${collectionName}`, spy);
58
+ });
59
+
60
+ it('should call the event-mapped function', () => {
61
+ collection.add(model);
62
+ assert.called(spy);
63
+ });
64
+ });
65
+
66
+ describe(`when a feature is removed from '${collectionName}'`, () => {
67
+ let collection;
68
+ let model;
69
+ let spy;
70
+
71
+ beforeEach(() => {
72
+ collection = featuresModel[collectionName];
73
+ model = new FeatureModel(dto.features[collectionName][0]);
74
+ spy = sinon.spy();
75
+
76
+ featuresModel.on(`change:${collectionName}`, spy);
77
+ });
78
+
79
+ it('should call the event-mapped function', () => {
80
+ collection.remove(model);
81
+ assert.called(spy);
82
+ });
83
+ });
84
+ });
85
+ });
86
+
87
+ describe('#clear()', () => {
88
+ it('should clear all of the features', () => {
89
+ featuresModel.clear();
90
+
91
+ assert.equal(featuresModel.developer.models.length, 0);
92
+ assert.equal(featuresModel.entitlement.models.length, 0);
93
+ assert.equal(featuresModel.user.models.length, 0);
94
+ });
95
+ });
96
+ });
97
+ });
@@ -1,215 +1,215 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
- import sinon from 'sinon';
5
- import {assert} from '@webex/test-helper-chai';
6
- import {DeviceUrlInterceptor} from '@webex/internal-plugin-device';
7
-
8
- describe('plugin-device', () => {
9
- describe('DeviceUrlInterceptor', () => {
10
- let fixture;
11
- let interceptor;
12
- let waitForService;
13
- let getServiceFromUrl;
14
- let options;
15
-
16
- beforeEach(() => {
17
- interceptor = new DeviceUrlInterceptor();
18
-
19
- fixture = {
20
- api: 'example-api',
21
- resource: '/example/resource/',
22
- service: 'example',
23
- serviceUrl: 'https://www.example-service.com/',
24
- uri: 'https://www.example-uri.com/',
25
- };
26
-
27
- interceptor.webex = {
28
- internal: {
29
- device: {
30
- url: fixture.uri,
31
- },
32
- services: {
33
- waitForService: sinon.stub().resolves(fixture.serviceUrl),
34
- getServiceFromUrl: sinon.stub().returns({name: fixture.service}),
35
- },
36
- },
37
- };
38
-
39
- waitForService = interceptor.webex.internal.services.waitForService;
40
- getServiceFromUrl = interceptor.webex.internal.services.getServiceFromUrl;
41
-
42
- options = {};
43
- });
44
-
45
- describe('#onRequest()', () => {
46
- describe('when `cisco-device-url` header is are already set', () => {
47
- it('should return the options unchanged', () => {
48
- interceptor.webex.internal.device.url = undefined;
49
- options = {
50
- headers: {
51
- 'cisco-device-url': fixture.url,
52
- },
53
- ...options,
54
- };
55
-
56
- return interceptor
57
- .onRequest({...options})
58
- .then((results) => assert.deepEqual(results, options));
59
- });
60
-
61
- describe('when `cisco-device-url` header exists but is not set', () => {
62
- it('should return the options unchanged', () => {
63
- interceptor.webex.internal.device.url = undefined;
64
- options = {
65
- headers: {
66
- 'cisco-device-url': undefined,
67
- },
68
- ...options,
69
- };
70
-
71
- return interceptor
72
- .onRequest({...options})
73
- .then((results) => assert.deepEqual(results, options));
74
- });
75
- });
76
-
77
- describe('when service does not exist', () => {
78
- it('should return the options', () => {
79
- interceptor.webex.internal.device.url = 'http://device-url.com/';
80
- interceptor.webex.internal.services.waitForService = sinon
81
- .stub()
82
- .resolves('http://example-url.com/');
83
- interceptor.webex.internal.services.getServiceFromUrl = sinon.stub().returns();
84
-
85
- return interceptor
86
- .onRequest({...options})
87
- .then((results) => assert.deepEqual(results, options));
88
- });
89
- });
90
- });
91
-
92
- describe('adds cisco-device-url to the request header for service catalog services', () => {
93
- it('when only the service property is provided', () => {
94
- options.service = fixture.service;
95
-
96
- interceptor.onRequest(options).then((results) => {
97
- assert.calledWith(waitForService, {
98
- service: options.service,
99
- url: undefined,
100
- });
101
- assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
102
- assert.isDefined(options.headers['cisco-device-url']);
103
- assert.equal(results.headers['cisco-device-url'], fixture.uri);
104
- });
105
- });
106
-
107
- it('when only the uri property is provided', () => {
108
- options = {
109
- uri: fixture.uri,
110
- ...options,
111
- };
112
-
113
- interceptor.onRequest(options).then((results) => {
114
- assert.calledWith(waitForService, {
115
- service: undefined,
116
- url: options.uri,
117
- });
118
- assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
119
- assert.isDefined(results.headers['cisco-device-url']);
120
- assert.equal(results.headers['cisco-device-url'], fixture.uri);
121
- });
122
- });
123
-
124
- it('when both the service and uri properties are provided', () => {
125
- options = {
126
- services: fixture.service,
127
- uri: fixture.uri,
128
- ...options,
129
- };
130
-
131
- interceptor.onRequest(options).then((results) => {
132
- assert.calledWith(waitForService, {
133
- service: options.service,
134
- url: options.uri,
135
- });
136
- assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
137
- assert.isDefined(results.headers['cisco-device-url']);
138
- assert.equal(results.headers['cisco-device-url'], fixture.uri);
139
- });
140
- });
141
-
142
- describe('does not add cisco-device-url due to invalid service name', () => {
143
- it('service is `idbroker` and returns the original object', () => {
144
- getServiceFromUrl.returns({name: 'idbroker'});
145
-
146
- options = {
147
- services: fixture.service,
148
- uri: fixture.uri,
149
- ...options,
150
- };
151
-
152
- interceptor.onRequest(options).then((results) => {
153
- assert.calledWith(waitForService, {
154
- service: options.service,
155
- url: options.uri,
156
- });
157
- assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
158
- assert.isUndefined(results.headers);
159
- });
160
- });
161
-
162
- it('service is `oauth` returns the original object', () => {
163
- getServiceFromUrl.returns({name: 'saml'});
164
-
165
- options = {
166
- services: fixture.service,
167
- uri: fixture.uri,
168
- ...options,
169
- };
170
-
171
- interceptor.onRequest(options).then((results) => {
172
- assert.calledWith(waitForService, {
173
- service: options.service,
174
- url: options.uri,
175
- });
176
- assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
177
- assert.isUndefined(results.headers);
178
- });
179
- });
180
-
181
- it('service is `saml` returns the original object', () => {
182
- getServiceFromUrl.returns({name: 'saml'});
183
-
184
- options = {
185
- services: fixture.service,
186
- uri: fixture.uri,
187
- ...options,
188
- };
189
-
190
- interceptor.onRequest(options).then((results) => {
191
- assert.calledWith(waitForService, {
192
- service: options.service,
193
- url: options.uri,
194
- });
195
- assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
196
- assert.isUndefined(results.headers);
197
- });
198
- });
199
- });
200
-
201
- describe('waitForService returns a rejection', () => {
202
- beforeEach(() => {
203
- waitForService.rejects();
204
- });
205
-
206
- it('returns an error', () => {
207
- const promise = interceptor.onRequest(options);
208
-
209
- assert.isRejected(promise);
210
- });
211
- });
212
- });
213
- });
214
- });
215
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+ import sinon from 'sinon';
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import {DeviceUrlInterceptor} from '@webex/internal-plugin-device';
7
+
8
+ describe('plugin-device', () => {
9
+ describe('DeviceUrlInterceptor', () => {
10
+ let fixture;
11
+ let interceptor;
12
+ let waitForService;
13
+ let getServiceFromUrl;
14
+ let options;
15
+
16
+ beforeEach(() => {
17
+ interceptor = new DeviceUrlInterceptor();
18
+
19
+ fixture = {
20
+ api: 'example-api',
21
+ resource: '/example/resource/',
22
+ service: 'example',
23
+ serviceUrl: 'https://www.example-service.com/',
24
+ uri: 'https://www.example-uri.com/',
25
+ };
26
+
27
+ interceptor.webex = {
28
+ internal: {
29
+ device: {
30
+ url: fixture.uri,
31
+ },
32
+ services: {
33
+ waitForService: sinon.stub().resolves(fixture.serviceUrl),
34
+ getServiceFromUrl: sinon.stub().returns({name: fixture.service}),
35
+ },
36
+ },
37
+ };
38
+
39
+ waitForService = interceptor.webex.internal.services.waitForService;
40
+ getServiceFromUrl = interceptor.webex.internal.services.getServiceFromUrl;
41
+
42
+ options = {};
43
+ });
44
+
45
+ describe('#onRequest()', () => {
46
+ describe('when `cisco-device-url` header is are already set', () => {
47
+ it('should return the options unchanged', () => {
48
+ interceptor.webex.internal.device.url = undefined;
49
+ options = {
50
+ headers: {
51
+ 'cisco-device-url': fixture.url,
52
+ },
53
+ ...options,
54
+ };
55
+
56
+ return interceptor
57
+ .onRequest({...options})
58
+ .then((results) => assert.deepEqual(results, options));
59
+ });
60
+
61
+ describe('when `cisco-device-url` header exists but is not set', () => {
62
+ it('should return the options unchanged', () => {
63
+ interceptor.webex.internal.device.url = undefined;
64
+ options = {
65
+ headers: {
66
+ 'cisco-device-url': undefined,
67
+ },
68
+ ...options,
69
+ };
70
+
71
+ return interceptor
72
+ .onRequest({...options})
73
+ .then((results) => assert.deepEqual(results, options));
74
+ });
75
+ });
76
+
77
+ describe('when service does not exist', () => {
78
+ it('should return the options', () => {
79
+ interceptor.webex.internal.device.url = 'http://device-url.com/';
80
+ interceptor.webex.internal.services.waitForService = sinon
81
+ .stub()
82
+ .resolves('http://example-url.com/');
83
+ interceptor.webex.internal.services.getServiceFromUrl = sinon.stub().returns();
84
+
85
+ return interceptor
86
+ .onRequest({...options})
87
+ .then((results) => assert.deepEqual(results, options));
88
+ });
89
+ });
90
+ });
91
+
92
+ describe('adds cisco-device-url to the request header for service catalog services', () => {
93
+ it('when only the service property is provided', () => {
94
+ options.service = fixture.service;
95
+
96
+ interceptor.onRequest(options).then((results) => {
97
+ assert.calledWith(waitForService, {
98
+ service: options.service,
99
+ url: undefined,
100
+ });
101
+ assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
102
+ assert.isDefined(options.headers['cisco-device-url']);
103
+ assert.equal(results.headers['cisco-device-url'], fixture.uri);
104
+ });
105
+ });
106
+
107
+ it('when only the uri property is provided', () => {
108
+ options = {
109
+ uri: fixture.uri,
110
+ ...options,
111
+ };
112
+
113
+ interceptor.onRequest(options).then((results) => {
114
+ assert.calledWith(waitForService, {
115
+ service: undefined,
116
+ url: options.uri,
117
+ });
118
+ assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
119
+ assert.isDefined(results.headers['cisco-device-url']);
120
+ assert.equal(results.headers['cisco-device-url'], fixture.uri);
121
+ });
122
+ });
123
+
124
+ it('when both the service and uri properties are provided', () => {
125
+ options = {
126
+ services: fixture.service,
127
+ uri: fixture.uri,
128
+ ...options,
129
+ };
130
+
131
+ interceptor.onRequest(options).then((results) => {
132
+ assert.calledWith(waitForService, {
133
+ service: options.service,
134
+ url: options.uri,
135
+ });
136
+ assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
137
+ assert.isDefined(results.headers['cisco-device-url']);
138
+ assert.equal(results.headers['cisco-device-url'], fixture.uri);
139
+ });
140
+ });
141
+
142
+ describe('does not add cisco-device-url due to invalid service name', () => {
143
+ it('service is `idbroker` and returns the original object', () => {
144
+ getServiceFromUrl.returns({name: 'idbroker'});
145
+
146
+ options = {
147
+ services: fixture.service,
148
+ uri: fixture.uri,
149
+ ...options,
150
+ };
151
+
152
+ interceptor.onRequest(options).then((results) => {
153
+ assert.calledWith(waitForService, {
154
+ service: options.service,
155
+ url: options.uri,
156
+ });
157
+ assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
158
+ assert.isUndefined(results.headers);
159
+ });
160
+ });
161
+
162
+ it('service is `oauth` returns the original object', () => {
163
+ getServiceFromUrl.returns({name: 'saml'});
164
+
165
+ options = {
166
+ services: fixture.service,
167
+ uri: fixture.uri,
168
+ ...options,
169
+ };
170
+
171
+ interceptor.onRequest(options).then((results) => {
172
+ assert.calledWith(waitForService, {
173
+ service: options.service,
174
+ url: options.uri,
175
+ });
176
+ assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
177
+ assert.isUndefined(results.headers);
178
+ });
179
+ });
180
+
181
+ it('service is `saml` returns the original object', () => {
182
+ getServiceFromUrl.returns({name: 'saml'});
183
+
184
+ options = {
185
+ services: fixture.service,
186
+ uri: fixture.uri,
187
+ ...options,
188
+ };
189
+
190
+ interceptor.onRequest(options).then((results) => {
191
+ assert.calledWith(waitForService, {
192
+ service: options.service,
193
+ url: options.uri,
194
+ });
195
+ assert.calledWith(getServiceFromUrl, fixture.serviceUrl);
196
+ assert.isUndefined(results.headers);
197
+ });
198
+ });
199
+ });
200
+
201
+ describe('waitForService returns a rejection', () => {
202
+ beforeEach(() => {
203
+ waitForService.rejects();
204
+ });
205
+
206
+ it('returns an error', () => {
207
+ const promise = interceptor.onRequest(options);
208
+
209
+ assert.isRejected(promise);
210
+ });
211
+ });
212
+ });
213
+ });
214
+ });
215
+ });