cozy-sharing 13.1.2 → 13.3.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.
- package/CHANGELOG.md +27 -0
- package/dist/components/Recipient/GroupRecipientDetail.js +20 -1
- package/dist/components/Recipient/GroupRecipientDetailWithoutAccess.js +1 -1
- package/dist/components/ShareByEmail.js +19 -39
- package/dist/components/ShareRecipientsInput.js +5 -11
- package/dist/components/ShareRecipientsInput.spec.js +1 -1
- package/dist/helpers/{successMessage.js → share.js} +34 -1
- package/dist/helpers/share.spec.js +385 -0
- package/dist/queries/queries.js +4 -5
- package/locales/en.json +6 -1
- package/locales/fr.json +6 -1
- package/package.json +2 -2
- package/src/components/Recipient/GroupRecipientDetail.jsx +22 -0
- package/src/components/Recipient/GroupRecipientDetailWithoutAccess.jsx +1 -1
- package/src/components/ShareByEmail.jsx +13 -34
- package/src/components/ShareRecipientsInput.jsx +8 -16
- package/src/components/ShareRecipientsInput.spec.jsx +1 -1
- package/src/helpers/{successMessage.js → share.js} +46 -1
- package/src/helpers/share.spec.js +424 -0
- package/src/queries/queries.js +4 -5
- package/dist/helpers/successMessage.spec.js +0 -263
- package/src/helpers/successMessage.spec.js +0 -293
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { getSuccessMessage, countNewRecipients, getErrorMessage } from './share'
|
|
2
|
+
|
|
3
|
+
describe('share', () => {
|
|
4
|
+
describe('getSuccessMessage', () => {
|
|
5
|
+
const props = {
|
|
6
|
+
currentRecipients: [{ email: 'sansa.stark@winterfell.westeros' }],
|
|
7
|
+
documentType: 'Files',
|
|
8
|
+
sharingDesc: 'fake-doc.odt',
|
|
9
|
+
onShare: jest.fn(),
|
|
10
|
+
createContact: jest.fn()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
it('should return a success message and its params for multiple recipients', () => {
|
|
14
|
+
const recipientsAfter = [
|
|
15
|
+
{ _type: 'io.cozy.contacts', email: 'jon.snow@thewall.westeros' },
|
|
16
|
+
{ _type: 'io.cozy.contacts', email: 'arya.stark@winterfell.westeros' },
|
|
17
|
+
{ _type: 'io.cozy.contacts', email: 'sansa.stark@winterfell.westeros' }
|
|
18
|
+
]
|
|
19
|
+
const [message, params] = getSuccessMessage(
|
|
20
|
+
props.currentRecipients,
|
|
21
|
+
recipientsAfter,
|
|
22
|
+
props.documentType
|
|
23
|
+
)
|
|
24
|
+
expect(message).toEqual('Files.share.shareByEmail.contactSuccess')
|
|
25
|
+
expect(params).toEqual({ smart_count: 2 })
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('should return a success message and its params for one recipient with email', () => {
|
|
29
|
+
const recipientsBefore = props.currentRecipients
|
|
30
|
+
const [message, params] = getSuccessMessage(
|
|
31
|
+
recipientsBefore,
|
|
32
|
+
[{ email: 'jon.snow@thewall.westeros' }],
|
|
33
|
+
props.documentType
|
|
34
|
+
)
|
|
35
|
+
expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess')
|
|
36
|
+
expect(params).toEqual({ email: 'jon.snow@thewall.westeros' })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should return a success message and its params for one recipient (contact) with email', () => {
|
|
40
|
+
const recipientsBefore = props.currentRecipients
|
|
41
|
+
const [message, params] = getSuccessMessage(
|
|
42
|
+
recipientsBefore,
|
|
43
|
+
[
|
|
44
|
+
{
|
|
45
|
+
_id: 'e8c0e15f-da7d',
|
|
46
|
+
_type: 'io.cozy.contacts',
|
|
47
|
+
fullname: 'Jon Snow',
|
|
48
|
+
email: [
|
|
49
|
+
{
|
|
50
|
+
address: 'jon.snow@thewall.westeros',
|
|
51
|
+
primary: true
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
address: 'jon.snow@winterfell.westeros',
|
|
55
|
+
primary: false
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
props.documentType
|
|
61
|
+
)
|
|
62
|
+
expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess')
|
|
63
|
+
expect(params).toEqual({ email: 'jon.snow@thewall.westeros' })
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should return a success message and its params for one recipient with cozy', () => {
|
|
67
|
+
const recipientsBefore = props.currentRecipients
|
|
68
|
+
const [message, params] = getSuccessMessage(
|
|
69
|
+
recipientsBefore,
|
|
70
|
+
[
|
|
71
|
+
{
|
|
72
|
+
cozy: [
|
|
73
|
+
{
|
|
74
|
+
url: 'https://doranmartell.mycozy.cloud'
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
props.documentType
|
|
80
|
+
)
|
|
81
|
+
expect(message).toEqual('Files.share.shareByEmail.singleContactSuccess')
|
|
82
|
+
expect(params).toEqual({ email: 'https://doranmartell.mycozy.cloud' })
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('should use contact success message if recipient has no email and no cozy', () => {
|
|
86
|
+
const recipientsBefore = props.currentRecipients
|
|
87
|
+
const [message, params] = getSuccessMessage(
|
|
88
|
+
recipientsBefore,
|
|
89
|
+
[
|
|
90
|
+
{
|
|
91
|
+
_id: 'fcb16b9e-7421'
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
props.documentType
|
|
95
|
+
)
|
|
96
|
+
expect(message).toEqual('Files.share.shareByEmail.contactSuccess')
|
|
97
|
+
expect(params).toEqual({ smart_count: 1 })
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('should use single group success message if recipient is a group', () => {
|
|
101
|
+
const recipientsBefore = props.currentRecipients
|
|
102
|
+
const [message, params] = getSuccessMessage(
|
|
103
|
+
recipientsBefore,
|
|
104
|
+
[
|
|
105
|
+
{
|
|
106
|
+
_type: 'io.cozy.contacts.groups',
|
|
107
|
+
name: 'Stark family'
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
props.documentType
|
|
111
|
+
)
|
|
112
|
+
expect(message).toEqual('Files.share.shareByEmail.singleGroupSuccess')
|
|
113
|
+
expect(params).toEqual({ groupName: 'Stark family' })
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('should use contact success message if recipient has only multiple contacts', () => {
|
|
117
|
+
const recipientsBefore = props.currentRecipients
|
|
118
|
+
const [message, params] = getSuccessMessage(
|
|
119
|
+
recipientsBefore,
|
|
120
|
+
[
|
|
121
|
+
{
|
|
122
|
+
_type: 'io.cozy.contacts'
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
_type: 'io.cozy.contacts'
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
_type: 'io.cozy.contacts'
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
props.documentType
|
|
132
|
+
)
|
|
133
|
+
expect(message).toEqual('Files.share.shareByEmail.contactSuccess')
|
|
134
|
+
expect(params).toEqual({ smart_count: 3 })
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('should use group success message if recipient has only multiple groups', () => {
|
|
138
|
+
const recipientsBefore = props.currentRecipients
|
|
139
|
+
const [message, params] = getSuccessMessage(
|
|
140
|
+
recipientsBefore,
|
|
141
|
+
[
|
|
142
|
+
{
|
|
143
|
+
_type: 'io.cozy.contacts.groups'
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
_type: 'io.cozy.contacts.groups'
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
props.documentType
|
|
150
|
+
)
|
|
151
|
+
expect(message).toEqual('Files.share.shareByEmail.groupSuccess')
|
|
152
|
+
expect(params).toEqual({ smart_count: 2 })
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('should use contact and group success message if recipient has multiple contacts and groups', () => {
|
|
156
|
+
const recipientsBefore = props.currentRecipients
|
|
157
|
+
const [message, params] = getSuccessMessage(
|
|
158
|
+
recipientsBefore,
|
|
159
|
+
[
|
|
160
|
+
{
|
|
161
|
+
_type: 'io.cozy.contacts'
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
_id: 'fcb16b9e-7421',
|
|
165
|
+
_type: 'io.cozy.contacts.groups'
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
_id: 'f45b16be-7523',
|
|
169
|
+
_type: 'io.cozy.contacts.groups'
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
props.documentType
|
|
173
|
+
)
|
|
174
|
+
expect(message).toEqual('Files.share.shareByEmail.contactAndGroupSuccess')
|
|
175
|
+
expect(params).toEqual({ nbContact: 1, nbGroup: 2 })
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
describe('countNewRecipients', () => {
|
|
180
|
+
const currentRecipients = [
|
|
181
|
+
{
|
|
182
|
+
email: 'arya.stark@winterfell.westeros'
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
email: 'sansa.stark@winterfell.westeros'
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
email: 'jon.snow@thewall.westeros'
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
const addedRecipients = [
|
|
192
|
+
{
|
|
193
|
+
_id: 'e8c0e15f-da7d',
|
|
194
|
+
_type: 'io.cozy.contacts',
|
|
195
|
+
fullname: 'Jon Snow',
|
|
196
|
+
email: [
|
|
197
|
+
{
|
|
198
|
+
address: 'jon.snow@thewall.westeros',
|
|
199
|
+
primary: true
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
address: 'jon.snow@winterfell.westeros',
|
|
203
|
+
primary: false
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
_id: 'fcb16b9e-7421',
|
|
209
|
+
_type: 'io.cozy.contacts'
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
_id: 'f45b16be-7523',
|
|
213
|
+
_type: 'io.cozy.contacts',
|
|
214
|
+
cozy: [
|
|
215
|
+
{
|
|
216
|
+
url: 'https://doranmartell.mycozy.cloud'
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
|
|
222
|
+
it('should count the new recipients with email', () => {
|
|
223
|
+
const result = countNewRecipients(currentRecipients, addedRecipients)
|
|
224
|
+
expect(result.contact).toEqual(2)
|
|
225
|
+
expect(result.group).toEqual(0)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('should count the new recipients with cozy url', () => {
|
|
229
|
+
const currentRecipients = [
|
|
230
|
+
{
|
|
231
|
+
instance: 'https://bran.mycozy.cloud'
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
instance: 'https://jon.mycozy.cloud'
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
const addedRecipients = [
|
|
238
|
+
{
|
|
239
|
+
_type: 'io.cozy.contacts',
|
|
240
|
+
cozy: [
|
|
241
|
+
{
|
|
242
|
+
url: 'https://jon.mycozy.cloud',
|
|
243
|
+
type: 'primary'
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
_type: 'io.cozy.contacts',
|
|
249
|
+
cozy: [
|
|
250
|
+
{
|
|
251
|
+
url: 'https://sansa.mycozy.cloud',
|
|
252
|
+
type: 'primary'
|
|
253
|
+
}
|
|
254
|
+
]
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
_type: 'io.cozy.contacts',
|
|
258
|
+
cozy: [
|
|
259
|
+
{
|
|
260
|
+
url: 'https://bran.mycozy.cloud',
|
|
261
|
+
type: 'primary'
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
_type: 'io.cozy.contacts',
|
|
267
|
+
cozy: [
|
|
268
|
+
{
|
|
269
|
+
url: 'https://arya.mycozy.cloud',
|
|
270
|
+
type: 'primary'
|
|
271
|
+
}
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
const result = countNewRecipients(currentRecipients, addedRecipients)
|
|
276
|
+
expect(result.contact).toEqual(2)
|
|
277
|
+
expect(result.group).toEqual(0)
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
it('should count the new recipients with groups', () => {
|
|
281
|
+
const result = countNewRecipients(currentRecipients, [
|
|
282
|
+
...addedRecipients,
|
|
283
|
+
{ _id: 'f45b16be-7523', _type: 'io.cozy.contacts.groups' }
|
|
284
|
+
])
|
|
285
|
+
expect(result.contact).toEqual(2)
|
|
286
|
+
expect(result.group).toEqual(1)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it('should return 0 if there are no new recipients', () => {
|
|
290
|
+
const result = countNewRecipients(currentRecipients, [])
|
|
291
|
+
expect(result.contact).toEqual(0)
|
|
292
|
+
expect(result.group).toEqual(0)
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
describe('getErrorMessage', () => {
|
|
297
|
+
const t = key => key // Mock translation function
|
|
298
|
+
const documentType = 'document'
|
|
299
|
+
const recipients = [{ name: 'John Doe' }]
|
|
300
|
+
const selectedOption = 'readOnly'
|
|
301
|
+
|
|
302
|
+
it('should return generic error message for non-FetchError', () => {
|
|
303
|
+
const err = new Error('Some error')
|
|
304
|
+
const result = getErrorMessage({
|
|
305
|
+
t,
|
|
306
|
+
err,
|
|
307
|
+
documentType,
|
|
308
|
+
recipients,
|
|
309
|
+
selectedOption
|
|
310
|
+
})
|
|
311
|
+
expect(result).toEqual([`${documentType}.share.error.generic`])
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('should return specific error message for FetchError with status 400 and specific detail', () => {
|
|
315
|
+
const err = {
|
|
316
|
+
name: 'FetchError',
|
|
317
|
+
status: 400,
|
|
318
|
+
message: JSON.stringify({
|
|
319
|
+
errors: [
|
|
320
|
+
{ detail: 'A group member cannot be added as they are already in' }
|
|
321
|
+
]
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
const result = getErrorMessage({
|
|
325
|
+
t,
|
|
326
|
+
err,
|
|
327
|
+
documentType,
|
|
328
|
+
recipients,
|
|
329
|
+
selectedOption
|
|
330
|
+
})
|
|
331
|
+
expect(result).toEqual([
|
|
332
|
+
'Share.errors.groupMemberAlreadyInSharing',
|
|
333
|
+
{
|
|
334
|
+
smart_count: recipients.length,
|
|
335
|
+
groupName: recipients[0].name,
|
|
336
|
+
sharingRights: 'Share.errors.sharingRights.readWrite',
|
|
337
|
+
icon: false
|
|
338
|
+
}
|
|
339
|
+
])
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
it('should return opposite sharingRights for the other group when the group member already in sharing', () => {
|
|
343
|
+
const err = {
|
|
344
|
+
name: 'FetchError',
|
|
345
|
+
status: 400,
|
|
346
|
+
message: JSON.stringify({
|
|
347
|
+
errors: [
|
|
348
|
+
{ detail: 'A group member cannot be added as they are already in' }
|
|
349
|
+
]
|
|
350
|
+
})
|
|
351
|
+
}
|
|
352
|
+
const result = getErrorMessage({
|
|
353
|
+
t,
|
|
354
|
+
err,
|
|
355
|
+
documentType,
|
|
356
|
+
recipients,
|
|
357
|
+
selectedOption: 'readWrite'
|
|
358
|
+
})
|
|
359
|
+
expect(result).toEqual([
|
|
360
|
+
'Share.errors.groupMemberAlreadyInSharing',
|
|
361
|
+
{
|
|
362
|
+
smart_count: recipients.length,
|
|
363
|
+
groupName: recipients[0].name,
|
|
364
|
+
sharingRights: 'Share.errors.sharingRights.readOnly',
|
|
365
|
+
icon: false
|
|
366
|
+
}
|
|
367
|
+
])
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
it('should return specific text if there is only one recipient and it is a contact', () => {
|
|
371
|
+
const err = {
|
|
372
|
+
name: 'FetchError',
|
|
373
|
+
status: 400,
|
|
374
|
+
message: JSON.stringify({
|
|
375
|
+
errors: [
|
|
376
|
+
{ detail: 'A group member cannot be added as they are already in' }
|
|
377
|
+
]
|
|
378
|
+
})
|
|
379
|
+
}
|
|
380
|
+
const result = getErrorMessage({
|
|
381
|
+
t,
|
|
382
|
+
err,
|
|
383
|
+
documentType,
|
|
384
|
+
recipients: [
|
|
385
|
+
{
|
|
386
|
+
_type: 'io.cozy.contacts',
|
|
387
|
+
name: {
|
|
388
|
+
givenName: 'John',
|
|
389
|
+
familyName: 'Doe'
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
],
|
|
393
|
+
selectedOption
|
|
394
|
+
})
|
|
395
|
+
expect(result).toEqual([
|
|
396
|
+
'Share.errors.contactAlreadyInSharing',
|
|
397
|
+
{
|
|
398
|
+
smart_count: recipients.length,
|
|
399
|
+
contactName: 'John Doe',
|
|
400
|
+
sharingRights: 'Share.errors.sharingRights.readWrite',
|
|
401
|
+
icon: false
|
|
402
|
+
}
|
|
403
|
+
])
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
it('should return generic error message for FetchError with status 400 and different detail', () => {
|
|
407
|
+
const err = {
|
|
408
|
+
name: 'FetchError',
|
|
409
|
+
status: 400,
|
|
410
|
+
message: JSON.stringify({
|
|
411
|
+
errors: [{ detail: 'Some other detail' }]
|
|
412
|
+
})
|
|
413
|
+
}
|
|
414
|
+
const result = getErrorMessage({
|
|
415
|
+
t,
|
|
416
|
+
err,
|
|
417
|
+
documentType,
|
|
418
|
+
recipients,
|
|
419
|
+
selectedOption
|
|
420
|
+
})
|
|
421
|
+
expect(result).toEqual([`${documentType}.share.error.generic`])
|
|
422
|
+
})
|
|
423
|
+
})
|
|
424
|
+
})
|
package/src/queries/queries.js
CHANGED
|
@@ -59,12 +59,11 @@ export const buildReachableContactsQuery = () => ({
|
|
|
59
59
|
}
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
export const
|
|
63
|
-
definition: Q(Group.doctype)
|
|
62
|
+
export const buildContactGroupsQuery = () => ({
|
|
63
|
+
definition: Q(Group.doctype),
|
|
64
64
|
options: {
|
|
65
|
-
as: `io.cozy.contacts.groups
|
|
66
|
-
fetchPolicy: defaultFetchPolicy
|
|
67
|
-
enabled: ids.length > 0
|
|
65
|
+
as: `io.cozy.contacts.groups`,
|
|
66
|
+
fetchPolicy: defaultFetchPolicy
|
|
68
67
|
}
|
|
69
68
|
})
|
|
70
69
|
|
|
@@ -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
|
-
});
|