10 permissionsReceiveMap,
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', () => {
20 canReceive(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)
23 canReceive(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)
27 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL |
28 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG |
29 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL
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();
37 canReceive(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG)
42 describe('canSend', () => {
43 it('Should return true for any send permission', () => {
45 canSend(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)
48 canSend(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)
52 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL |
53 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG |
54 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL
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();
62 canSend(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG)
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();
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();
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);
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);
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);
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);
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
126 getReceivePermission(
127 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG
129 ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL);
131 getReceivePermission(
132 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL |
133 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG |
134 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL
136 ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL);
138 it('Should return ORG permission', () => {
139 expect(getReceivePermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG)).toEqual(
140 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG
143 getReceivePermission(
144 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL
146 ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG);
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
153 expect(getReceivePermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL)).toEqual(
154 ADDRESS_PERMISSIONS.NO_PERMISSION
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
165 getSendPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG)
166 ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL);
169 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL |
170 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG |
171 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL
173 ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL);
175 it('Should return ORG permission', () => {
176 expect(getSendPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG)).toEqual(
177 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG
181 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL
183 ).toEqual(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG);
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
190 expect(getSendPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL)).toEqual(
191 ADDRESS_PERMISSIONS.NO_PERMISSION
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
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);
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
213 expect(options).toHaveLength(1);
214 expect(options[0].text).toEqual('No permission');
215 expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
217 it('Should return setup incomplete option', () => {
218 const options = permissionsMap(
219 ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER,
220 ADDRESS_PERMISSION_TYPE.RECEIVE
222 expect(options).toHaveLength(1);
223 expect(options[0].text).toEqual('Setup incomplete');
224 expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
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);
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
239 expect(options).toHaveLength(1);
240 expect(options[0].text).toEqual('No permission');
241 expect(options[0].value).toEqual(ADDRESS_PERMISSIONS.NO_PERMISSION);
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);
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(
258 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG,
259 ADDRESS_PERMISSION_TYPE.RECEIVE
261 ).toEqual('Receive from all');
264 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL |
265 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG |
266 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL,
267 ADDRESS_PERMISSION_TYPE.RECEIVE
269 ).toEqual('Receive from all');
271 it('Should return receive org permission', () => {
272 expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG, ADDRESS_PERMISSION_TYPE.RECEIVE)).toEqual(
277 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL,
278 ADDRESS_PERMISSION_TYPE.RECEIVE
280 ).toEqual('Organization only');
282 it('Should return receive setup incomplete', () => {
283 expect(getPermission(ADDRESS_PERMISSIONS.NO_PERMISSION, ADDRESS_PERMISSION_TYPE.RECEIVE)).toEqual(
287 getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER, ADDRESS_PERMISSION_TYPE.RECEIVE)
288 ).toEqual('Setup incomplete');
290 it('Should default to receive no permission', () => {
291 expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL, ADDRESS_PERMISSION_TYPE.RECEIVE)).toEqual(
296 ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL,
297 ADDRESS_PERMISSION_TYPE.RECEIVE
299 ).toEqual('No permission');
301 it('Should return send all permission in priority', () => {
302 expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
307 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL | ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG,
308 ADDRESS_PERMISSION_TYPE.SEND
310 ).toEqual('Send to all');
313 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ALL |
314 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG |
315 ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL,
316 ADDRESS_PERMISSION_TYPE.SEND
318 ).toEqual('Send to all');
320 it('Should return send org permission', () => {
321 expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
326 ADDRESS_PERMISSIONS.PERMISSIONS_SEND_ORG | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL,
327 ADDRESS_PERMISSION_TYPE.SEND
329 ).toEqual('Organization only');
331 it('Should return send setup incomplete', () => {
332 expect(getPermission(ADDRESS_PERMISSIONS.NO_PERMISSION, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
335 expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
339 it('Should default to send no permission', () => {
340 expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
343 expect(getPermission(ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL, ADDRESS_PERMISSION_TYPE.SEND)).toEqual(
348 ADDRESS_PERMISSIONS.PERMISSIONS_AUTORESPONDER | ADDRESS_PERMISSIONS.PERMISSIONS_RECEIVE_ALL,
349 ADDRESS_PERMISSION_TYPE.SEND
351 ).toEqual('No permission');