@webex/plugin-people 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.
@@ -1,170 +1,170 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import '@webex/internal-plugin-mercury';
6
- import '@webex/plugin-people';
7
-
8
- import {assert} from '@webex/test-helper-chai';
9
- import WebexCore from '@webex/webex-core';
10
- import testUsers from '@webex/test-helper-test-users';
11
- import sinon from 'sinon';
12
-
13
- describe('plugin-people', function () {
14
- this.timeout(60000);
15
- describe('People', () => {
16
- let bones, mccoy, spock;
17
-
18
- beforeEach('create users', () =>
19
- testUsers.create({count: 3}).then((users) => {
20
- [spock, mccoy, bones] = users;
21
- spock.webex = new WebexCore({
22
- credentials: {
23
- authorization: users[0].token,
24
- },
25
- });
26
- mccoy.webex = new WebexCore({
27
- credentials: {
28
- authorization: users[1].token,
29
- },
30
- });
31
- })
32
- );
33
-
34
- describe('#get()', () => {
35
- it('gets a person by id', () =>
36
- spock.webex.people.get(mccoy.id).then((peopleResponse) => {
37
- assert.isPerson(peopleResponse);
38
- assert.equal(peopleResponse.emails[0], mccoy.email);
39
- }));
40
-
41
- it('gets the current user with "get(\'me\')"', () =>
42
- spock.webex.people.get('me').then((peopleResponse) => {
43
- assert.isPerson(peopleResponse);
44
- assert.equal(peopleResponse.emails[0], spock.email);
45
- }));
46
-
47
- it('gets a user by hydra id', () =>
48
- spock.webex.people
49
- .get('me')
50
- .then((person) => spock.webex.people.get(person.id))
51
- .then((person) => {
52
- assert.isPerson(person);
53
- assert.equal(person.emails[0], spock.email);
54
- }));
55
-
56
- it('gets multiple users at a time', () =>
57
- Promise.all([spock.webex.people.get(mccoy.id), spock.webex.people.get('me')]).then(
58
- (peopleResponse) => {
59
- assert.isPerson(peopleResponse[0]);
60
- assert.isPerson(peopleResponse[1]);
61
- assert.equal(peopleResponse[0].emails[0], mccoy.email);
62
- assert.equal(peopleResponse[1].emails[0], spock.email);
63
- }
64
- ));
65
- });
66
-
67
- describe('#list()', () => {
68
- it('gets a group of people by ids', () =>
69
- spock.webex.people.list([mccoy.id, spock.id, bones.id]).then((peopleResponse) => {
70
- assert.equal(peopleResponse.length, 3);
71
- assert.isPerson(peopleResponse[0]);
72
- assert.isPerson(peopleResponse[1]);
73
- assert.isPerson(peopleResponse[2]);
74
- assert.equal(peopleResponse[0].emails[0], mccoy.email);
75
- assert.equal(peopleResponse[1].emails[0], spock.email);
76
- }));
77
-
78
- it('defaults to false showAllTypes', () =>
79
- spock.webex.people
80
- .list([mccoy.id, spock.id, bones.id])
81
- .then(assert.isFalse(spock.webex.people.batcher.config.showAllTypes)));
82
-
83
- it('sets showAllTypes to true', () => {
84
- spock.webex.people.batcher.config.showAllTypes = true;
85
-
86
- return spock.webex.people
87
- .list([mccoy.id, spock.id, bones.id])
88
- .then(assert.isTrue(spock.webex.people.batcher.config.showAllTypes));
89
- });
90
-
91
- it('returns a list of people matching email address', () =>
92
- spock.webex.people.list({email: mccoy.email}).then((peopleResponse) => {
93
- assert.isAbove(peopleResponse.items.length, 0);
94
- const person = peopleResponse.items[0];
95
-
96
- assert.isPerson(person);
97
- assert.equal(person.emails[0], mccoy.email);
98
- }));
99
-
100
- it('returns a list of people matching name', () =>
101
- spock.webex.people.list({displayName: mccoy.name}).then((peopleResponse) => {
102
- assert.isAbove(peopleResponse.items.length, 0);
103
- let isMccoyFound = false;
104
-
105
- peopleResponse.items.forEach((person) => {
106
- if (person.displayName === mccoy.name) {
107
- isMccoyFound = true;
108
- }
109
- assert.isPerson(person);
110
- });
111
- assert.isTrue(isMccoyFound);
112
- }));
113
-
114
- describe('batching of people requests', () => {
115
- let batchTestUsers;
116
-
117
- beforeEach('create more users', () =>
118
- testUsers.create({count: 6}).then((users) => {
119
- batchTestUsers = users;
120
- })
121
- );
122
-
123
- it('batches uuid get requests into one', () => {
124
- sinon.spy(spock.webex.people.batcher, 'submitHttpRequest');
125
-
126
- return Promise.all(batchTestUsers.map((user) => spock.webex.people.get(user.id))).then(
127
- (peopleResponse) => {
128
- assert.equal(peopleResponse.length, 6);
129
- assert.calledOnce(spock.webex.people.batcher.submitHttpRequest);
130
- spock.webex.people.batcher.submitHttpRequest.restore();
131
- }
132
- );
133
- });
134
-
135
- it('batches people get requests into one', () => {
136
- sinon.spy(spock.webex.people.batcher, 'submitHttpRequest');
137
-
138
- return Promise.all(batchTestUsers.map((user) => spock.webex.people.get(user))).then(
139
- (peopleResponse) => {
140
- assert.equal(peopleResponse.length, 6);
141
- peopleResponse.map((personResponse) => assert.isPerson(personResponse));
142
- assert.calledOnce(spock.webex.people.batcher.submitHttpRequest);
143
- spock.webex.people.batcher.submitHttpRequest.restore();
144
- }
145
- );
146
- });
147
-
148
- it('executes network requests for max limit', () => {
149
- spock.webex.people.config.batcherMaxCalls = 2;
150
- sinon.spy(spock.webex.people.batcher, 'submitHttpRequest');
151
-
152
- return spock.webex.people
153
- .list(batchTestUsers.map((user) => user.id))
154
- .then((peopleResponse) => {
155
- assert.equal(peopleResponse.length, 6);
156
- assert.calledThrice(spock.webex.people.batcher.submitHttpRequest);
157
- spock.webex.people.batcher.submitHttpRequest.restore();
158
- });
159
- });
160
- });
161
- });
162
-
163
- describe('#inferPersonId', () => {
164
- it('infers a person id without a network dip', () =>
165
- spock.webex.people
166
- .get(spock.id)
167
- .then((me) => assert.equal(spock.webex.people.inferPersonIdFromUuid(spock.id), me.id)));
168
- });
169
- });
170
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import '@webex/internal-plugin-mercury';
6
+ import '@webex/plugin-people';
7
+
8
+ import {assert} from '@webex/test-helper-chai';
9
+ import WebexCore from '@webex/webex-core';
10
+ import testUsers from '@webex/test-helper-test-users';
11
+ import sinon from 'sinon';
12
+
13
+ describe('plugin-people', function () {
14
+ this.timeout(60000);
15
+ describe('People', () => {
16
+ let bones, mccoy, spock;
17
+
18
+ beforeEach('create users', () =>
19
+ testUsers.create({count: 3}).then((users) => {
20
+ [spock, mccoy, bones] = users;
21
+ spock.webex = new WebexCore({
22
+ credentials: {
23
+ authorization: users[0].token,
24
+ },
25
+ });
26
+ mccoy.webex = new WebexCore({
27
+ credentials: {
28
+ authorization: users[1].token,
29
+ },
30
+ });
31
+ })
32
+ );
33
+
34
+ describe('#get()', () => {
35
+ it('gets a person by id', () =>
36
+ spock.webex.people.get(mccoy.id).then((peopleResponse) => {
37
+ assert.isPerson(peopleResponse);
38
+ assert.equal(peopleResponse.emails[0], mccoy.email);
39
+ }));
40
+
41
+ it('gets the current user with "get(\'me\')"', () =>
42
+ spock.webex.people.get('me').then((peopleResponse) => {
43
+ assert.isPerson(peopleResponse);
44
+ assert.equal(peopleResponse.emails[0], spock.email);
45
+ }));
46
+
47
+ it('gets a user by hydra id', () =>
48
+ spock.webex.people
49
+ .get('me')
50
+ .then((person) => spock.webex.people.get(person.id))
51
+ .then((person) => {
52
+ assert.isPerson(person);
53
+ assert.equal(person.emails[0], spock.email);
54
+ }));
55
+
56
+ it('gets multiple users at a time', () =>
57
+ Promise.all([spock.webex.people.get(mccoy.id), spock.webex.people.get('me')]).then(
58
+ (peopleResponse) => {
59
+ assert.isPerson(peopleResponse[0]);
60
+ assert.isPerson(peopleResponse[1]);
61
+ assert.equal(peopleResponse[0].emails[0], mccoy.email);
62
+ assert.equal(peopleResponse[1].emails[0], spock.email);
63
+ }
64
+ ));
65
+ });
66
+
67
+ describe('#list()', () => {
68
+ it('gets a group of people by ids', () =>
69
+ spock.webex.people.list([mccoy.id, spock.id, bones.id]).then((peopleResponse) => {
70
+ assert.equal(peopleResponse.length, 3);
71
+ assert.isPerson(peopleResponse[0]);
72
+ assert.isPerson(peopleResponse[1]);
73
+ assert.isPerson(peopleResponse[2]);
74
+ assert.equal(peopleResponse[0].emails[0], mccoy.email);
75
+ assert.equal(peopleResponse[1].emails[0], spock.email);
76
+ }));
77
+
78
+ it('defaults to false showAllTypes', () =>
79
+ spock.webex.people
80
+ .list([mccoy.id, spock.id, bones.id])
81
+ .then(assert.isFalse(spock.webex.people.batcher.config.showAllTypes)));
82
+
83
+ it('sets showAllTypes to true', () => {
84
+ spock.webex.people.batcher.config.showAllTypes = true;
85
+
86
+ return spock.webex.people
87
+ .list([mccoy.id, spock.id, bones.id])
88
+ .then(assert.isTrue(spock.webex.people.batcher.config.showAllTypes));
89
+ });
90
+
91
+ it('returns a list of people matching email address', () =>
92
+ spock.webex.people.list({email: mccoy.email}).then((peopleResponse) => {
93
+ assert.isAbove(peopleResponse.items.length, 0);
94
+ const person = peopleResponse.items[0];
95
+
96
+ assert.isPerson(person);
97
+ assert.equal(person.emails[0], mccoy.email);
98
+ }));
99
+
100
+ it('returns a list of people matching name', () =>
101
+ spock.webex.people.list({displayName: mccoy.name}).then((peopleResponse) => {
102
+ assert.isAbove(peopleResponse.items.length, 0);
103
+ let isMccoyFound = false;
104
+
105
+ peopleResponse.items.forEach((person) => {
106
+ if (person.displayName === mccoy.name) {
107
+ isMccoyFound = true;
108
+ }
109
+ assert.isPerson(person);
110
+ });
111
+ assert.isTrue(isMccoyFound);
112
+ }));
113
+
114
+ describe('batching of people requests', () => {
115
+ let batchTestUsers;
116
+
117
+ beforeEach('create more users', () =>
118
+ testUsers.create({count: 6}).then((users) => {
119
+ batchTestUsers = users;
120
+ })
121
+ );
122
+
123
+ it('batches uuid get requests into one', () => {
124
+ sinon.spy(spock.webex.people.batcher, 'submitHttpRequest');
125
+
126
+ return Promise.all(batchTestUsers.map((user) => spock.webex.people.get(user.id))).then(
127
+ (peopleResponse) => {
128
+ assert.equal(peopleResponse.length, 6);
129
+ assert.calledOnce(spock.webex.people.batcher.submitHttpRequest);
130
+ spock.webex.people.batcher.submitHttpRequest.restore();
131
+ }
132
+ );
133
+ });
134
+
135
+ it('batches people get requests into one', () => {
136
+ sinon.spy(spock.webex.people.batcher, 'submitHttpRequest');
137
+
138
+ return Promise.all(batchTestUsers.map((user) => spock.webex.people.get(user))).then(
139
+ (peopleResponse) => {
140
+ assert.equal(peopleResponse.length, 6);
141
+ peopleResponse.map((personResponse) => assert.isPerson(personResponse));
142
+ assert.calledOnce(spock.webex.people.batcher.submitHttpRequest);
143
+ spock.webex.people.batcher.submitHttpRequest.restore();
144
+ }
145
+ );
146
+ });
147
+
148
+ it('executes network requests for max limit', () => {
149
+ spock.webex.people.config.batcherMaxCalls = 2;
150
+ sinon.spy(spock.webex.people.batcher, 'submitHttpRequest');
151
+
152
+ return spock.webex.people
153
+ .list(batchTestUsers.map((user) => user.id))
154
+ .then((peopleResponse) => {
155
+ assert.equal(peopleResponse.length, 6);
156
+ assert.calledThrice(spock.webex.people.batcher.submitHttpRequest);
157
+ spock.webex.people.batcher.submitHttpRequest.restore();
158
+ });
159
+ });
160
+ });
161
+ });
162
+
163
+ describe('#inferPersonId', () => {
164
+ it('infers a person id without a network dip', () =>
165
+ spock.webex.people
166
+ .get(spock.id)
167
+ .then((me) => assert.equal(spock.webex.people.inferPersonIdFromUuid(spock.id), me.id)));
168
+ });
169
+ });
170
+ });
@@ -1,106 +1,106 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {assert} from '@webex/test-helper-chai';
6
- import People from '@webex/plugin-people';
7
- import MockWebex from '@webex/test-helper-mock-webex';
8
- import sinon from 'sinon';
9
-
10
- describe('people-batcher', () => {
11
- describe('PersonUUIDRequestBatcher', () => {
12
- let batcher;
13
- let webex;
14
-
15
- beforeEach(() => {
16
- webex = new MockWebex({
17
- children: {
18
- people: People,
19
- },
20
- config: {
21
- people: {showAllTypes: false},
22
- },
23
- });
24
- batcher = webex.people.batcher;
25
- });
26
-
27
- describe('#fingerprints', () => {
28
- it("fingerprintRequest returns encrypted 'hydraId'", () =>
29
- batcher
30
- .fingerprintRequest('hydraId')
31
- .then((result) =>
32
- assert.deepEqual(result, webex.people.inferPersonIdFromUuid('hydraId'))
33
- ));
34
- });
35
-
36
- describe('#submitHttpRequest()', () => {
37
- const ids = ['id1'];
38
- const mockRequest = {
39
- service: 'hydra',
40
- resource: `people/?id=${ids}&showAllTypes=false`,
41
- };
42
-
43
- it('calls webex.request with expected params', () => {
44
- webex.request = function (options) {
45
- return Promise.resolve(options);
46
- };
47
-
48
- return batcher.submitHttpRequest(ids).then((req) => assert.deepEqual(req, mockRequest));
49
- });
50
- });
51
-
52
- describe('#handleHttpSuccess()', () => {
53
- let failureSpy, successSpy;
54
-
55
- beforeEach(() => {
56
- successSpy = sinon.stub(batcher, 'handleItemSuccess');
57
- failureSpy = sinon.stub(batcher, 'handleItemFailure');
58
- });
59
-
60
- it('handles item success', () => {
61
- const mockResponse = {
62
- items: [
63
- {
64
- id: 'hydra1',
65
- displayName: 'name1',
66
- },
67
- ],
68
- };
69
-
70
- return batcher
71
- .handleHttpSuccess({
72
- body: mockResponse,
73
- })
74
- .then(() => {
75
- assert.calledWith(successSpy, 'hydra1', mockResponse.items[0]);
76
- assert.notCalled(failureSpy);
77
- });
78
- });
79
-
80
- it('handles item failure', () => {
81
- const mockResponse = {
82
- items: [
83
- {
84
- id: 'hydra1',
85
- displayName: 'name1',
86
- },
87
- {
88
- id: 'hydra2',
89
- displayName: 'name2',
90
- },
91
- ],
92
- notFoundIds: ['hydra3'],
93
- };
94
-
95
- return batcher
96
- .handleHttpSuccess({
97
- body: mockResponse,
98
- })
99
- .then(() => {
100
- assert.calledTwice(successSpy);
101
- assert.calledWith(failureSpy, 'hydra3');
102
- });
103
- });
104
- });
105
- });
106
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import People from '@webex/plugin-people';
7
+ import MockWebex from '@webex/test-helper-mock-webex';
8
+ import sinon from 'sinon';
9
+
10
+ describe('people-batcher', () => {
11
+ describe('PersonUUIDRequestBatcher', () => {
12
+ let batcher;
13
+ let webex;
14
+
15
+ beforeEach(() => {
16
+ webex = new MockWebex({
17
+ children: {
18
+ people: People,
19
+ },
20
+ config: {
21
+ people: {showAllTypes: false},
22
+ },
23
+ });
24
+ batcher = webex.people.batcher;
25
+ });
26
+
27
+ describe('#fingerprints', () => {
28
+ it("fingerprintRequest returns encrypted 'hydraId'", () =>
29
+ batcher
30
+ .fingerprintRequest('hydraId')
31
+ .then((result) =>
32
+ assert.deepEqual(result, webex.people.inferPersonIdFromUuid('hydraId'))
33
+ ));
34
+ });
35
+
36
+ describe('#submitHttpRequest()', () => {
37
+ const ids = ['id1'];
38
+ const mockRequest = {
39
+ service: 'hydra',
40
+ resource: `people/?id=${ids}&showAllTypes=false`,
41
+ };
42
+
43
+ it('calls webex.request with expected params', () => {
44
+ webex.request = function (options) {
45
+ return Promise.resolve(options);
46
+ };
47
+
48
+ return batcher.submitHttpRequest(ids).then((req) => assert.deepEqual(req, mockRequest));
49
+ });
50
+ });
51
+
52
+ describe('#handleHttpSuccess()', () => {
53
+ let failureSpy, successSpy;
54
+
55
+ beforeEach(() => {
56
+ successSpy = sinon.stub(batcher, 'handleItemSuccess');
57
+ failureSpy = sinon.stub(batcher, 'handleItemFailure');
58
+ });
59
+
60
+ it('handles item success', () => {
61
+ const mockResponse = {
62
+ items: [
63
+ {
64
+ id: 'hydra1',
65
+ displayName: 'name1',
66
+ },
67
+ ],
68
+ };
69
+
70
+ return batcher
71
+ .handleHttpSuccess({
72
+ body: mockResponse,
73
+ })
74
+ .then(() => {
75
+ assert.calledWith(successSpy, 'hydra1', mockResponse.items[0]);
76
+ assert.notCalled(failureSpy);
77
+ });
78
+ });
79
+
80
+ it('handles item failure', () => {
81
+ const mockResponse = {
82
+ items: [
83
+ {
84
+ id: 'hydra1',
85
+ displayName: 'name1',
86
+ },
87
+ {
88
+ id: 'hydra2',
89
+ displayName: 'name2',
90
+ },
91
+ ],
92
+ notFoundIds: ['hydra3'],
93
+ };
94
+
95
+ return batcher
96
+ .handleHttpSuccess({
97
+ body: mockResponse,
98
+ })
99
+ .then(() => {
100
+ assert.calledTwice(successSpy);
101
+ assert.calledWith(failureSpy, 'hydra3');
102
+ });
103
+ });
104
+ });
105
+ });
106
+ });
@@ -1,26 +1,26 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {assert} from '@webex/test-helper-chai';
6
- import People from '@webex/plugin-people';
7
- import MockWebex from '@webex/test-helper-mock-webex';
8
-
9
- describe('plugin-people', () => {
10
- describe('People', () => {
11
- let webex;
12
-
13
- beforeEach(() => {
14
- webex = new MockWebex({
15
- children: {
16
- people: People,
17
- },
18
- });
19
- });
20
-
21
- describe('#get()', () => {
22
- it('requires a person parameter', () =>
23
- assert.isRejected(webex.people.get(), /A person with an id is required/));
24
- });
25
- });
26
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import People from '@webex/plugin-people';
7
+ import MockWebex from '@webex/test-helper-mock-webex';
8
+
9
+ describe('plugin-people', () => {
10
+ describe('People', () => {
11
+ let webex;
12
+
13
+ beforeEach(() => {
14
+ webex = new MockWebex({
15
+ children: {
16
+ people: People,
17
+ },
18
+ });
19
+ });
20
+
21
+ describe('#get()', () => {
22
+ it('requires a person parameter', () =>
23
+ assert.isRejected(webex.people.get(), /A person with an id is required/));
24
+ });
25
+ });
26
+ });