cozy-sharing 37.0.2 → 37.2.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/OpenSharingLinkButton.js +1 -1
  3. package/dist/SharingProvider.js +315 -138
  4. package/dist/SharingProvider.spec.js +454 -240
  5. package/dist/actions/addToCozySharingLink.js +1 -1
  6. package/dist/actions/createCozySharingLink.js +1 -1
  7. package/dist/actions/shareNative.js +1 -1
  8. package/dist/actions/syncToCozySharingLink.js +1 -1
  9. package/dist/components/Avatar/AvatarList.js +1 -1
  10. package/dist/components/Recipient/GroupRecipient.js +0 -2
  11. package/dist/components/Recipient/GroupRecipientDetail.js +2 -25
  12. package/dist/components/Recipient/GroupRecipientDetailWithoutAccess.js +1 -1
  13. package/dist/components/Recipient/LinkRecipient.js +1 -1
  14. package/dist/components/Recipient/LinkRecipientLite.js +1 -1
  15. package/dist/components/Recipient/actions/revokeLink.js +1 -1
  16. package/dist/components/ShareAutosuggest.js +6 -6
  17. package/dist/components/ShareButton.js +1 -1
  18. package/dist/components/ShareByLink.js +1 -1
  19. package/dist/components/ShareLinkAccessModal/ShareLinkAccessModal.js +316 -0
  20. package/dist/components/ShareLinkAccessModal/ShareLinkAccessModal.spec.js +372 -0
  21. package/dist/components/ShareLinkAccessModal/index.js +1 -0
  22. package/dist/components/ShareRestrictionModal/BoxDate.js +1 -1
  23. package/dist/components/ShareRestrictionModal/BoxEditingRights.js +1 -1
  24. package/dist/components/ShareRestrictionModal/BoxPassword.js +1 -1
  25. package/dist/components/ShareRestrictionModal/ShareRestrictionModal.js +1 -1
  26. package/dist/components/ShareRestrictionModal/helpers.js +36 -18
  27. package/dist/components/ShareRestrictionModal/helpers.spec.js +3 -3
  28. package/dist/components/SharedBadge.js +1 -1
  29. package/dist/components/SharedDrive/SharedDriveHeader.js +1 -1
  30. package/dist/index.js +1 -0
  31. package/locales/en.json +21 -3
  32. package/locales/fr.json +22 -4
  33. package/locales/ru.json +21 -3
  34. package/locales/vi.json +21 -3
  35. package/package.json +3 -3
  36. package/src/OpenSharingLinkButton.jsx +1 -1
  37. package/src/SharingProvider.jsx +91 -27
  38. package/src/SharingProvider.spec.jsx +212 -60
  39. package/src/actions/addToCozySharingLink.js +1 -1
  40. package/src/actions/createCozySharingLink.js +1 -1
  41. package/src/actions/shareNative.js +1 -1
  42. package/src/actions/syncToCozySharingLink.js +1 -1
  43. package/src/components/Avatar/AvatarList.jsx +1 -1
  44. package/src/components/Recipient/GroupRecipient.jsx +1 -2
  45. package/src/components/Recipient/GroupRecipientDetail.jsx +3 -33
  46. package/src/components/Recipient/GroupRecipientDetailWithoutAccess.jsx +1 -1
  47. package/src/components/Recipient/LinkRecipient.jsx +1 -1
  48. package/src/components/Recipient/LinkRecipientLite.jsx +1 -1
  49. package/src/components/Recipient/actions/revokeLink.js +1 -1
  50. package/src/components/ShareAutosuggest.jsx +3 -4
  51. package/src/components/ShareButton.jsx +1 -1
  52. package/src/components/ShareByLink.jsx +1 -1
  53. package/src/components/ShareLinkAccessModal/ShareLinkAccessModal.jsx +293 -0
  54. package/src/components/ShareLinkAccessModal/ShareLinkAccessModal.spec.jsx +291 -0
  55. package/src/components/ShareLinkAccessModal/index.js +1 -0
  56. package/src/components/ShareRestrictionModal/BoxDate.jsx +1 -1
  57. package/src/components/ShareRestrictionModal/BoxEditingRights.jsx +1 -1
  58. package/src/components/ShareRestrictionModal/BoxPassword.jsx +1 -1
  59. package/src/components/ShareRestrictionModal/ShareRestrictionModal.jsx +1 -1
  60. package/src/components/ShareRestrictionModal/helpers.js +30 -6
  61. package/src/components/ShareRestrictionModal/helpers.spec.js +3 -3
  62. package/src/components/SharedBadge.jsx +2 -1
  63. package/src/components/SharedDrive/SharedDriveHeader.jsx +1 -1
  64. package/src/helpers/sharings.js +0 -1
  65. package/src/index.jsx +1 -0
@@ -1,12 +1,13 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
4
 
4
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
6
 
6
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
8
 
8
- import _regeneratorRuntime from "@babel/runtime/regenerator";
9
9
  import { act, render, screen } from '@testing-library/react';
10
+ import { endOfDay } from 'date-fns';
10
11
  import React from 'react';
11
12
  import { createMockClient } from 'cozy-client';
12
13
  import { SharingProvider } from './SharingProvider';
@@ -26,6 +27,24 @@ var AppWrapper = function AppWrapper(_ref) {
26
27
  }, children));
27
28
  };
28
29
 
