cozy-client 60.15.0 → 60.15.2

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.
@@ -3126,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
3126
3126
  CozyClient.hooks = CozyClient.hooks || {};
3127
3127
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3128
3128
 
3129
- CozyClient.version = "60.15.0";
3129
+ CozyClient.version = "60.15.2";
3130
3130
 
3131
3131
  _microee.default.mixin(CozyClient);
3132
3132
 
@@ -98,10 +98,18 @@ var documents = function documents() {
98
98
  return state;
99
99
  }
100
100
 
101
- if (action && action.definition && action.definition.mutationType === _dsl.MutationTypes.DELETE_DOCUMENT) {
102
- var docId = action.definition.document._id;
103
- var _type = action.definition.document._type;
104
- return _objectSpread(_objectSpread({}, state), {}, (0, _defineProperty2.default)({}, _type, (0, _omit.default)(state[_type], docId)));
101
+ if (action && action.definition) {
102
+ if (action.definition.mutationType === _dsl.MutationTypes.DELETE_DOCUMENT) {
103
+ var docId = action.definition.document._id;
104
+ var _type = action.definition.document._type;
105
+ return _objectSpread(_objectSpread({}, state), {}, (0, _defineProperty2.default)({}, _type, (0, _omit.default)(state[_type], docId)));
106
+ } else if (action.definition.mutationType === _dsl.MutationTypes.DELETE_DOCUMENTS) {
107
+ var docIds = action.definition.documents.map(function (doc) {
108
+ return doc._id;
109
+ });
110
+ var _type2 = action.definition.documents[0]._type;
111
+ return _objectSpread(_objectSpread({}, state), {}, (0, _defineProperty2.default)({}, _type2, (0, _omit.default)(state[_type2], docIds)));
112
+ }
105
113
  }
106
114
 
107
115
  var _action$response = action.response,
@@ -1,4 +1,4 @@
1
- import {
1
+ import documents, {
2
2
  extractAndMergeDocument,
3
3
  mergeDocumentsWithRelationships
4
4
  } from './documents'
@@ -346,3 +346,65 @@ describe('mergeDocumentsWithRelationships', () => {
346
346
  })
347
347
  })
348
348
  })
349
+
350
+ jest.mock('./mutations', () => {
351
+ return {
352
+ isReceivingMutationResult: jest.fn()
353
+ }
354
+ })
355
+
356
+ import { isReceivingMutationResult } from './mutations'
357
+
358
+ describe('documents reducer - delete mutations', () => {
359
+ const initialState = {
360
+ 'io.cozy.files': {
361
+ '1': { _id: '1', _type: 'io.cozy.files', name: 'File 1' },
362
+ '2': { _id: '2', _type: 'io.cozy.files', name: 'File 2' },
363
+ '3': { _id: '3', _type: 'io.cozy.files', name: 'File 3' }
364
+ },
365
+ 'io.cozy.notes': {
366
+ a: { _id: 'a', _type: 'io.cozy.notes', name: 'Note A' }
367
+ }
368
+ }
369
+
370
+ beforeEach(() => {
371
+ /** @type {jest.Mock} */ ;(isReceivingMutationResult).mockReturnValue(true)
372
+ })
373
+
374
+ afterEach(() => {
375
+ jest.clearAllMocks()
376
+ })
377
+
378
+ it('should delete a document with DELETE_DOCUMENT', () => {
379
+ const action = {
380
+ definition: {
381
+ mutationType: 'DELETE_DOCUMENT',
382
+ document: { _id: '2', _type: 'io.cozy.files' }
383
+ },
384
+ response: {}
385
+ }
386
+ const newState = documents(initialState, action)
387
+ expect(newState['io.cozy.files']).not.toHaveProperty('2')
388
+ expect(newState['io.cozy.files']).toHaveProperty('1')
389
+ expect(newState['io.cozy.files']).toHaveProperty('3')
390
+ expect(newState['io.cozy.notes']).toHaveProperty('a')
391
+ })
392
+
393
+ it('should delete multiple documents with DELETE_DOCUMENTS', () => {
394
+ const action = {
395
+ definition: {
396
+ mutationType: 'DELETE_DOCUMENTS',
397
+ documents: [
398
+ { _id: '1', _type: 'io.cozy.files' },
399
+ { _id: '3', _type: 'io.cozy.files' }
400
+ ]
401
+ },
402
+ response: {}
403
+ }
404
+ const newState = documents(initialState, action)
405
+ expect(newState['io.cozy.files']).not.toHaveProperty('1')
406
+ expect(newState['io.cozy.files']).not.toHaveProperty('3')
407
+ expect(newState['io.cozy.files']).toHaveProperty('2')
408
+ expect(newState['io.cozy.notes']).toHaveProperty('a')
409
+ })
410
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "60.15.0",
3
+ "version": "60.15.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "@types/jest": "^26.0.20",
20
20
  "@types/lodash": "^4.14.170",
21
21
  "btoa": "^1.2.1",
22
- "cozy-stack-client": "^60.6.0",
22
+ "cozy-stack-client": "^60.15.1",
23
23
  "date-fns": "^2.30.0",
24
24
  "fast-deep-equal": "^3.1.3",
25
25
  "json-stable-stringify": "^1.0.1",
@@ -74,5 +74,5 @@
74
74
  "react-native-ios11-devicecheck": "^0.0.3"
75
75
  },
76
76
  "sideEffects": false,
77
- "gitHead": "0dc1c60b0fe631ea825d15fc10952e1e119ff199"
77
+ "gitHead": "34f198a7cb619bdfba442fe94c3b41beec424e6a"
78
78
  }