cozy-pouch-link 60.23.2 → 60.24.1

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.
package/dist/files.js CHANGED
@@ -23,19 +23,23 @@ exports.TYPE_FILE = TYPE_FILE;
23
23
 
24
24
  var queryFileById = /*#__PURE__*/function () {
25
25
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, id) {
26
- var queryOpts;
26
+ var definition, options;
27
27
  return _regenerator.default.wrap(function _callee$(_context) {
28
28
  while (1) {
29
29
  switch (_context.prev = _context.next) {
30
30
  case 0:
31
- queryOpts = {
31
+ definition = (0, _cozyClient.Q)('io.cozy.files').getById(id);
32
+ options = {
32
33
  as: "io.cozy.files/".concat(id),
33
34
  fetchPolicy: defaultFetchPolicy,
34
35
  singleDocData: true
35
36
  };
36
- return _context.abrupt("return", client.query((0, _cozyClient.Q)('io.cozy.files').getById(id), queryOpts));
37
+ return _context.abrupt("return", client.fetchQueryAndGetFromState({
38
+ definition: definition,
39
+ options: options
40
+ }));
37
41
 
38
- case 2:
42
+ case 3:
39
43
  case "end":
40
44
  return _context.stop();
41
45
  }
@@ -0,0 +1,25 @@
1
+ import { Q } from 'cozy-client'
2
+
3
+ import { queryFileById } from './files'
4
+
5
+ describe('queryFileById', () => {
6
+ it('should call client.fetchQueryAndGetFromState with the expected definition and options', async () => {
7
+ const expectedResult = { data: { _id: 'parent', path: '/parent' } }
8
+ const client = {
9
+ fetchQueryAndGetFromState: jest.fn().mockResolvedValue(expectedResult)
10
+ }
11
+
12
+ const res = await queryFileById(client, 'parent')
13
+
14
+ expect(res).toBe(expectedResult)
15
+ expect(client.fetchQueryAndGetFromState).toHaveBeenCalledTimes(1)
16
+ expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
17
+ definition: expect.objectContaining(Q('io.cozy.files').getById('parent')),
18
+ options: {
19
+ as: 'io.cozy.files/parent',
20
+ fetchPolicy: expect.any(Function),
21
+ singleDocData: true
22
+ }
23
+ })
24
+ })
25
+ })
package/dist/jsonapi.js CHANGED
@@ -167,7 +167,7 @@ var buildPathWithName = function buildPathWithName(parentPath, fileName) {
167
167
 
168
168
  var computeFileFullpath = /*#__PURE__*/function () {
169
169
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, file) {
170
- var _file$path, newPath, filePath, parentPath, builtPath, path, _yield$queryFileById, parentDir, _path;
170
+ var _file$path, newPath, filePath, parentPath, builtPath, path, result, parentDir, _path;
171
171
 
172
172
  return _regenerator.default.wrap(function _callee$(_context) {
173
173
  while (1) {
@@ -246,8 +246,8 @@ var computeFileFullpath = /*#__PURE__*/function () {
246
246
  return (0, _files.queryFileById)(client, file.dir_id);
247
247
 
248
248
  case 27:
249
- _yield$queryFileById = _context.sent;
250
- parentDir = _yield$queryFileById.data;
249
+ result = _context.sent;
250
+ parentDir = result === null || result === void 0 ? void 0 : result.data;
251
251
 
252
252
  if (parentDir !== null && parentDir !== void 0 && parentDir.path) {
253
253
  _path = buildPathWithName(parentDir.path, file.name);
@@ -719,4 +719,35 @@ describe('computeFileFullpath', () => {
719
719
  const res2 = await computeFileFullpath(client, updFile)
720
720
  expect(res2.path).toEqual('ROOT/MYDIR/file3.1')
721
721
  })
722
+
723
+ it('should return the file unchanged when queryFileById resolves to undefined', async () => {
724
+ // This happens offline when the link chain returns nothing for the
725
+ // parent dir lookup. Before the fix, destructuring `.data` from
726
+ // `undefined` crashed with "Cannot read property 'data' of undefined".
727
+ queryFileById.mockResolvedValue(undefined)
728
+ const file = {
729
+ _id: 'offline-file-1',
730
+ _type: 'io.cozy.files',
731
+ type: 'file',
732
+ dir_id: 'unknown-dir',
733
+ name: 'offline.txt'
734
+ }
735
+ const res = await computeFileFullpath(client, file)
736
+ expect(res).toBe(file)
737
+ expect(res.path).toBeUndefined()
738
+ })
739
+
740
+ it('should return the file unchanged when queryFileById resolves with null data', async () => {
741
+ queryFileById.mockResolvedValue({ data: null })
742
+ const file = {
743
+ _id: 'offline-file-2',
744
+ _type: 'io.cozy.files',
745
+ type: 'file',
746
+ dir_id: 'unknown-dir',
747
+ name: 'offline2.txt'
748
+ }
749
+ const res = await computeFileFullpath(client, file)
750
+ expect(res).toBe(file)
751
+ expect(res.path).toBeUndefined()
752
+ })
722
753
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-pouch-link",
3
- "version": "60.23.2",
3
+ "version": "60.24.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "url": "git+https://github.com/linagora/cozy-client.git"
14
14
  },
15
15
  "dependencies": {
16
- "cozy-client": "^60.23.2",
16
+ "cozy-client": "^60.24.0",
17
17
  "pouchdb-browser": "^7.2.2",
18
18
  "pouchdb-find": "^7.2.2"
19
19
  },
@@ -41,5 +41,5 @@
41
41
  "typecheck": "tsc -p tsconfig.json"
42
42
  },
43
43
  "sideEffects": false,
44
- "gitHead": "973a40f4d79a8456961df6838c8391904a2b9720"
44
+ "gitHead": "97abc13aa043737c338d0e25694320432675b43a"
45
45
  }