Remove payments API routing initialization
[ProtonMail-WebClient.git] / packages / components / containers / addresses / helper.test.tsx
blobbb20450c902261b027ed7167ae5dcfbbf2c80a43
1 import {
2     canReceive,
3     canSend,
4     getPermission,
5     getReceivePermission,
6     getSendPermission,
7     hasIncompleteSetup,
8     noPermissionMap,
9     permissionsMap,
10     permissionsReceiveMap,
11     permissionsSendMap,
12     setupIncompletePermissionMap,
13 } from '@proton/components/containers/addresses/helper';
14 import { ADDRESS_PERMISSIONS, ADDRESS_PERMISSION_TYPE } from '@proton/shared/lib/constants';
16 describe('addresses helper functions', () => {
17     describe('canReceive', () => {
18         it('Should return true for any receive permission', () => {
19             expect(
20                 canReceive(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)
21             ).toBeTruthy();
22             expect(
23                 canReceive(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)
24             ).toBeTruthy();
25             expect(
26                 canReceive(
27                     ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL |
28                         ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG |
29                         ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL
30                 )
31             ).toBeTruthy();
32         });
33         it('Should return false if no receive permission', () => {
34             expect(canReceive(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)).toBeFalsy();
35             expect(canReceive(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG)).toBeFalsy();
36             expect(
37                 canReceive(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG)
38             ).toBeFalsy();
39         });
40     });
42     describe('canSend', () => {
43         it('Should return true for any send permission', () => {
44             expect(
45                 canSend(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)
46             ).toBeTruthy();
47             expect(
48                 canSend(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)
49             ).toBeTruthy();
50             expect(
51                 canSend(
52                     ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL |
53                         ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG |
54                         ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL
55                 )
56             ).toBeTruthy();
57         });
58         it('Should return false if no send permission', () => {
59             expect(canSend(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)).toBeFalsy();
60             expect(canSend(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG)).toBeFalsy();
61             expect(
62                 canSend(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG)
63             ).toBeFalsy();
64         });
65     });
67     describe('hasIncompleteSetup', () => {
68         it('Should return true when no receive and send permission both', () => {
69             expect(hasIncompleteSetup(ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER)).toBeTruthy();
70             expect(hasIncompleteSetup(ADDRESS_PERMISSIONS.NO_PERMISSION)).toBeTruthy();
71         });
72         it('Should return false when at least one of the receive or send permission set', () => {
73             expect(hasIncompleteSetup(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)).toBeFalsy();
74             expect(hasIncompleteSetup(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG)).toBeFalsy();
75             expect(hasIncompleteSetup(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)).toBeFalsy();
76             expect(hasIncompleteSetup(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG)).toBeFalsy();
77         });
78     });
80     describe('noPermissionMap', () => {
81         it('Should return one no permission option', () => {
82             const options = noPermissionMap();
83             expect(options).toHaveLength(1);
84             expect(options[0].text).toEqual('No permission');
85             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
86         });
87     });
89     describe('setupIncompletePermissionMap', () => {
90         it('Should return one setup incomplete option', () => {
91             const options = setupIncompletePermissionMap();
92             expect(options).toHaveLength(1);
93             expect(options[0].text).toEqual('Setup incomplete');
94             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
95         });
96     });
98     describe('permissionsReceiveMap', () => {
99         it('Should return two receive permission options', () => {
100             const options = permissionsReceiveMap();
101             expect(options).toHaveLength(2);
102             expect(options[0].text).toEqual('Receive from all');
103             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL);
104             expect(options[1].text).toEqual('Organization only');
105             expect(options[1].value).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG);
106         });
107     });
109     describe('permissionsSendMap', () => {
110         it('Should return two send permission options', () => {
111             const options = permissionsSendMap();
112             expect(options).toHaveLength(2);
113             expect(options[0].text).toEqual('Send to all');
114             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL);
115             expect(options[1].text).toEqual('Organization only');
116             expect(options[1].value).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG);
117         });
118     });
120     describe('getReceivePermission', () => {
121         it('Should return ALL permission in priority', () => {
122             expect(getReceivePermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)).toEqual(
123                 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL
124             );
125             expect(
126                 getReceivePermission(
127                     ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG
128                 )
129             ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL);
130             expect(
131                 getReceivePermission(
132                     ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL |
133                         ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG |
134                         ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL
135                 )
136             ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL);
137         });
138         it('Should return ORG permission', () => {
139             expect(getReceivePermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG)).toEqual(
140                 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG
141             );
142             expect(
143                 getReceivePermission(
144                     ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL
145                 )
146             ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG);
147         });
148         it('Should default to no permission', () => {
149             expect(getReceivePermission(ADDRESS_PERMISSIONS.NO_PERMISSION)).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
150             expect(getReceivePermission(ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER)).toEqual(
151                 ADDRESS_PERMISSIONS.NO_PERMISSION
152             );
153             expect(getReceivePermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)).toEqual(
154                 ADDRESS_PERMISSIONS.NO_PERMISSION
155             );
156         });
157     });
159     describe('getSendPermission', () => {
160         it('Should return ALL permission in priority', () => {
161             expect(getSendPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)).toEqual(
162                 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL
163             );
164             expect(
165                 getSendPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG)
166             ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL);
167             expect(
168                 getSendPermission(
169                     ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL |
170                         ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG |
171                         ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL
172                 )
173             ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL);
174         });
175         it('Should return ORG permission', () => {
176             expect(getSendPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG)).toEqual(
177                 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG
178             );
179             expect(
180                 getSendPermission(
181                     ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL
182                 )
183             ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG);
184         });
185         it('Should default to no permission', () => {
186             expect(getSendPermission(ADDRESS_PERMISSIONS.NO_PERMISSION)).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
187             expect(getSendPermission(ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER)).toEqual(
188                 ADDRESS_PERMISSIONS.NO_PERMISSION
189             );
190             expect(getSendPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)).toEqual(
191                 ADDRESS_PERMISSIONS.NO_PERMISSION
192             );
193         });
194     });
196     describe('permissionsMap', () => {
197         it('Should return two receive permission options', () => {
198             const options = permissionsMap(
199                 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL,
200                 ADDRESS_PERMISSION_TYPE.RECEIVE
201             );
202             expect(options).toHaveLength(2);
203             expect(options[0].text).toEqual('Receive from all');
204             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL);
205             expect(options[1].text).toEqual('Organization only');
206             expect(options[1].value).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG);
207         });
208         it('Should return no receive permission option', () => {
209             const options = permissionsMap(
210                 ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL,
211                 ADDRESS_PERMISSION_TYPE.RECEIVE
212             );
213             expect(options).toHaveLength(1);
214             expect(options[0].text).toEqual('No permission');
215             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
216         });
217         it('Should return setup incomplete option', () => {
218             const options = permissionsMap(
219                 ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER,
220                 ADDRESS_PERMISSION_TYPE.RECEIVE
221             );
222             expect(options).toHaveLength(1);
223             expect(options[0].text).toEqual('Setup incomplete');
224             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
225         });
226         it('Should return two send permission options', () => {
227             const options = permissionsMap(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL, ADDRESS_PERMISSION_TYPE.SEND);
228             expect(options).toHaveLength(2);
229             expect(options[0].text).toEqual('Send to all');
230             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL);
231             expect(options[1].text).toEqual('Organization only');
232             expect(options[1].value).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG);
233         });
234         it('Should return no send permission option', () => {
235             const options = permissionsMap(
236                 ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL,
237                 ADDRESS_PERMISSION_TYPE.SEND
238             );
239             expect(options).toHaveLength(1);
240             expect(options[0].text).toEqual('No permission');
241             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
242         });
243         it('Should return setup incomplete option', () => {
244             const options = permissionsMap(ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER, ADDRESS_PERMISSION_TYPE.SEND);
245             expect(options).toHaveLength(1);
246             expect(options[0].text).toEqual('Setup incomplete');
247             expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
248         });
249     });
251     describe('getPermission', () => {
252         it('Should return receive all permission in priority', () => {
253             expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL, ADDRESS_PERMISSION_TYPE.RECEIVE)).toEqual(
254                 'Receive from all'
255             );
256             expect(
257                 getPermission(
258                     ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG,
259                     ADDRESS_PERMISSION_TYPE.RECEIVE
260                 )
261             ).toEqual('Receive from all');
262             expect(
263                 getPermission(
264                     ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL |
265                         ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG |
266                         ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL,
267                     ADDRESS_PERMISSION_TYPE.RECEIVE
268                 )
269             ).toEqual('Receive from all');
270         });
271         it('Should return receive org permission', () => {
272             expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG, ADDRESS_PERMISSION_TYPE.RECEIVE)).toEqual(
273                 'Organization only'
274             );
275             expect(
276                 getPermission(
277                     ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL,
278                     ADDRESS_PERMISSION_TYPE.RECEIVE
279                 )
280             ).toEqual('Organization only');
281         });
282         it('Should return receive setup incomplete', () => {
283             expect(getPermission(ADDRESS_PERMISSIONS.NO_PERMISSION, ADDRESS_PERMISSION_TYPE.RECEIVE)).toEqual(
284                 'Setup incomplete'
285             );
286             expect(
287                 getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER, ADDRESS_PERMISSION_TYPE.RECEIVE)
288             ).toEqual('Setup incomplete');
289         });
290         it('Should default to receive no permission', () => {
291             expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL, ADDRESS_PERMISSION_TYPE.RECEIVE)).toEqual(
292                 'No permission'
293             );
294             expect(
295                 getPermission(
296                     ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL,
297                     ADDRESS_PERMISSION_TYPE.RECEIVE
298                 )
299             ).toEqual('No permission');
300         });
301         it('Should return send all permission in priority', () => {
302             expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
303                 'Send to all'
304             );
305             expect(
306                 getPermission(
307                     ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG,
308                     ADDRESS_PERMISSION_TYPE.SEND
309                 )
310             ).toEqual('Send to all');
311             expect(
312                 getPermission(
313                     ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL |
314                         ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG |
315                         ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL,
316                     ADDRESS_PERMISSION_TYPE.SEND
317                 )
318             ).toEqual('Send to all');
319         });
320         it('Should return send org permission', () => {
321             expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
322                 'Organization only'
323             );
324             expect(
325                 getPermission(
326                     ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL,
327                     ADDRESS_PERMISSION_TYPE.SEND
328                 )
329             ).toEqual('Organization only');
330         });
331         it('Should return send setup incomplete', () => {
332             expect(getPermission(ADDRESS_PERMISSIONS.NO_PERMISSION, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
333                 'Setup incomplete'
334             );
335             expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
336                 'Setup incomplete'
337             );
338         });
339         it('Should default to send no permission', () => {
340             expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
341                 'No permission'
342             );
343             expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
344                 'No permission'
345             );
346             expect(
347                 getPermission(
348                     ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL,
349                     ADDRESS_PERMISSION_TYPE.SEND
350                 )
351             ).toEqual('No permission');
352         });
353     });