cozy-sharing 13.2.0 → 13.3.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,263 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { getSuccessMessage, countNewRecipients } from './successMessage';
3
- describe('getSuccessMessage method', function () {
4
- var props = {
5
- currentRecipients: [{
6
- email: 'sansa.stark@winterfell.westeros'
7
- }],
8
- documentType: 'Files',
9
- sharingDesc: 'fake-doc.odt',
10
- onShare: jest.fn(),
11
- createContact: jest.fn()
12
- };
13
- it('should return a success message and its params for multiple recipients', function () {
14
- var recipientsAfter = [{
15
- _type: 'io.cozy.contacts',
16
- email: 'jon.snow@thewall.westeros'
17
- }, {
18
- _type: 'io.cozy.contacts',
19
- email: 'arya.stark@winterfell.westeros'
20
- }, {
21
- _type: 'io.cozy.contacts',
22
- email: 'sansa.stark@winterfell.westeros'
23
- }];
24
-
25
- var _getSuccessMessage = getSuccessMessage(props.currentRecipients, recipientsAfter, props.documentType),
26
- _getSuccessMessage2 = _slicedToArray(_getSuccessMessage, 2),
27
- message = _getSuccessMessage2[0],
28
- params = _getSuccessMessage2[1];
29
-
30
- expect(message).toEqual('Files.share.shareByEmail.contactSuccess');
31
- expect(params).toEqual({
32
- smart_count: 2
33
- });
34
- });
35
- it('should return a success message and its params for one recipient with email', function () {
36
- var recipientsBefore = props.currentRecipients;
37
-
38
- var _getSuccessMessage3 = getSuccessMessage(recipientsBefore, [{
39
- email: 'jon.snow@thewall.westeros'
40
- }], props.documentType),
41
- _getSuccessMessage4 = _slicedToArray(_getSuccessMessage3, 2),
42
- message = _getSuccessMessage4[0],
43
- params = _getSuccessMessage4[1];
44
-
45
- expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess');
46
- expect(params).toEqual({
47
- email: 'jon.snow@thewall.westeros'
48
- });
49
- });
50
- it('should return a success message and its params for one recipient (contact) with email', function () {
51
- var recipientsBefore = props.currentRecipients;
52
-
53
- var _getSuccessMessage5 = getSuccessMessage(recipientsBefore, [{
54
- _id: 'e8c0e15f-da7d',
55
- _type: 'io.cozy.contacts',
56
- fullname: 'Jon Snow',
57
- email: [{
58
- address: 'jon.snow@thewall.westeros',
59
- primary: true
60
- }, {
61
- address: 'jon.snow@winterfell.westeros',
62
- primary: false
63
- }]
64
- }], props.documentType),
65
- _getSuccessMessage6 = _slicedToArray(_getSuccessMessage5, 2),
66
- message = _getSuccessMessage6[0],
67
- params = _getSuccessMessage6[1];
68
-
69
- expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess');
70
- expect(params).toEqual({
71
- email: 'jon.snow@thewall.westeros'
72
- });
73
- });
74
- it('should return a success message and its params for one recipient with cozy', function () {
75
- var recipientsBefore = props.currentRecipients;
76
-
77
- var _getSuccessMessage7 = getSuccessMessage(recipientsBefore, [{
78
- cozy: [{
79
- url: 'https://doranmartell.mycozy.cloud'
80
- }]
81
- }], props.documentType),
82
- _getSuccessMessage8 = _slicedToArray(_getSuccessMessage7, 2),
83
- message = _getSuccessMessage8[0],
84
- params = _getSuccessMessage8[1];
85
-
86
- expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess');
87
- expect(params).toEqual({
88
- email: 'https://doranmartell.mycozy.cloud'
89
- });
90
- });
91
- it('should use contact success message if recipient has no email and no cozy', function () {
92
- var recipientsBefore = props.currentRecipients;
93
-
94
- var _getSuccessMessage9 = getSuccessMessage(recipientsBefore, [{
95
- _id: 'fcb16b9e-7421'
96
- }], props.documentType),
97
- _getSuccessMessage10 = _slicedToArray(_getSuccessMessage9, 2),
98
- message = _getSuccessMessage10[0],
99
- params = _getSuccessMessage10[1];
100
-
101
- expect(message).toEqual('Files.share.shareByEmail.contactSuccess');
102
- expect(params).toEqual({
103
- smart_count: 1
104
- });
105
- });
106
- it('should use single group success message if recipient is a group', function () {
107
- var recipientsBefore = props.currentRecipients;
108
-
109
- var _getSuccessMessage11 = getSuccessMessage(recipientsBefore, [{
110
- _type: 'io.cozy.contacts.groups',
111
- name: 'Stark family'
112
- }], props.documentType),
113
- _getSuccessMessage12 = _slicedToArray(_getSuccessMessage11, 2),
114
- message = _getSuccessMessage12[0],
115
- params = _getSuccessMessage12[1];
116
-
117
- expect(message).toEqual('Files.share.shareByEmail.singleGroupSuccess');
118
- expect(params).toEqual({
119
- groupName: 'Stark family'
120
- });
121
- });
122
- it('should use contact success message if recipient has only multiple contacts', function () {
123
- var recipientsBefore = props.currentRecipients;
124
-
125
- var _getSuccessMessage13 = getSuccessMessage(recipientsBefore, [{
126
- _type: 'io.cozy.contacts'
127
- }, {
128
- _type: 'io.cozy.contacts'
129
- }, {
130
- _type: 'io.cozy.contacts'
131
- }], props.documentType),
132
- _getSuccessMessage14 = _slicedToArray(_getSuccessMessage13, 2),
133
- message = _getSuccessMessage14[0],
134
- params = _getSuccessMessage14[1];
135
-
136
- expect(message).toEqual('Files.share.shareByEmail.contactSuccess');
137
- expect(params).toEqual({
138
- smart_count: 3
139
- });
140
- });
141
- it('should use group success message if recipient has only multiple groups', function () {
142
- var recipientsBefore = props.currentRecipients;
143
-
144
- var _getSuccessMessage15 = getSuccessMessage(recipientsBefore, [{
145
- _type: 'io.cozy.contacts.groups'
146
- }, {
147
- _type: 'io.cozy.contacts.groups'
148
- }], props.documentType),
149
- _getSuccessMessage16 = _slicedToArray(_getSuccessMessage15, 2),
150
- message = _getSuccessMessage16[0],
151
- params = _getSuccessMessage16[1];
152
-
153
- expect(message).toEqual('Files.share.shareByEmail.groupSuccess');
154
- expect(params).toEqual({
155
- smart_count: 2
156
- });
157
- });
158
- it('should use contact and group success message if recipient has multiple contacts and groups', function () {
159
- var recipientsBefore = props.currentRecipients;
160
-
161
- var _getSuccessMessage17 = getSuccessMessage(recipientsBefore, [{
162
- _type: 'io.cozy.contacts'
163
- }, {
164
- _id: 'fcb16b9e-7421',
165
- _type: 'io.cozy.contacts.groups'
166
- }, {
167
- _id: 'f45b16be-7523',
168
- _type: 'io.cozy.contacts.groups'
169
- }], props.documentType),
170
- _getSuccessMessage18 = _slicedToArray(_getSuccessMessage17, 2),
171
- message = _getSuccessMessage18[0],
172
- params = _getSuccessMessage18[1];
173
-
174
- expect(message).toEqual('Files.share.shareByEmail.contactAndGroupSuccess');
175
- expect(params).toEqual({
176
- nbContact: 1,
177
- nbGroup: 2
178
- });
179
- });
180
- });
181
- describe('countNewRecipients', function () {
182
- var currentRecipients = [{
183
- email: 'arya.stark@winterfell.westeros'
184
- }, {
185
- email: 'sansa.stark@winterfell.westeros'
186
- }, {
187
- email: 'jon.snow@thewall.westeros'
188
- }];
189
- var addedRecipients = [{
190
- _id: 'e8c0e15f-da7d',
191
- _type: 'io.cozy.contacts',
192
- fullname: 'Jon Snow',
193
- email: [{
194
- address: 'jon.snow@thewall.westeros',
195
- primary: true
196
- }, {
197
- address: 'jon.snow@winterfell.westeros',
198
- primary: false
199
- }]
200
- }, {
201
- _id: 'fcb16b9e-7421',
202
- _type: 'io.cozy.contacts'
203
- }, {
204
- _id: 'f45b16be-7523',
205
- _type: 'io.cozy.contacts',
206
- cozy: [{
207
- url: 'https://doranmartell.mycozy.cloud'
208
- }]
209
- }];
210
- it('should count the new recipients with email', function () {
211
- var result = countNewRecipients(currentRecipients, addedRecipients);
212
- expect(result.contact).toEqual(2);
213
- expect(result.group).toEqual(0);
214
- });
215
- it('should count the new recipients with cozy url', function () {
216
- var currentRecipients = [{
217
- instance: 'https://bran.mycozy.cloud'
218
- }, {
219
- instance: 'https://jon.mycozy.cloud'
220
- }];
221
- var addedRecipients = [{
222
- _type: 'io.cozy.contacts',
223
- cozy: [{
224
- url: 'https://jon.mycozy.cloud',
225
- type: 'primary'
226
- }]
227
- }, {
228
- _type: 'io.cozy.contacts',
229
- cozy: [{
230
- url: 'https://sansa.mycozy.cloud',
231
- type: 'primary'
232
- }]
233
- }, {
234
- _type: 'io.cozy.contacts',
235
- cozy: [{
236
- url: 'https://bran.mycozy.cloud',
237
- type: 'primary'
238
- }]
239
- }, {
240
- _type: 'io.cozy.contacts',
241
- cozy: [{
242
- url: 'https://arya.mycozy.cloud',
243
- type: 'primary'
244
- }]
245
- }];
246
- var result = countNewRecipients(currentRecipients, addedRecipients);
247
- expect(result.contact).toEqual(2);
248
- expect(result.group).toEqual(0);
249
- });
250
- it('should count the new recipients with groups', function () {
251
- var result = countNewRecipients(currentRecipients, [].concat(addedRecipients, [{
252
- _id: 'f45b16be-7523',
253
- _type: 'io.cozy.contacts.groups'
254
- }]));
255
- expect(result.contact).toEqual(2);
256
- expect(result.group).toEqual(1);
257
- });
258
- it('should return 0 if there are no new recipients', function () {
259
- var result = countNewRecipients(currentRecipients, []);
260
- expect(result.contact).toEqual(0);
261
- expect(result.group).toEqual(0);
262
- });
263
- });
@@ -1,293 +0,0 @@
1
- import { getSuccessMessage, countNewRecipients } from './successMessage'
2
-
3
- describe('getSuccessMessage method', () => {
4
- const props = {
5
- currentRecipients: [{ email: 'sansa.stark@winterfell.westeros' }],
6
- documentType: 'Files',
7
- sharingDesc: 'fake-doc.odt',
8
- onShare: jest.fn(),
9
- createContact: jest.fn()
10
- }
11
-
12
- it('should return a success message and its params for multiple recipients', () => {
13
- const recipientsAfter = [
14
- { _type: 'io.cozy.contacts', email: 'jon.snow@thewall.westeros' },
15
- { _type: 'io.cozy.contacts', email: 'arya.stark@winterfell.westeros' },
16
- { _type: 'io.cozy.contacts', email: 'sansa.stark@winterfell.westeros' }
17
- ]
18
- const [message, params] = getSuccessMessage(
19
- props.currentRecipients,
20
- recipientsAfter,
21
- props.documentType
22
- )
23
- expect(message).toEqual('Files.share.shareByEmail.contactSuccess')
24
- expect(params).toEqual({ smart_count: 2 })
25
- })
26
-
27
- it('should return a success message and its params for one recipient with email', () => {
28
- const recipientsBefore = props.currentRecipients
29
- const [message, params] = getSuccessMessage(
30
- recipientsBefore,
31
- [{ email: 'jon.snow@thewall.westeros' }],
32
- props.documentType
33
- )
34
- expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess')
35
- expect(params).toEqual({ email: 'jon.snow@thewall.westeros' })
36
- })
37
-
38
- it('should return a success message and its params for one recipient (contact) with email', () => {
39
- const recipientsBefore = props.currentRecipients
40
- const [message, params] = getSuccessMessage(
41
- recipientsBefore,
42
- [
43
- {
44
- _id: 'e8c0e15f-da7d',
45
- _type: 'io.cozy.contacts',
46
- fullname: 'Jon Snow',
47
- email: [
48
- {
49
- address: 'jon.snow@thewall.westeros',
50
- primary: true
51
- },
52
- {
53
- address: 'jon.snow@winterfell.westeros',
54
- primary: false
55
- }
56
- ]
57
- }
58
- ],
59
- props.documentType
60
- )
61
- expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess')
62
- expect(params).toEqual({ email: 'jon.snow@thewall.westeros' })
63
- })
64
-
65
- it('should return a success message and its params for one recipient with cozy', () => {
66
- const recipientsBefore = props.currentRecipients
67
- const [message, params] = getSuccessMessage(
68
- recipientsBefore,
69
- [
70
- {
71
- cozy: [
72
- {
73
- url: 'https://doranmartell.mycozy.cloud'
74
- }
75
- ]
76
- }
77
- ],
78
- props.documentType
79
- )
80
- expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess')
81
- expect(params).toEqual({ email: 'https://doranmartell.mycozy.cloud' })
82
- })
83
-
84
- it('should use contact success message if recipient has no email and no cozy', () => {
85
- const recipientsBefore = props.currentRecipients
86
- const [message, params] = getSuccessMessage(
87
- recipientsBefore,
88
- [
89
- {
90
- _id: 'fcb16b9e-7421'
91
- }
92
- ],
93
- props.documentType
94
- )
95
- expect(message).toEqual('Files.share.shareByEmail.contactSuccess')
96
- expect(params).toEqual({ smart_count: 1 })
97
- })
98
-
99
- it('should use single group success message if recipient is a group', () => {
100
- const recipientsBefore = props.currentRecipients
101
- const [message, params] = getSuccessMessage(
102
- recipientsBefore,
103
- [
104
- {
105
- _type: 'io.cozy.contacts.groups',
106
- name: 'Stark family'
107
- }
108
- ],
109
- props.documentType
110
- )
111
- expect(message).toEqual('Files.share.shareByEmail.singleGroupSuccess')
112
- expect(params).toEqual({ groupName: 'Stark family' })
113
- })
114
-
115
- it('should use contact success message if recipient has only multiple contacts', () => {
116
- const recipientsBefore = props.currentRecipients
117
- const [message, params] = getSuccessMessage(
118
- recipientsBefore,
119
- [
120
- {
121
- _type: 'io.cozy.contacts'
122
- },
123
- {
124
- _type: 'io.cozy.contacts'
125
- },
126
- {
127
- _type: 'io.cozy.contacts'
128
- }
129
- ],
130
- props.documentType
131
- )
132
- expect(message).toEqual('Files.share.shareByEmail.contactSuccess')
133
- expect(params).toEqual({ smart_count: 3 })
134
- })
135
-
136
- it('should use group success message if recipient has only multiple groups', () => {
137
- const recipientsBefore = props.currentRecipients
138
- const [message, params] = getSuccessMessage(
139
- recipientsBefore,
140
- [
141
- {
142
- _type: 'io.cozy.contacts.groups'
143
- },
144
- {
145
- _type: 'io.cozy.contacts.groups'
146
- }
147
- ],
148
- props.documentType
149
- )
150
- expect(message).toEqual('Files.share.shareByEmail.groupSuccess')
151
- expect(params).toEqual({ smart_count: 2 })
152
- })
153
-
154
- it('should use contact and group success message if recipient has multiple contacts and groups', () => {
155
- const recipientsBefore = props.currentRecipients
156
- const [message, params] = getSuccessMessage(
157
- recipientsBefore,
158
- [
159
- {
160
- _type: 'io.cozy.contacts'
161
- },
162
- {
163
- _id: 'fcb16b9e-7421',
164
- _type: 'io.cozy.contacts.groups'
165
- },
166
- {
167
- _id: 'f45b16be-7523',
168
- _type: 'io.cozy.contacts.groups'
169
- }
170
- ],
171
- props.documentType
172
- )
173
- expect(message).toEqual('Files.share.shareByEmail.contactAndGroupSuccess')
174
- expect(params).toEqual({ nbContact: 1, nbGroup: 2 })
175
- })
176
- })
177
-
178
- describe('countNewRecipients', () => {
179
- const currentRecipients = [
180
- {
181
- email: 'arya.stark@winterfell.westeros'
182
- },
183
- {
184
- email: 'sansa.stark@winterfell.westeros'
185
- },
186
- {
187
- email: 'jon.snow@thewall.westeros'
188
- }
189
- ]
190
- const addedRecipients = [
191
- {
192
- _id: 'e8c0e15f-da7d',
193
- _type: 'io.cozy.contacts',
194
- fullname: 'Jon Snow',
195
- email: [
196
- {
197
- address: 'jon.snow@thewall.westeros',
198
- primary: true
199
- },
200
- {
201
- address: 'jon.snow@winterfell.westeros',
202
- primary: false
203
- }
204
- ]
205
- },
206
- {
207
- _id: 'fcb16b9e-7421',
208
- _type: 'io.cozy.contacts'
209
- },
210
- {
211
- _id: 'f45b16be-7523',
212
- _type: 'io.cozy.contacts',
213
- cozy: [
214
- {
215
- url: 'https://doranmartell.mycozy.cloud'
216
- }
217
- ]
218
- }
219
- ]
220
-
221
- it('should count the new recipients with email', () => {
222
- const result = countNewRecipients(currentRecipients, addedRecipients)
223
- expect(result.contact).toEqual(2)
224
- expect(result.group).toEqual(0)
225
- })
226
-
227
- it('should count the new recipients with cozy url', () => {
228
- const currentRecipients = [
229
- {
230
- instance: 'https://bran.mycozy.cloud'
231
- },
232
- {
233
- instance: 'https://jon.mycozy.cloud'
234
- }
235
- ]
236
- const addedRecipients = [
237
- {
238
- _type: 'io.cozy.contacts',
239
- cozy: [
240
- {
241
- url: 'https://jon.mycozy.cloud',
242
- type: 'primary'
243
- }
244
- ]
245
- },
246
- {
247
- _type: 'io.cozy.contacts',
248
- cozy: [
249
- {
250
- url: 'https://sansa.mycozy.cloud',
251
- type: 'primary'
252
- }
253
- ]
254
- },
255
- {
256
- _type: 'io.cozy.contacts',
257
- cozy: [
258
- {
259
- url: 'https://bran.mycozy.cloud',
260
- type: 'primary'
261
- }
262
- ]
263
- },
264
- {
265
- _type: 'io.cozy.contacts',
266
- cozy: [
267
- {
268
- url: 'https://arya.mycozy.cloud',
269
- type: 'primary'
270
- }
271
- ]
272
- }
273
- ]
274
- const result = countNewRecipients(currentRecipients, addedRecipients)
275
- expect(result.contact).toEqual(2)
276
- expect(result.group).toEqual(0)
277
- })
278
-
279
- it('should count the new recipients with groups', () => {
280
- const result = countNewRecipients(currentRecipients, [
281
- ...addedRecipients,
282
- { _id: 'f45b16be-7523', _type: 'io.cozy.contacts.groups' }
283
- ])
284
- expect(result.contact).toEqual(2)
285
- expect(result.group).toEqual(1)
286
- })
287
-
288
- it('should return 0 if there are no new recipients', () => {
289
- const result = countNewRecipients(currentRecipients, [])
290
- expect(result.contact).toEqual(0)
291
- expect(result.group).toEqual(0)
292
- })
293
- })