30
+ var setupProvider = function setupProvider(client) {
31
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
32
+ var state = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : reducer();
33
+ var provider = new SharingProvider(_objectSpread({
34
+ client: client
35
+ }, options));
36
+ provider.state = _objectSpread(_objectSpread(_objectSpread({}, provider.state), state), {}, {
37
+ onShared: provider.state.onShared
38
+ });
39
+ provider.dispatch = jest.fn(function (action) {
40
+ var onShared = provider.state.onShared;
41
+ provider.state = _objectSpread(_objectSpread(_objectSpread({}, provider.state), reducer(provider.state, action)), {}, {
42
+ onShared: onShared
43
+ });
44
+ });
45
+ return provider;
46
+ };
47
+
29
48
  describe('allLoaded', function () {
30
49
  var client = createMockClient({});
31
50
  client.isLogged = true;
@@ -172,25 +191,19 @@ describe('shareByLink', function () {
172
191
  mockClient.collection = jest.fn().mockReturnValue({
173
192
  createSharingLink: mockCreateSharingLink
174
193
  });
175
- provider = new SharingProvider({
176
- client: mockClient
177
- });
178
- provider.state = reducer();
179
- provider.dispatch = jest.fn(function (action) {
180
- provider.state = reducer(provider.state, action);
181
- });
182
- _context3.next = 8;
194
+ provider = setupProvider(mockClient);
195
+ _context3.next = 6;
183
196
  return provider.shareByLink(driveFile, {
184
197
  verbs: ['GET']
185
198
  });
186
199
 
187
- case 8:
200
+ case 6:
188
201
  expect(provider.dispatch).toHaveBeenCalledTimes(1);
189
202
  permissions = getDocumentPermissions(provider.state, driveFile._id);
190
203
  expect(permissions).toHaveLength(1);
191
204
  expect(permissions[0].id).toBe(PERM_DRIVE_FILE.id);
192
205
 
193
- case 12:
206
+ case 10:
194
207
  case "end":
195
208
  return _context3.stop();
196
209
  }
@@ -229,34 +242,287 @@ describe('shareByLink', function () {
229
242
  mockClient.collection = jest.fn().mockReturnValue({
230
243
  createSharingLink: mockCreateSharingLink
231
244
  });
232
- provider = new SharingProvider({
233
- client: mockClient
234
- });
235
- provider.state = reducer();
245
+ provider = setupProvider(mockClient);
236
246
  provider.permissionCol = {
237
247
  createSharingLink: mockCreateSharingLink
238
248
  };
239
- provider.dispatch = jest.fn(function (action) {
240
- provider.state = reducer(provider.state, action);
241
- });
242
- _context4.next = 11;
249
+ _context4.next = 9;
243
250
  return provider.shareByLink(regularFile, {
244
251
  verbs: ['GET']
245
252
  });
246
253
 
247
- case 11:
254
+ case 9:
248
255
  expect(provider.dispatch).toHaveBeenCalledTimes(1);
249
256
  permissions = getDocumentPermissions(provider.state, regularFile._id);
250
257
  expect(permissions).toHaveLength(1);
251
258
  expect(permissions[0].id).toBe(PERM_REGULAR_FILE.id);
252
259
 
253
- case 15:
260
+ case 13:
254
261
  case "end":
255
262
  return _context4.stop();
256
263
  }
257
264
  }, _callee4);
258
265
  })));
259
266
  });
