@webex/internal-plugin-user 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,98 +1,98 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {assert} from '@webex/test-helper-chai';
6
- import MockWebex from '@webex/test-helper-mock-webex';
7
- import sinon from 'sinon';
8
- import User from '@webex/internal-plugin-user';
9
-
10
- describe('plugin-user', () => {
11
- describe('UserUUIDBatcher', () => {
12
- let batcher;
13
- let webex;
14
-
15
- beforeEach(() => {
16
- webex = new MockWebex({
17
- children: {
18
- user: User,
19
- },
20
- });
21
- batcher = webex.internal.user.batcher.creator;
22
- });
23
-
24
- describe('#fingerprints', () => {
25
- const email = 'test@example.com';
26
-
27
- it("fingerprintRequest returns 'email'", () =>
28
- batcher.fingerprintRequest(email).then((res) => assert.deepEqual(res, email)));
29
- it("fingerprintResponse returns 'email'", () =>
30
- batcher.fingerprintRequest({email}).then((res) => assert.deepEqual(res, email)));
31
- });
32
-
33
- describe('#submitHttpRequest()', () => {
34
- const email = 'test@example.com';
35
- const mockRequest = {
36
- method: 'POST',
37
- service: 'conversation',
38
- resource: '/users',
39
- body: email,
40
- qs: {
41
- shouldCreateUsers: true,
42
- },
43
- };
44
-
45
- it('calls webex.request with expected params', () => {
46
- webex.request = function (options) {
47
- return Promise.resolve(options);
48
- };
49
-
50
- return batcher
51
- .submitHttpRequest(mockRequest.body)
52
- .then((req) => assert.deepEqual(req, mockRequest));
53
- });
54
- });
55
-
56
- describe('#handleHttpSuccess()', () => {
57
- const email = 'test@example.com';
58
- let failureSpy, successSpy;
59
-
60
- beforeEach(() => {
61
- successSpy = sinon.stub(batcher, 'handleItemSuccess');
62
- failureSpy = sinon.stub(batcher, 'handleItemFailure');
63
- });
64
-
65
- it('handles item success', () => {
66
- const mockResponse = {
67
- [email]: {
68
- id: '11111',
69
- },
70
- };
71
-
72
- return batcher
73
- .handleHttpSuccess({
74
- body: mockResponse,
75
- })
76
- .then(() => {
77
- assert.calledWith(successSpy, email, mockResponse[email]);
78
- });
79
- });
80
-
81
- it('handles item failure', () => {
82
- const mockResponse = {
83
- [email]: {
84
- errorCode: 11111,
85
- },
86
- };
87
-
88
- return batcher
89
- .handleHttpSuccess({
90
- body: mockResponse,
91
- })
92
- .then(() => {
93
- assert.calledWith(failureSpy, email, mockResponse[email]);
94
- });
95
- });
96
- });
97
- });
98
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import MockWebex from '@webex/test-helper-mock-webex';
7
+ import sinon from 'sinon';
8
+ import User from '@webex/internal-plugin-user';
9
+
10
+ describe('plugin-user', () => {
11
+ describe('UserUUIDBatcher', () => {
12
+ let batcher;
13
+ let webex;
14
+
15
+ beforeEach(() => {
16
+ webex = new MockWebex({
17
+ children: {
18
+ user: User,
19
+ },
20
+ });
21
+ batcher = webex.internal.user.batcher.creator;
22
+ });
23
+
24
+ describe('#fingerprints', () => {
25
+ const email = 'test@example.com';
26
+
27
+ it("fingerprintRequest returns 'email'", () =>
28
+ batcher.fingerprintRequest(email).then((res) => assert.deepEqual(res, email)));
29
+ it("fingerprintResponse returns 'email'", () =>
30
+ batcher.fingerprintRequest({email}).then((res) => assert.deepEqual(res, email)));
31
+ });
32
+
33
+ describe('#submitHttpRequest()', () => {
34
+ const email = 'test@example.com';
35
+ const mockRequest = {
36
+ method: 'POST',
37
+ service: 'conversation',
38
+ resource: '/users',
39
+ body: email,
40
+ qs: {
41
+ shouldCreateUsers: true,
42
+ },
43
+ };
44
+
45
+ it('calls webex.request with expected params', () => {
46
+ webex.request = function (options) {
47
+ return Promise.resolve(options);
48
+ };
49
+
50
+ return batcher
51
+ .submitHttpRequest(mockRequest.body)
52
+ .then((req) => assert.deepEqual(req, mockRequest));
53
+ });
54
+ });
55
+
56
+ describe('#handleHttpSuccess()', () => {
57
+ const email = 'test@example.com';
58
+ let failureSpy, successSpy;
59
+
60
+ beforeEach(() => {
61
+ successSpy = sinon.stub(batcher, 'handleItemSuccess');
62
+ failureSpy = sinon.stub(batcher, 'handleItemFailure');
63
+ });
64
+
65
+ it('handles item success', () => {
66
+ const mockResponse = {
67
+ [email]: {
68
+ id: '11111',
69
+ },
70
+ };
71
+
72
+ return batcher
73
+ .handleHttpSuccess({
74
+ body: mockResponse,
75
+ })
76
+ .then(() => {
77
+ assert.calledWith(successSpy, email, mockResponse[email]);
78
+ });
79
+ });
80
+
81
+ it('handles item failure', () => {
82
+ const mockResponse = {
83
+ [email]: {
84
+ errorCode: 11111,
85
+ },
86
+ };
87
+
88
+ return batcher
89
+ .handleHttpSuccess({
90
+ body: mockResponse,
91
+ })
92
+ .then(() => {
93
+ assert.calledWith(failureSpy, email, mockResponse[email]);
94
+ });
95
+ });
96
+ });
97
+ });
98
+ });
@@ -1,155 +1,155 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import UserService from '@webex/internal-plugin-user';
6
- import {assert} from '@webex/test-helper-chai';
7
- import MockWebex from '@webex/test-helper-mock-webex';
8
- import sinon from 'sinon';
9
- import uuid from 'uuid';
10
-
11
- describe('plugin-user', () => {
12
- describe('User', () => {
13
- let webex, userService;
14
-
15
- beforeEach(() => {
16
- webex = new MockWebex({
17
- children: {
18
- user: UserService,
19
- },
20
- });
21
-
22
- userService = webex.internal.user;
23
- });
24
-
25
- describe('#activate()', () => {
26
- it('requires a `verificationToken` or a confirmationCode + user id', () => {
27
- assert.isRejected(
28
- userService.activate(),
29
- /either options.verificationToken is required or both options.confirmationCode and options.id are required/
30
- );
31
- });
32
- });
33
-
34
- describe('#asUUID()', () => {
35
- it('requires a `user`', () => assert.isRejected(userService.asUUID(), /`user` is required/));
36
-
37
- it('requires a `user` in the array', () =>
38
- assert.isRejected(userService.asUUID(['']), /`user` is required/));
39
-
40
- it('requires a valid email', () =>
41
- assert.isRejected(
42
- userService.asUUID('not valid email'),
43
- /Provided user object does not appear to identify a user/
44
- ));
45
-
46
- it('resolves id if id is passed', () => {
47
- const id = uuid.v4();
48
-
49
- return userService.asUUID(id).then((res) => {
50
- assert.equal(res, id);
51
- });
52
- });
53
- });
54
-
55
- describe('#recordUUID()', () => {
56
- it('requires a `user`', () =>
57
- assert.isRejected(userService.recordUUID(), /`user` is required/));
58
-
59
- it('requires an `id`', () =>
60
- assert.isRejected(userService.recordUUID({}), /`user.id` is required/));
61
-
62
- it('requires the `id` to be a uuid', () =>
63
- assert.isRejected(
64
- userService.recordUUID({
65
- id: 'not a uuid',
66
- }),
67
- /`user.id` must be a uuid/
68
- ));
69
-
70
- it('requires an `emailAddress`', () =>
71
- assert.isRejected(
72
- userService.recordUUID({
73
- id: uuid.v4(),
74
- }),
75
- /`user.emailAddress` is required/
76
- ));
77
-
78
- it('requires the `emailAddress` to be a uuid', () =>
79
- assert.isRejected(
80
- userService.recordUUID({
81
- id: uuid.v4(),
82
- emailAddress: 'not an email address',
83
- }),
84
- /`user.emailAddress` must be an email address/
85
- ));
86
-
87
- it('places the user in the userstore', () => {
88
- const spy = sinon.stub(userService.store, 'add').returns(Promise.resolve());
89
-
90
- const user = {
91
- id: uuid.v4(),
92
- emailAddress: 'test@example.com',
93
- };
94
-
95
- userService.recordUUID(user);
96
-
97
- assert.calledWith(spy, user);
98
- });
99
- });
100
-
101
- describe('#generateOTP()', () => {
102
- it('requires one of `email` or `id`', () =>
103
- assert.isRejected(
104
- userService.generateOTP(),
105
- /One of `options.email` or `options.id` is required/
106
- ));
107
- });
108
-
109
- describe('#validateOTP()', () => {
110
- it('requires one of `email` or `id` and `oneTimePassword`', () =>
111
- assert.isRejected(
112
- userService.validateOTP(),
113
- /One of `options.email` or `options.id` and `options.oneTimePassword` are required/
114
- ));
115
- it('requires one of `email` or `id` even when otp is given', () =>
116
- assert.isRejected(
117
- userService.validateOTP({oneTimePassword: '123456'}),
118
- /One of `options.email` or `options.id` and `options.oneTimePassword` are required/
119
- ));
120
- it('requires oneTimePassword even when email is given', () =>
121
- assert.isRejected(
122
- userService.validateOTP({email: 'example@test.com'}),
123
- /One of `options.email` or `options.id` and `options.oneTimePassword` are required/
124
- ));
125
- it('requires oneTimePassword even when id is given', () =>
126
- assert.isRejected(
127
- userService.validateOTP({id: 'some-fake-id'}),
128
- /One of `options.email` or `options.id` and `options.oneTimePassword` are required/
129
- ));
130
- });
131
-
132
- describe('#setPassword()', () => {
133
- it('requires a `password`', () =>
134
- assert.isRejected(userService.setPassword(), /`options.password` is required/));
135
- });
136
-
137
- describe('#update()', () => {
138
- it('requires a `displayName`', () =>
139
- assert.isRejected(userService.update(), /`options.displayName` is required/));
140
- });
141
-
142
- describe('#updateName()', () => {
143
- it('requires one of `givenName` `familyName` or `displayName`', () =>
144
- assert.isRejected(
145
- userService.updateName(),
146
- /One of `givenName` and `familyName` or `displayName` is required/
147
- ));
148
- });
149
-
150
- describe('#verify()', () => {
151
- it('requires an `email` param', () =>
152
- assert.isRejected(userService.verify(), /`options.email` is required/));
153
- });
154
- });
155
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import UserService from '@webex/internal-plugin-user';
6
+ import {assert} from '@webex/test-helper-chai';
7
+ import MockWebex from '@webex/test-helper-mock-webex';
8
+ import sinon from 'sinon';
9
+ import uuid from 'uuid';
10
+
11
+ describe('plugin-user', () => {
12
+ describe('User', () => {
13
+ let webex, userService;
14
+
15
+ beforeEach(() => {
16
+ webex = new MockWebex({
17
+ children: {
18
+ user: UserService,
19
+ },
20
+ });
21
+
22
+ userService = webex.internal.user;
23
+ });
24
+
25
+ describe('#activate()', () => {
26
+ it('requires a `verificationToken` or a confirmationCode + user id', () => {
27
+ assert.isRejected(
28
+ userService.activate(),
29
+ /either options.verificationToken is required or both options.confirmationCode and options.id are required/
30
+ );
31
+ });
32
+ });
33
+
34
+ describe('#asUUID()', () => {
35
+ it('requires a `user`', () => assert.isRejected(userService.asUUID(), /`user` is required/));
36
+
37
+ it('requires a `user` in the array', () =>
38
+ assert.isRejected(userService.asUUID(['']), /`user` is required/));
39
+
40
+ it('requires a valid email', () =>
41
+ assert.isRejected(
42
+ userService.asUUID('not valid email'),
43
+ /Provided user object does not appear to identify a user/
44
+ ));
45
+
46
+ it('resolves id if id is passed', () => {
47
+ const id = uuid.v4();
48
+
49
+ return userService.asUUID(id).then((res) => {
50
+ assert.equal(res, id);
51
+ });
52
+ });
53
+ });
54
+
55
+ describe('#recordUUID()', () => {
56
+ it('requires a `user`', () =>
57
+ assert.isRejected(userService.recordUUID(), /`user` is required/));
58
+
59
+ it('requires an `id`', () =>
60
+ assert.isRejected(userService.recordUUID({}), /`user.id` is required/));
61
+
62
+ it('requires the `id` to be a uuid', () =>
63
+ assert.isRejected(
64
+ userService.recordUUID({
65
+ id: 'not a uuid',
66
+ }),
67
+ /`user.id` must be a uuid/
68
+ ));
69
+
70
+ it('requires an `emailAddress`', () =>
71
+ assert.isRejected(
72
+ userService.recordUUID({
73
+ id: uuid.v4(),
74
+ }),
75
+ /`user.emailAddress` is required/
76
+ ));
77
+
78
+ it('requires the `emailAddress` to be a uuid', () =>
79
+ assert.isRejected(
80
+ userService.recordUUID({
81
+ id: uuid.v4(),
82
+ emailAddress: 'not an email address',
83
+ }),
84
+ /`user.emailAddress` must be an email address/
85
+ ));
86
+
87
+ it('places the user in the userstore', () => {
88
+ const spy = sinon.stub(userService.store, 'add').returns(Promise.resolve());
89
+
90
+ const user = {
91
+ id: uuid.v4(),
92
+ emailAddress: 'test@example.com',
93
+ };
94
+
95
+ userService.recordUUID(user);
96
+
97
+ assert.calledWith(spy, user);
98
+ });
99
+ });
100
+
101
+ describe('#generateOTP()', () => {
102
+ it('requires one of `email` or `id`', () =>
103
+ assert.isRejected(
104
+ userService.generateOTP(),
105
+ /One of `options.email` or `options.id` is required/
106
+ ));
107
+ });
108
+
109
+ describe('#validateOTP()', () => {
110
+ it('requires one of `email` or `id` and `oneTimePassword`', () =>
111
+ assert.isRejected(
112
+ userService.validateOTP(),
113
+ /One of `options.email` or `options.id` and `options.oneTimePassword` are required/
114
+ ));
115
+ it('requires one of `email` or `id` even when otp is given', () =>
116
+ assert.isRejected(
117
+ userService.validateOTP({oneTimePassword: '123456'}),
118
+ /One of `options.email` or `options.id` and `options.oneTimePassword` are required/
119
+ ));
120
+ it('requires oneTimePassword even when email is given', () =>
121
+ assert.isRejected(
122
+ userService.validateOTP({email: 'example@test.com'}),
123
+ /One of `options.email` or `options.id` and `options.oneTimePassword` are required/
124
+ ));
125
+ it('requires oneTimePassword even when id is given', () =>
126
+ assert.isRejected(
127
+ userService.validateOTP({id: 'some-fake-id'}),
128
+ /One of `options.email` or `options.id` and `options.oneTimePassword` are required/
129
+ ));
130
+ });
131
+
132
+ describe('#setPassword()', () => {
133
+ it('requires a `password`', () =>
134
+ assert.isRejected(userService.setPassword(), /`options.password` is required/));
135
+ });
136
+
137
+ describe('#update()', () => {
138
+ it('requires a `displayName`', () =>
139
+ assert.isRejected(userService.update(), /`options.displayName` is required/));
140
+ });
141
+
142
+ describe('#updateName()', () => {
143
+ it('requires one of `givenName` `familyName` or `displayName`', () =>
144
+ assert.isRejected(
145
+ userService.updateName(),
146
+ /One of `givenName` and `familyName` or `displayName` is required/
147
+ ));
148
+ });
149
+
150
+ describe('#verify()', () => {
151
+ it('requires an `email` param', () =>
152
+ assert.isRejected(userService.verify(), /`options.email` is required/));
153
+ });
154
+ });
155
+ });