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.
@@ -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
- })