267
+ describe('ensureSharingLink', function () {
268
+ var permission = {
269
+ id: 'permission-id',
270
+ attributes: {
271
+ permissions: {
272
+ rule0: {
273
+ verbs: ['GET'],
274
+ values: ['file-id']
275
+ }
276
+ },
277
+ shortcodes: {
278
+ code: 'share-code'
279
+ }
280
+ }
281
+ };
282
+ var document = {
283
+ _id: 'file-id',
284
+ name: 'invoice.pdf'
285
+ };
286
+ var linkAccess = {
287
+ editingRights: 'write',
288
+ dateEnabled: false,
289
+ selectedDate: null,
290
+ passwordEnabled: false,
291
+ password: ''
292
+ };
293
+ it('fetches regular links with the regular permission API', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
294
+ var client, provider, unrelatedPermission, findLinksByDoctype, findLinksByIds;
295
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
296
+ while (1) switch (_context5.prev = _context5.next) {
297
+ case 0:
298
+ client = createMockClient({});
299
+
300
+ client.getStackClient = function () {
301
+ return {
302
+ uri: 'https://cozy.example'
303
+ };
304
+ };
305
+
306
+ client.collection = jest.fn().mockReturnValue({});
307
+ client.capabilities = {
308
+ flat_subdomains: true
309
+ };
310
+ provider = setupProvider(client, {
311
+ doctype: 'io.cozy.files',
312
+ documentType: 'Files'
313
+ });
314
+ unrelatedPermission = _objectSpread(_objectSpread({}, permission), {}, {
315
+ id: 'unrelated-permission-id',
316
+ attributes: _objectSpread(_objectSpread({}, permission.attributes), {}, {
317
+ permissions: {
318
+ rule0: _objectSpread(_objectSpread({}, permission.attributes.permissions.rule0), {}, {
319
+ values: ['other']
320
+ })
321
+ }
322
+ })
323
+ });
324
+ findLinksByDoctype = jest.fn().mockResolvedValue({
325
+ data: [permission, unrelatedPermission]
326
+ });
327
+ findLinksByIds = jest.fn(function () {
328
+ throw new Error('findLinksByIds is only supported for shared drives');
329
+ });
330
+ provider.permissionCol = {
331
+ findLinksByDoctype: findLinksByDoctype,
332
+ findLinksByIds: findLinksByIds
333
+ };
334
+ provider.updateDocumentPermissions = jest.fn().mockResolvedValue([{
335
+ data: permission
336
+ }]);
337
+ _context5.next = 12;
338
+ return provider.ensureSharingLink(document, linkAccess);
339
+
340
+ case 12:
341
+ expect(findLinksByDoctype).toHaveBeenCalledWith('io.cozy.files');
342
+ expect(findLinksByIds).not.toHaveBeenCalled();
343
+ expect(provider.updateDocumentPermissions).toHaveBeenCalledWith(_objectSpread(_objectSpread({}, document), {}, {
344
+ id: 'file-id'
345
+ }), expect.any(Object), [permission]);
346
+
347
+ case 15:
348
+ case "end":
349
+ return _context5.stop();
350
+ }
351
+ }, _callee5);
352
+ })));
353
+ it('updates an existing link and returns its public URL', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
354
+ var client, provider, result;
355
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
356
+ while (1) switch (_context6.prev = _context6.next) {
357
+ case 0:
358
+ client = createMockClient({});
359
+
360
+ client.getStackClient = function () {
361
+ return {
362
+ uri: 'https://cozy.example'
363
+ };
364
+ };
365
+
366
+ client.collection = jest.fn().mockReturnValue({});
367
+ client.capabilities = {
368
+ flat_subdomains: true
369
+ };
370
+ provider = setupProvider(client, {
371
+ documentType: 'Files'
372
+ });
373
+ provider.fetchSharingLinks = jest.fn().mockResolvedValue([permission]);
374
+ provider.updateDocumentPermissions = jest.fn().mockResolvedValue([{
375
+ data: permission
376
+ }]);
377
+ _context6.next = 9;
378
+ return provider.ensureSharingLink(document, linkAccess);
379
+
380
+ case 9:
381
+ result = _context6.sent;
382
+ expect(provider.updateDocumentPermissions).toHaveBeenCalledWith(_objectSpread(_objectSpread({}, document), {}, {
383
+ id: 'file-id'
384
+ }), {
385
+ verbs: ['GET', 'POST', 'PUT', 'PATCH'],
386
+ expiresAt: '',
387
+ password: ''
388
+ }, [permission]);
389
+ expect(result.documentId).toBe('file-id');
390
+ expect(result.url).toContain('sharecode=share-code');
391
+
392
+ case 13:
393
+ case "end":
394
+ return _context6.stop();
395
+ }
396
+ }, _callee6);
397
+ })));
398
+ it('creates a link when no existing permission is found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
399
+ var client, provider;
400
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
401
+ while (1) switch (_context7.prev = _context7.next) {
402
+ case 0:
403
+ client = createMockClient({});
404
+
405
+ client.getStackClient = function () {
406
+ return {
407
+ uri: 'https://cozy.example'
408
+ };
409
+ };
410
+
411
+ client.collection = jest.fn().mockReturnValue({});
412
+ client.capabilities = {
413
+ flat_subdomains: true
414
+ };
415
+ provider = setupProvider(client, {
416
+ documentType: 'Files'
417
+ });
418
+ provider.fetchSharingLinks = jest.fn().mockResolvedValue([]);
419
+ provider.shareByLink = jest.fn().mockResolvedValue({
420
+ data: permission
421
+ });
422
+ _context7.next = 9;
423
+ return provider.ensureSharingLink(document, linkAccess);
424
+
425
+ case 9:
426
+ expect(provider.shareByLink).toHaveBeenCalledWith(document, expect.objectContaining({
427
+ verbs: ['GET', 'POST', 'PUT', 'PATCH']
428
+ }));
429
+
430
+ case 10:
431
+ case "end":
432
+ return _context7.stop();
433
+ }
434
+ }, _callee7);
435
+ })));
436
+ it('sends the selected expiry and password when updating a link', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
437
+ var client, provider, selectedDate;
438
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
439
+ while (1) switch (_context8.prev = _context8.next) {
440
+ case 0:
441
+ client = createMockClient({});
442
+
443
+ client.getStackClient = function () {
444
+ return {
445
+ uri: 'https://cozy.example'
446
+ };
447
+ };
448
+
449
+ client.collection = jest.fn().mockReturnValue({});
450
+ client.capabilities = {
451
+ flat_subdomains: true
452
+ };
453
+ provider = setupProvider(client, {
454
+ documentType: 'Files'
455
+ });
456
+ selectedDate = new Date('2100-01-01T12:00:00.000Z');
457
+ provider.fetchSharingLinks = jest.fn().mockResolvedValue([permission]);
458
+ provider.updateDocumentPermissions = jest.fn().mockResolvedValue([{
459
+ data: permission
460
+ }]);
461
+ _context8.next = 10;
462
+ return provider.ensureSharingLink(document, {
463
+ editingRights: 'readOnly',
464
+ dateEnabled: true,
465
+ selectedDate: selectedDate,
466
+ passwordEnabled: true,
467
+ password: 'secret'
468
+ });
469
+
470
+ case 10:
471
+ expect(provider.updateDocumentPermissions).toHaveBeenCalledWith(_objectSpread(_objectSpread({}, document), {}, {
472
+ id: 'file-id'
473
+ }), {
474
+ verbs: ['GET'],
475
+ expiresAt: endOfDay(selectedDate).toISOString(),
476
+ password: 'secret'
477
+ }, [permission]);
478
+
479
+ case 11:
480
+ case "end":
481
+ return _context8.stop();
482
+ }
483
+ }, _callee8);
484
+ })));
485
+ it('updates permissions discovered outside the current store state', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
486
+ var client, provider, updatePermission;
487
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
488
+ while (1) switch (_context9.prev = _context9.next) {
489
+ case 0:
490
+ client = createMockClient({});
491
+
492
+ client.getStackClient = function () {
493
+ return {
494
+ uri: 'https://cozy.example'
495
+ };
496
+ };
497
+
498
+ client.collection = jest.fn().mockReturnValue({});
499
+ client.capabilities = {
500
+ flat_subdomains: true
501
+ };
502
+ provider = setupProvider(client, {
503
+ documentType: 'Files'
504
+ });
505
+ updatePermission = jest.fn().mockResolvedValue({
506
+ data: permission
507
+ });
508
+ provider.permissionCol = {
509
+ add: updatePermission
510
+ };
511
+ provider.fetchSharingLinks = jest.fn().mockResolvedValue([permission]);
512
+ provider.dispatch = jest.fn();
513
+ _context9.next = 11;
514
+ return provider.ensureSharingLink(document, linkAccess);
515
+
516
+ case 11:
517
+ expect(updatePermission).toHaveBeenCalledTimes(1);
518
+
519
+ case 12:
520
+ case "end":
521
+ return _context9.stop();
522
+ }
523
+ }, _callee9);
524
+ })));
525
+ });
260
526
  describe('revokeSharingLink', function () {
261
527
  var PERM = {
262
528
  type: 'io.cozy.permissions',
@@ -287,18 +553,12 @@ describe('revokeSharingLink', function () {
287
553
  mockClient.collection = jest.fn().mockReturnValue({
288
554
  destroy: mockDestroy
289
555
  });
290
- provider = new SharingProvider({
291
- client: mockClient
292
- });
293
- provider.state = reducer(undefined, addSharingLink(PERM));
294
- provider.dispatch = jest.fn(function (action) {
295
- provider.state = reducer(provider.state, action);
296
- });
556
+ provider = setupProvider(mockClient, {}, reducer(undefined, addSharingLink(PERM)));
297
557
  });
298
- it('uses permissionCol.destroy for a regular file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
558
+ it('uses permissionCol.destroy for a regular file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
299
559
  var regularFile;
300
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
301
- while (1) switch (_context5.prev = _context5.next) {
560
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
561
+ while (1) switch (_context10.prev = _context10.next) {
302
562
  case 0:
303
563
  regularFile = {
304
564
  _id: 'file_id',
@@ -307,7 +567,7 @@ describe('revokeSharingLink', function () {
307
567
  provider.permissionCol = {
308
568
  destroy: mockDestroy
309
569
  };
310
- _context5.next = 4;
570
+ _context10.next = 4;
311
571
  return provider.revokeSharingLink(regularFile);
312
572
 
313
573
  case 4:
@@ -317,14 +577,14 @@ describe('revokeSharingLink', function () {
317
577
 
318
578
  case 7:
319
579
  case "end":
320
- return _context5.stop();
580
+ return _context10.stop();
321
581
  }
322
- }, _callee5);
582
+ }, _callee10);
323
583
  })));
324
- it('uses drivePermissionCollection.destroy for a shared drive file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
584
+ it('uses drivePermissionCollection.destroy for a shared drive file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
325
585
  var driveFile, mockDriveCollection;
326
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
327
- while (1) switch (_context6.prev = _context6.next) {
586
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
587
+ while (1) switch (_context11.prev = _context11.next) {
328
588
  case 0:
329
589
  driveFile = {
330
590
  _id: 'file_id',
@@ -335,7 +595,7 @@ describe('revokeSharingLink', function () {
335
595
  destroy: mockDestroy
336
596
  };
337
597
  provider.props.client.collection = jest.fn().mockReturnValue(mockDriveCollection);
338
- _context6.next = 5;
598
+ _context11.next = 5;
339
599
  return provider.revokeSharingLink(driveFile);
340
600
 
341
601
  case 5:
@@ -348,9 +608,9 @@ describe('revokeSharingLink', function () {
348
608
 
349
609
  case 9:
350
610
  case "end":
351
- return _context6.stop();
611
+ return _context11.stop();
352
612
  }
353
- }, _callee6);
613
+ }, _callee11);
354
614
  })));
355
615
  });
356
616
  describe('updateDocumentPermissions', function () {
@@ -371,10 +631,10 @@ describe('updateDocumentPermissions', function () {
371
631
  }
372
632
  }
373
633
  };
374
- it('sends only one PATCH request for a shared drive file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
634
+ it('sends only one PATCH request for a shared drive file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
375
635
  var driveFile, mockAdd, mockClient, provider;
376
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
377
- while (1) switch (_context7.prev = _context7.next) {
636
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
637
+ while (1) switch (_context12.prev = _context12.next) {
378
638
  case 0:
379
639
  driveFile = {
380
640
  _id: 'file_in_drive',
@@ -387,28 +647,25 @@ describe('updateDocumentPermissions', function () {
387
647
  mockClient = createMockClient({});
388
648
  mockClient.collection = jest.fn().mockReturnValue({
389
649
  add: mockAdd
390
- });
391
- provider = new SharingProvider({
392
- client: mockClient
393
650
  }); // Seed the state with exactly one permission (as it would be after a correct shareByLink)
394
651
 
395
- provider.state = reducer(undefined, addSharingLink(PERM_DRIVE_FILE));
652
+ provider = setupProvider(mockClient, {}, reducer(undefined, addSharingLink(PERM_DRIVE_FILE)));
396
653
  provider.dispatch = jest.fn();
397
- _context7.next = 9;
654
+ _context12.next = 8;
398
655
  return provider.updateDocumentPermissions(driveFile, {
399
656
  verbs: ['GET'],
400
657
  expiresAt: '',
401
658
  password: ''
402
659
  });
403
660
 
404
- case 9:
661
+ case 8:
405
662
  expect(mockAdd).toHaveBeenCalledTimes(1);
406
663
 
407
- case 10:
664
+ case 9:
408
665
  case "end":
409
- return _context7.stop();
666
+ return _context12.stop();
410
667
  }
411
- }, _callee7);
668
+ }, _callee12);
412
669
  })));
413
670
  });
414
671
  describe('shared drive recipient revocation', function () {
@@ -468,15 +725,9 @@ describe('shared drive recipient revocation', function () {
468
725
  };
469
726
 
470
727
  mockClient.collection = jest.fn().mockReturnValue({});
471
- provider = new SharingProvider({
472
- client: mockClient
473
- });
474
- provider.state = _objectSpread(_objectSpread({}, provider.state), reducer(undefined, receiveSharings({
728
+ provider = setupProvider(mockClient, {}, reducer(undefined, receiveSharings({
475
729
  sharings: [SHARED_DRIVE]
476
730
  })));
477
- provider.dispatch = jest.fn(function (action) {
478
- provider.state = _objectSpread(_objectSpread({}, provider.state), reducer(provider.state, action));
479
- });
480
731
  sharingCol = {
481
732
  addRecipients: jest.fn(),
482
733
  create: jest.fn().mockResolvedValue({
@@ -486,11 +737,11 @@ describe('shared drive recipient revocation', function () {
486
737
  };
487
738
  provider.sharingCol = sharingCol;
488
739
  });
489
- it('forgets the shared drive when revoking its last recipient', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
490
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
491
- while (1) switch (_context8.prev = _context8.next) {
740
+ it('forgets the shared drive when revoking its last recipient', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
741
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
742
+ while (1) switch (_context13.prev = _context13.next) {
492
743
  case 0:
493
- _context8.next = 2;
744
+ _context13.next = 2;
494
745
  return provider.revoke(document, SHARED_DRIVE.id, 1);
495
746
 
496
747
  case 2:
@@ -499,19 +750,19 @@ describe('shared drive recipient revocation', function () {
499
750
 
500
751
  case 4:
501
752
  case "end":
502
- return _context8.stop();
753
+ return _context13.stop();
503
754
  }
504
- }, _callee8);
755
+ }, _callee13);
505
756
  })));
506
- it('creates a new sharing when re-adding after the last recipient was revoked', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
507
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
508
- while (1) switch (_context9.prev = _context9.next) {
757
+ it('creates a new sharing when re-adding after the last recipient was revoked', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
758
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
759
+ while (1) switch (_context14.prev = _context14.next) {
509
760
  case 0:
510
- _context9.next = 2;
761
+ _context14.next = 2;
511
762
  return provider.revoke(document, SHARED_DRIVE.id, 1);
512
763
 
513
764
  case 2:
514
- _context9.next = 4;
765
+ _context14.next = 4;
515
766
  return provider.share({
516
767
  document: document,
517
768
  recipients: [recipient],
@@ -535,9 +786,9 @@ describe('shared drive recipient revocation', function () {
535
786
 
536
787
  case 6:
537
788
  case "end":
538
- return _context9.stop();
789
+ return _context14.stop();
539
790
  }
540
- }, _callee9);
791
+ }, _callee14);
541
792
  })));
542
793
  });
543
794
  describe('fetchSharedDriveSharingLinks', function () {
@@ -563,10 +814,10 @@ describe('fetchSharedDriveSharingLinks', function () {
563
814
  id: 'file_in_drive',
564
815
  driveId: 'drive_123'
565
816
  };
566
- it('fetches shared drive sharing links by file id', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
817
+ it('fetches shared drive sharing links by file id', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
567
818
  var mockFindLinksByIds, mockClient, provider, result, permissions;
568
- return _regeneratorRuntime.wrap(function _callee10$(_context10) {
569
- while (1) switch (_context10.prev = _context10.next) {
819
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
820
+ while (1) switch (_context15.prev = _context15.next) {
570
821
  case 0:
571
822
  mockFindLinksByIds = jest.fn().mockResolvedValue({
572
823
  data: [PERM_DRIVE_FILE]
@@ -575,18 +826,12 @@ describe('fetchSharedDriveSharingLinks', function () {
575
826
  mockClient.collection = jest.fn().mockReturnValue({
576
827
  findLinksByIds: mockFindLinksByIds
577
828
  });
578
- provider = new SharingProvider({
579
- client: mockClient
580
- });
581
- provider.state = reducer();
582
- provider.dispatch = jest.fn(function (action) {
583
- provider.state = reducer(provider.state, action);
584
- });
585
- _context10.next = 8;
829
+ provider = setupProvider(mockClient);
830
+ _context15.next = 6;
586
831
  return provider.fetchSharedDriveSharingLinks(driveFile);
587
832
 
588
- case 8:
589
- result = _context10.sent;
833
+ case 6:
834
+ result = _context15.sent;
590
835
  expect(mockClient.collection).toHaveBeenCalledWith('io.cozy.permissions', {
591
836
  driveId: 'drive_123'
592
837
  });
@@ -597,47 +842,45 @@ describe('fetchSharedDriveSharingLinks', function () {
597
842
  expect(permissions[0].id).toBe(PERM_DRIVE_FILE.id);
598
843
  expect(result).toEqual([PERM_DRIVE_FILE]);
599
844
 
600
- case 16:
845
+ case 14:
601
846
  case "end":
602
- return _context10.stop();
847
+ return _context15.stop();
603
848
  }
604
- }, _callee10);
849
+ }, _callee15);
605
850
  })));
606
- it('returns an empty array and skips the API call for non-shared-drive documents', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
851
+ it('returns an empty array and skips the API call for non-shared-drive documents', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
607
852
  var mockClient, findLinksByIds, provider, result;
608
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
609
- while (1) switch (_context11.prev = _context11.next) {
853
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
854
+ while (1) switch (_context16.prev = _context16.next) {
610
855
  case 0:
611
856
  mockClient = createMockClient({});
612
857
  findLinksByIds = jest.fn();
613
858
  mockClient.collection = jest.fn().mockReturnValue({
614
859
  findLinksByIds: findLinksByIds
615
860
  });
616
- provider = new SharingProvider({
617
- client: mockClient
618
- });
861
+ provider = setupProvider(mockClient);
619
862
  provider.dispatch = jest.fn();
620
- _context11.next = 7;
863
+ _context16.next = 7;
621
864
  return provider.fetchSharedDriveSharingLinks({
622
865
  _id: 'regular_file'
623
866
  });
624
867
 
625
868
  case 7:
626
- result = _context11.sent;
869
+ result = _context16.sent;
627
870
  expect(result).toEqual([]);
628
871
  expect(findLinksByIds).not.toHaveBeenCalled();
629
872
  expect(provider.dispatch).not.toHaveBeenCalled();
630
873
 
631
874
  case 11:
632
875
  case "end":
633
- return _context11.stop();
876
+ return _context16.stop();
634
877
  }
635
- }, _callee11);
878
+ }, _callee16);
636
879
  })));
637
- it('uses document.id as a fallback when _id is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
880
+ it('uses document.id as a fallback when _id is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17() {
638
881
  var mockFindLinksByIds, mockClient, provider;
639
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
640
- while (1) switch (_context12.prev = _context12.next) {
882
+ return _regeneratorRuntime.wrap(function _callee17$(_context17) {
883
+ while (1) switch (_context17.prev = _context17.next) {
641
884
  case 0:
642
885
  mockFindLinksByIds = jest.fn().mockResolvedValue({
643
886
  data: [PERM_DRIVE_FILE]
@@ -646,32 +889,26 @@ describe('fetchSharedDriveSharingLinks', function () {
646
889
  mockClient.collection = jest.fn().mockReturnValue({
647
890
  findLinksByIds: mockFindLinksByIds
648
891
  });
649
- provider = new SharingProvider({
650
- client: mockClient
651
- });
652
- provider.state = reducer();
653
- provider.dispatch = jest.fn(function (action) {
654
- provider.state = reducer(provider.state, action);
655
- });
656
- _context12.next = 8;
892
+ provider = setupProvider(mockClient);
893
+ _context17.next = 6;
657
894
  return provider.fetchSharedDriveSharingLinks({
658
895
  id: 'file_in_drive',
659
896
  driveId: 'drive_123'
660
897
  });
661
898
 
662
- case 8:
899
+ case 6:
663
900
  expect(mockFindLinksByIds).toHaveBeenCalledWith(['file_in_drive']);
664
901
 
665
- case 9:
902
+ case 7:
666
903
  case "end":
667
- return _context12.stop();
904
+ return _context17.stop();
668
905
  }
669
- }, _callee12);
906
+ }, _callee17);
670
907
  })));
671
- it('does not dispatch when the response has no data', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
908
+ it('does not dispatch when the response has no data', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
672
909
  var mockFindLinksByIds, mockClient, provider, result;
673
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
674
- while (1) switch (_context13.prev = _context13.next) {
910
+ return _regeneratorRuntime.wrap(function _callee18$(_context18) {
911
+ while (1) switch (_context18.prev = _context18.next) {
675
912
  case 0:
676
913
  mockFindLinksByIds = jest.fn().mockResolvedValue({
677
914
  data: []
@@ -680,23 +917,21 @@ describe('fetchSharedDriveSharingLinks', function () {
680
917
  mockClient.collection = jest.fn().mockReturnValue({
681
918
  findLinksByIds: mockFindLinksByIds
682
919
  });
683
- provider = new SharingProvider({
684
- client: mockClient
685
- });
920
+ provider = setupProvider(mockClient);
686
921
  provider.dispatch = jest.fn();
687
- _context13.next = 7;
922
+ _context18.next = 7;
688
923
  return provider.fetchSharedDriveSharingLinks(driveFile);
689
924
 
690
925
  case 7:
691
- result = _context13.sent;
926
+ result = _context18.sent;
692
927
  expect(result).toEqual([]);
693
928
  expect(provider.dispatch).not.toHaveBeenCalled();
694
929
 
695
930
  case 10:
696
931
  case "end":
697
- return _context13.stop();
932
+ return _context18.stop();
698
933
  }
699
- }, _callee13);
934
+ }, _callee18);
700
935
  })));
701
936
  });
702
937
  describe('shareByLink shared drive 409 recovery', function () {
@@ -722,10 +957,10 @@ describe('shareByLink shared drive 409 recovery', function () {
722
957
  id: 'file_in_drive',
723
958
  driveId: 'drive_123'
724
959
  };
725
- it('falls back to fetching existing links when create returns 409', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
960
+ it('falls back to fetching existing links when create returns 409', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19() {
726
961
  var conflict, mockCreateSharingLink, mockFindLinksByIds, mockClient, provider, resp;
727
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
728
- while (1) switch (_context14.prev = _context14.next) {
962
+ return _regeneratorRuntime.wrap(function _callee19$(_context19) {
963
+ while (1) switch (_context19.prev = _context19.next) {
729
964
  case 0:
730
965
  conflict = Object.assign(new Error('Conflict'), {
731
966
  status: 409
@@ -739,34 +974,28 @@ describe('shareByLink shared drive 409 recovery', function () {
739
974
  createSharingLink: mockCreateSharingLink,
740
975
  findLinksByIds: mockFindLinksByIds
741
976
  });
742
- provider = new SharingProvider({
743
- client: mockClient
744
- });
745
- provider.state = reducer();
746
- provider.dispatch = jest.fn(function (action) {
747
- provider.state = reducer(provider.state, action);
748
- });
749
- _context14.next = 10;
977
+ provider = setupProvider(mockClient);
978
+ _context19.next = 8;
750
979
  return provider.shareByLink(driveFile, {
751
980
  verbs: ['GET']
752
981
  });
753
982
 
754
- case 10:
755
- resp = _context14.sent;
983
+ case 8:
984
+ resp = _context19.sent;
756
985
  expect(mockCreateSharingLink).toHaveBeenCalled();
757
986
  expect(mockFindLinksByIds).toHaveBeenCalledWith(['file_in_drive']);
758
987
  expect(resp.data.id).toBe(PERM_DRIVE_FILE.id);
759
988
 
760
- case 14:
989
+ case 12:
761
990
  case "end":
762
- return _context14.stop();
991
+ return _context19.stop();
763
992
  }
764
- }, _callee14);
993
+ }, _callee19);
765
994
  })));
766
- it('does not duplicate existing links when 409 recovery refetches them', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
995
+ it('does not duplicate existing links when 409 recovery refetches them', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20() {
767
996
  var conflict, mockCreateSharingLink, mockFindLinksByIds, mockClient, provider, resp, permissions;
768
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
769
- while (1) switch (_context15.prev = _context15.next) {
997
+ return _regeneratorRuntime.wrap(function _callee20$(_context20) {
998
+ while (1) switch (_context20.prev = _context20.next) {
770
999
  case 0:
771
1000
  conflict = Object.assign(new Error('Conflict'), {
772
1001
  status: 409
@@ -780,35 +1009,29 @@ describe('shareByLink shared drive 409 recovery', function () {
780
1009
  createSharingLink: mockCreateSharingLink,
781
1010
  findLinksByIds: mockFindLinksByIds
782
1011
  });
783
- provider = new SharingProvider({
784
- client: mockClient
785
- });
786
- provider.state = reducer(undefined, addSharingLink(PERM_DRIVE_FILE));
787
- provider.dispatch = jest.fn(function (action) {
788
- provider.state = reducer(provider.state, action);
789
- });
790
- _context15.next = 10;
1012
+ provider = setupProvider(mockClient, {}, reducer(undefined, addSharingLink(PERM_DRIVE_FILE)));
1013
+ _context20.next = 8;
791
1014
  return provider.shareByLink(driveFile, {
792
1015
  verbs: ['GET']
793
1016
  });
794
1017
 
795
- case 10:
796
- resp = _context15.sent;
1018
+ case 8:
1019
+ resp = _context20.sent;
797
1020
  permissions = getDocumentPermissions(provider.state, 'file_in_drive');
798
1021
  expect(resp.data.id).toBe(PERM_DRIVE_FILE.id);
799
1022
  expect(provider.dispatch).not.toHaveBeenCalled();
800
1023
  expect(permissions).toHaveLength(1);
801
1024
 
802
- case 15:
1025
+ case 13:
803
1026
  case "end":
804
- return _context15.stop();
1027
+ return _context20.stop();
805
1028
  }
806
- }, _callee15);
1029
+ }, _callee20);
807
1030
  })));
808
- it('rethrows the original error when 409 happens and no link is found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
1031
+ it('rethrows the original error when 409 happens and no link is found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() {
809
1032
  var conflict, mockCreateSharingLink, mockFindLinksByIds, mockClient, provider;
810
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
811
- while (1) switch (_context16.prev = _context16.next) {
1033
+ return _regeneratorRuntime.wrap(function _callee21$(_context21) {
1034
+ while (1) switch (_context21.prev = _context21.next) {
812
1035
  case 0:
813
1036
  conflict = Object.assign(new Error('Conflict'), {
814
1037
  status: 409
@@ -822,21 +1045,18 @@ describe('shareByLink shared drive 409 recovery', function () {
822
1045
  createSharingLink: mockCreateSharingLink,
823
1046
  findLinksByIds: mockFindLinksByIds
824
1047
  });
825
- provider = new SharingProvider({
826
- client: mockClient
827
- });
828
- provider.state = reducer();
1048
+ provider = setupProvider(mockClient);
829
1049
  provider.dispatch = jest.fn();
830
- _context16.next = 10;
1050
+ _context21.next = 9;
831
1051
  return expect(provider.shareByLink(driveFile, {
832
1052
  verbs: ['GET']
833
1053
  })).rejects.toBe(conflict);
834
1054
 
835
- case 10:
1055
+ case 9:
836
1056
  case "end":
837
- return _context16.stop();
1057
+ return _context21.stop();
838
1058
  }
839
- }, _callee16);
1059
+ }, _callee21);
840
1060
  })));
841
1061
  });
842
1062
  describe('updateSharingMemberType', function () {
@@ -863,51 +1083,45 @@ describe('updateSharingMemberType', function () {
863
1083
  },
864
1084
  collection: jest.fn().mockReturnValue({})
865
1085
  };
866
- instance = new SharingProvider({
867
- client: mockClient
868
- });
869
- instance.state = _objectSpread(_objectSpread({}, instance.state), {}, {
1086
+ instance = setupProvider(mockClient, {}, _objectSpread(_objectSpread({}, reducer()), {}, {
870
1087
  sharings: [mockSharing]
871
- });
1088
+ }));
872
1089
  instance.sharingCol = {
873
1090
  setReadOnly: jest.fn().mockResolvedValue({}),
874
1091
  setReadWrite: jest.fn().mockResolvedValue({})
875
1092
  };
876
- instance.dispatch = jest.fn(function (action) {
877
- instance.state = _objectSpread(_objectSpread({}, instance.state), reducer(instance.state, action));
878
- });
879
1093
  });
880
- it('should throw when sharing is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17() {
881
- return _regeneratorRuntime.wrap(function _callee17$(_context17) {
882
- while (1) switch (_context17.prev = _context17.next) {
1094
+ it('should throw when sharing is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22() {
1095
+ return _regeneratorRuntime.wrap(function _callee22$(_context22) {
1096
+ while (1) switch (_context22.prev = _context22.next) {
883
1097
  case 0:
884
- _context17.next = 2;
1098
+ _context22.next = 2;
885
1099
  return expect(instance.updateSharingMemberType('unknown-id', 1, 'one-way')).rejects.toThrow('Sharing not found');
886
1100
 
887
1101
  case 2:
888
1102
  case "end":
889
- return _context17.stop();
1103
+ return _context22.stop();
890
1104
  }
891
- }, _callee17);
1105
+ }, _callee22);
892
1106
  })));
893
- it('should throw when member is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
894
- return _regeneratorRuntime.wrap(function _callee18$(_context18) {
895
- while (1) switch (_context18.prev = _context18.next) {
1107
+ it('should throw when member is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23() {
1108
+ return _regeneratorRuntime.wrap(function _callee23$(_context23) {
1109
+ while (1) switch (_context23.prev = _context23.next) {
896
1110
  case 0:
897
- _context18.next = 2;
1111
+ _context23.next = 2;
898
1112
  return expect(instance.updateSharingMemberType('sharing-123', 99, 'one-way')).rejects.toThrow('Member not found');
899
1113
 
900
1114
  case 2:
901
1115
  case "end":
902
- return _context18.stop();
1116
+ return _context23.stop();
903
1117
  }
904
- }, _callee18);
1118
+ }, _callee23);
905
1119
  })));
906
- it('should call setReadOnly when switching to one-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19() {
907
- return _regeneratorRuntime.wrap(function _callee19$(_context19) {
908
- while (1) switch (_context19.prev = _context19.next) {
1120
+ it('should call setReadOnly when switching to one-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24() {
1121
+ return _regeneratorRuntime.wrap(function _callee24$(_context24) {
1122
+ while (1) switch (_context24.prev = _context24.next) {
909
1123
  case 0:
910
- _context19.next = 2;
1124
+ _context24.next = 2;
911
1125
  return instance.updateSharingMemberType('sharing-123', 1, 'one-way');
912
1126
 
913
1127
  case 2:
@@ -916,15 +1130,15 @@ describe('updateSharingMemberType', function () {
916
1130
 
917
1131
  case 4:
918
1132
  case "end":
919
- return _context19.stop();
1133
+ return _context24.stop();
920
1134
  }
921
- }, _callee19);
1135
+ }, _callee24);
922
1136
  })));
923
- it('should call setReadWrite when switching to two-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20() {
924
- return _regeneratorRuntime.wrap(function _callee20$(_context20) {
925
- while (1) switch (_context20.prev = _context20.next) {
1137
+ it('should call setReadWrite when switching to two-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25() {
1138
+ return _regeneratorRuntime.wrap(function _callee25$(_context25) {
1139
+ while (1) switch (_context25.prev = _context25.next) {
926
1140
  case 0:
927
- _context20.next = 2;
1141
+ _context25.next = 2;
928
1142
  return instance.updateSharingMemberType('sharing-123', 1, 'two-way');
929
1143
 
930
1144
  case 2:
@@ -933,15 +1147,15 @@ describe('updateSharingMemberType', function () {
933
1147
 
934
1148
  case 4:
935
1149
  case "end":
936
- return _context20.stop();
1150
+ return _context25.stop();
937
1151
  }
938
- }, _callee20);
1152
+ }, _callee25);
939
1153
  })));
940
- it('should optimistically dispatch a state update when switching to one-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() {
941
- return _regeneratorRuntime.wrap(function _callee21$(_context21) {
942
- while (1) switch (_context21.prev = _context21.next) {
1154
+ it('should optimistically dispatch a state update when switching to one-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26() {
1155
+ return _regeneratorRuntime.wrap(function _callee26$(_context26) {
1156
+ while (1) switch (_context26.prev = _context26.next) {
943
1157
  case 0:
944
- _context21.next = 2;
1158
+ _context26.next = 2;
945
1159
  return instance.updateSharingMemberType('sharing-123', 1, 'one-way');
946
1160
 
947
1161
  case 2:
@@ -958,15 +1172,15 @@ describe('updateSharingMemberType', function () {
958
1172
 
959
1173
  case 3:
960
1174
  case "end":
961
- return _context21.stop();
1175
+ return _context26.stop();
962
1176
  }
963
- }, _callee21);
1177
+ }, _callee26);
964
1178
  })));
965
- it('should optimistically dispatch a state update when switching to two-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22() {
966
- return _regeneratorRuntime.wrap(function _callee22$(_context22) {
967
- while (1) switch (_context22.prev = _context22.next) {
1179
+ it('should optimistically dispatch a state update when switching to two-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee27() {
1180
+ return _regeneratorRuntime.wrap(function _callee27$(_context27) {
1181
+ while (1) switch (_context27.prev = _context27.next) {
968
1182
  case 0:
969
- _context22.next = 2;
1183
+ _context27.next = 2;
970
1184
  return instance.updateSharingMemberType('sharing-123', 1, 'two-way');
971
1185
 
972
1186
  case 2:
@@ -983,44 +1197,44 @@ describe('updateSharingMemberType', function () {
983
1197
 
984
1198
  case 3:
985
1199
  case "end":
986
- return _context22.stop();
1200
+ return _context27.stop();
987
1201
  }
988
- }, _callee22);
1202
+ }, _callee27);
989
1203
  })));
990
- it('should rethrow error if setReadOnly fails', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23() {
991
- return _regeneratorRuntime.wrap(function _callee23$(_context23) {
992
- while (1) switch (_context23.prev = _context23.next) {
1204
+ it('should rethrow error if setReadOnly fails', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee28() {
1205
+ return _regeneratorRuntime.wrap(function _callee28$(_context28) {
1206
+ while (1) switch (_context28.prev = _context28.next) {
993
1207
  case 0:
994
1208
  instance.sharingCol.setReadOnly.mockRejectedValue(new Error('Network error'));
995
- _context23.next = 3;
1209
+ _context28.next = 3;
996
1210
  return expect(instance.updateSharingMemberType('sharing-123', 1, 'one-way')).rejects.toThrow('Network error');
997
1211
 
998
1212
  case 3:
999
1213
  case "end":
1000
- return _context23.stop();
1214
+ return _context28.stop();
1001
1215
  }
1002
- }, _callee23);
1216
+ }, _callee28);
1003
1217
  })));
1004
- it('should rethrow error if setReadWrite fails', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24() {
1005
- return _regeneratorRuntime.wrap(function _callee24$(_context24) {
1006
- while (1) switch (_context24.prev = _context24.next) {
1218
+ it('should rethrow error if setReadWrite fails', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee29() {
1219
+ return _regeneratorRuntime.wrap(function _callee29$(_context29) {
1220
+ while (1) switch (_context29.prev = _context29.next) {
1007
1221
  case 0:
1008
1222
  instance.sharingCol.setReadWrite.mockRejectedValue(new Error('Network error'));
1009
- _context24.next = 3;
1223
+ _context29.next = 3;
1010
1224
  return expect(instance.updateSharingMemberType('sharing-123', 1, 'two-way')).rejects.toThrow('Network error');
1011
1225
 
1012
1226
  case 3:
1013
1227
  case "end":
1014
- return _context24.stop();
1228
+ return _context29.stop();
1015
1229
  }
1016
- }, _callee24);
1230
+ }, _callee29);
1017
1231
  })));
1018
- it('should rollback optimistic state update if API call fails', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25() {
1019
- return _regeneratorRuntime.wrap(function _callee25$(_context25) {
1020
- while (1) switch (_context25.prev = _context25.next) {
1232
+ it('should rollback optimistic state update if API call fails', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee30() {
1233
+ return _regeneratorRuntime.wrap(function _callee30$(_context30) {
1234
+ while (1) switch (_context30.prev = _context30.next) {
1021
1235
  case 0:
1022
1236
  instance.sharingCol.setReadOnly.mockRejectedValue(new Error('Network error'));
1023
- _context25.next = 3;
1237
+ _context30.next = 3;
1024
1238
  return expect(instance.updateSharingMemberType('sharing-123', 1, 'one-way')).rejects.toThrow('Network error');
1025
1239
 
1026
1240
  case 3:
@@ -1047,14 +1261,14 @@ describe('updateSharingMemberType', function () {
1047
1261
 
1048
1262
  case 5:
1049
1263
  case "end":
1050
- return _context25.stop();
1264
+ return _context30.stop();
1051
1265
  }
1052
- }, _callee25);
1266
+ }, _callee30);
1053
1267
  })));
1054
- it('should preserve realtime changes when rolling back an API failure', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee27() {
1268
+ it('should preserve realtime changes when rolling back an API failure', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee32() {
1055
1269
  var realtimeSharing;
1056
- return _regeneratorRuntime.wrap(function _callee27$(_context27) {
1057
- while (1) switch (_context27.prev = _context27.next) {
1270
+ return _regeneratorRuntime.wrap(function _callee32$(_context32) {
1271
+ while (1) switch (_context32.prev = _context32.next) {
1058
1272
  case 0:
1059
1273
  realtimeSharing = _objectSpread(_objectSpread({}, mockSharing), {}, {
1060
1274
  attributes: _objectSpread(_objectSpread({}, mockSharing.attributes), {}, {
@@ -1066,9 +1280,9 @@ describe('updateSharingMemberType', function () {
1066
1280
  })]
1067
1281
  })
1068
1282
  });
1069
- instance.sharingCol.setReadOnly.mockImplementation( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26() {
1070
- return _regeneratorRuntime.wrap(function _callee26$(_context26) {
1071
- while (1) switch (_context26.prev = _context26.next) {
1283
+ instance.sharingCol.setReadOnly.mockImplementation( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31() {
1284
+ return _regeneratorRuntime.wrap(function _callee31$(_context31) {
1285
+ while (1) switch (_context31.prev = _context31.next) {
1072
1286
  case 0:
1073
1287
  instance.state = _objectSpread(_objectSpread({}, instance.state), {}, {
1074
1288
  sharings: instance.state.sharings.map(function (sharing) {
@@ -1079,11 +1293,11 @@ describe('updateSharingMemberType', function () {
1079
1293
 
1080
1294
  case 2:
1081
1295
  case "end":
1082
- return _context26.stop();
1296
+ return _context31.stop();
1083
1297
  }
1084
- }, _callee26);
1298
+ }, _callee31);
1085
1299
  })));
1086
- _context27.next = 4;
1300
+ _context32.next = 4;
1087
1301
  return expect(instance.updateSharingMemberType('sharing-123', 1, 'one-way')).rejects.toThrow('Network error');
1088
1302
 
1089
1303
  case 4:
@@ -1100,9 +1314,9 @@ describe('updateSharingMemberType', function () {
1100
1314
 
1101
1315
  case 5:
1102
1316
  case "end":
1103
- return _context27.stop();
1317
+ return _context32.stop();
1104
1318
  }
1105
- }, _callee27);
1319
+ }, _callee32);
1106
1320
  })));
1107
1321
  }); // TODO Convert with react-testing-library
1108
1322
  // describe('hasWriteAccess', () => {