cozy-harvest-lib 22.0.4 → 22.0.6
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/CHANGELOG.md +22 -0
- package/dist/connections/triggers.js +15 -86
- package/dist/connections/triggers.spec.js +4 -117
- package/dist/locales/en.json +4 -0
- package/dist/locales/fr.json +4 -0
- package/dist/models/ConnectionFlow.spec.js +0 -6
- package/package.json +2 -2
- package/src/connections/triggers.js +6 -33
- package/src/connections/triggers.spec.js +4 -113
- package/src/locales/en.json +4 -0
- package/src/locales/fr.json +4 -0
- package/src/models/ConnectionFlow.spec.js +0 -5
- package/dist/connections/files.js +0 -86
- package/dist/connections/files.spec.js +0 -141
- package/src/connections/files.js +0 -30
- package/src/connections/files.spec.js +0 -94
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [22.0.6](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@22.0.5...cozy-harvest-lib@22.0.6) (2024-01-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Use konnectorFolder from cozy-client ([f81eed9](https://github.com/cozy/cozy-libs/commit/f81eed99e502f2c1378c6c2d0daa157047967f6e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [22.0.5](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@22.0.4...cozy-harvest-lib@22.0.5) (2024-01-08)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **harvest:** Enhance USER_ACTION_NEEDED messages ([1c26d3f](https://github.com/cozy/cozy-libs/commit/1c26d3f6d94e4e725f2f0ea7e74377303c3e05b8))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [22.0.4](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@22.0.3...cozy-harvest-lib@22.0.4) (2024-01-05)
|
|
7
29
|
|
|
8
30
|
**Note:** Version bump only for package cozy-harvest-lib
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { ensureKonnectorFolder } from 'cozy-client/dist/models/konnectorFolder';
|
|
4
4
|
import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
|
|
5
|
-
import { CozyFolder as CozyFolderClass } from 'cozy-doctypes';
|
|
6
5
|
import { fetchAccount, updateAccount } from './accounts';
|
|
7
|
-
import { statDirectoryByPath, createDirectoryByPath } from './files';
|
|
8
6
|
import * as accounts from '../helpers/accounts';
|
|
9
7
|
import cron from '../helpers/cron';
|
|
10
8
|
import * as konnectors from '../helpers/konnectors';
|
|
11
|
-
var FILES_DOCTYPE = 'io.cozy.files';
|
|
12
|
-
var PERMISSIONS_DOCTYPE = 'io.cozy.permissions';
|
|
13
9
|
var TRIGGERS_DOCTYPE = 'io.cozy.triggers';
|
|
14
10
|
/**
|
|
15
11
|
* Creates a trigger with given attributes
|
|
@@ -174,96 +170,29 @@ export var triggersMutations = function triggersMutations(client) {
|
|
|
174
170
|
launchTrigger: launchTrigger.bind(null, client)
|
|
175
171
|
};
|
|
176
172
|
};
|
|
177
|
-
|
|
178
|
-
var ensureKonnectorFolder = /*#__PURE__*/function () {
|
|
173
|
+
export var ensureTrigger = /*#__PURE__*/function () {
|
|
179
174
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(client, _ref5) {
|
|
180
|
-
var
|
|
181
|
-
|
|
175
|
+
var trigger, account, konnector, t, folder;
|
|
182
176
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
183
177
|
while (1) {
|
|
184
178
|
switch (_context5.prev = _context5.next) {
|
|
185
179
|
case 0:
|
|
186
|
-
|
|
187
|
-
permissions = client.collection(PERMISSIONS_DOCTYPE);
|
|
188
|
-
files = client.collection(FILES_DOCTYPE);
|
|
189
|
-
CozyFolder = CozyFolderClass.copyWithClient(client);
|
|
190
|
-
_context5.next = 6;
|
|
191
|
-
return Promise.all([CozyFolder.ensureMagicFolder(CozyFolder.magicFolders.ADMINISTRATIVE, "/".concat(t('folder.administrative'))), CozyFolder.ensureMagicFolder(CozyFolder.magicFolders.PHOTOS, "/".concat(t('folder.photos')))]);
|
|
192
|
-
|
|
193
|
-
case 6:
|
|
194
|
-
_yield$Promise$all = _context5.sent;
|
|
195
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
196
|
-
adminFolder = _yield$Promise$all2[0];
|
|
197
|
-
photosFolder = _yield$Promise$all2[1];
|
|
198
|
-
path = konnectors.buildFolderPath(konnector, account, {
|
|
199
|
-
administrative: adminFolder.path,
|
|
200
|
-
photos: photosFolder.path
|
|
201
|
-
});
|
|
202
|
-
_context5.next = 13;
|
|
203
|
-
return statDirectoryByPath(client, path);
|
|
204
|
-
|
|
205
|
-
case 13:
|
|
206
|
-
_context5.t0 = _context5.sent;
|
|
207
|
-
|
|
208
|
-
if (_context5.t0) {
|
|
209
|
-
_context5.next = 18;
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
_context5.next = 17;
|
|
214
|
-
return createDirectoryByPath(client, path);
|
|
215
|
-
|
|
216
|
-
case 17:
|
|
217
|
-
_context5.t0 = _context5.sent;
|
|
218
|
-
|
|
219
|
-
case 18:
|
|
220
|
-
folder = _context5.t0;
|
|
221
|
-
_context5.next = 21;
|
|
222
|
-
return permissions.add(konnector, konnectors.buildFolderPermission(folder));
|
|
223
|
-
|
|
224
|
-
case 21:
|
|
225
|
-
_context5.next = 23;
|
|
226
|
-
return files.addReferencesTo(konnector, [folder]);
|
|
227
|
-
|
|
228
|
-
case 23:
|
|
229
|
-
return _context5.abrupt("return", folder);
|
|
230
|
-
|
|
231
|
-
case 24:
|
|
232
|
-
case "end":
|
|
233
|
-
return _context5.stop();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}, _callee5);
|
|
237
|
-
}));
|
|
238
|
-
|
|
239
|
-
return function ensureKonnectorFolder(_x9, _x10) {
|
|
240
|
-
return _ref6.apply(this, arguments);
|
|
241
|
-
};
|
|
242
|
-
}();
|
|
243
|
-
|
|
244
|
-
export var ensureTrigger = /*#__PURE__*/function () {
|
|
245
|
-
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(client, _ref7) {
|
|
246
|
-
var trigger, account, konnector, t, folder;
|
|
247
|
-
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
248
|
-
while (1) {
|
|
249
|
-
switch (_context6.prev = _context6.next) {
|
|
250
|
-
case 0:
|
|
251
|
-
trigger = _ref7.trigger, account = _ref7.account, konnector = _ref7.konnector, t = _ref7.t;
|
|
180
|
+
trigger = _ref5.trigger, account = _ref5.account, konnector = _ref5.konnector, t = _ref5.t;
|
|
252
181
|
|
|
253
182
|
if (!trigger) {
|
|
254
|
-
|
|
183
|
+
_context5.next = 3;
|
|
255
184
|
break;
|
|
256
185
|
}
|
|
257
186
|
|
|
258
|
-
return
|
|
187
|
+
return _context5.abrupt("return", trigger);
|
|
259
188
|
|
|
260
189
|
case 3:
|
|
261
190
|
if (!konnectors.needsFolder(konnector)) {
|
|
262
|
-
|
|
191
|
+
_context5.next = 7;
|
|
263
192
|
break;
|
|
264
193
|
}
|
|
265
194
|
|
|
266
|
-
|
|
195
|
+
_context5.next = 6;
|
|
267
196
|
return ensureKonnectorFolder(client, {
|
|
268
197
|
konnector: konnector,
|
|
269
198
|
account: account,
|
|
@@ -271,10 +200,10 @@ export var ensureTrigger = /*#__PURE__*/function () {
|
|
|
271
200
|
});
|
|
272
201
|
|
|
273
202
|
case 6:
|
|
274
|
-
folder =
|
|
203
|
+
folder = _context5.sent;
|
|
275
204
|
|
|
276
205
|
case 7:
|
|
277
|
-
|
|
206
|
+
_context5.next = 9;
|
|
278
207
|
return createTrigger(client, triggersModel.buildTriggerAttributes({
|
|
279
208
|
account: account,
|
|
280
209
|
cron: cron.fromKonnector(konnector),
|
|
@@ -283,18 +212,18 @@ export var ensureTrigger = /*#__PURE__*/function () {
|
|
|
283
212
|
}));
|
|
284
213
|
|
|
285
214
|
case 9:
|
|
286
|
-
return
|
|
215
|
+
return _context5.abrupt("return", _context5.sent);
|
|
287
216
|
|
|
288
217
|
case 10:
|
|
289
218
|
case "end":
|
|
290
|
-
return
|
|
219
|
+
return _context5.stop();
|
|
291
220
|
}
|
|
292
221
|
}
|
|
293
|
-
},
|
|
222
|
+
}, _callee5);
|
|
294
223
|
}));
|
|
295
224
|
|
|
296
|
-
return function ensureTrigger(
|
|
297
|
-
return
|
|
225
|
+
return function ensureTrigger(_x9, _x10) {
|
|
226
|
+
return _ref6.apply(this, arguments);
|
|
298
227
|
};
|
|
299
228
|
}();
|
|
300
229
|
export default triggersMutations;
|
|
@@ -2,39 +2,9 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
|
|
4
4
|
/* eslint-env jest */
|
|
5
|
-
import { createTrigger, launchTrigger
|
|
6
|
-
import Polyglot from 'node-polyglot';
|
|
5
|
+
import { createTrigger, launchTrigger } from 'connections/triggers';
|
|
7
6
|
import CozyClient from 'cozy-client';
|
|
8
|
-
import { CozyFolder } from 'cozy-doctypes';
|
|
9
|
-
import { statDirectoryByPath, createDirectoryByPath } from '../../src/connections/files';
|
|
10
|
-
import en from '../../src/locales/en.json';
|
|
11
7
|
import fixtures from '../../test/fixtures';
|
|
12
|
-
jest.mock('../../src/connections/files', function () {
|
|
13
|
-
return {
|
|
14
|
-
statDirectoryByPath: jest.fn(),
|
|
15
|
-
createDirectoryByPath: jest.fn()
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
afterEach(function () {
|
|
19
|
-
jest.restoreAllMocks();
|
|
20
|
-
statDirectoryByPath.mockClear();
|
|
21
|
-
createDirectoryByPath.mockClear();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
CozyFolder.copyWithClient = function () {
|
|
25
|
-
return {
|
|
26
|
-
magicFolders: CozyFolder.magicFolders,
|
|
27
|
-
ensureMagicFolder: function ensureMagicFolder(id, path) {
|
|
28
|
-
return {
|
|
29
|
-
path: path
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
var polyglot = new Polyglot();
|
|
36
|
-
polyglot.extend(en);
|
|
37
|
-
var fakeT = polyglot.t.bind(polyglot);
|
|
38
8
|
|
|
39
9
|
var setup = function setup() {
|
|
40
10
|
var client = new CozyClient({});
|
|
@@ -46,26 +16,12 @@ var setup = function setup() {
|
|
|
46
16
|
data: fixtures.launchedJob
|
|
47
17
|
})
|
|
48
18
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
var fileCollection = {
|
|
53
|
-
addReferencesTo: jest.fn().mockResolvedValue({})
|
|
54
|
-
};
|
|
55
|
-
jest.spyOn(CozyClient.prototype, 'collection').mockImplementation(function (doctype) {
|
|
56
|
-
if (doctype == 'io.cozy.triggers') {
|
|
57
|
-
return triggerCollection;
|
|
58
|
-
} else if (doctype == 'io.cozy.permissions') {
|
|
59
|
-
return permissionCollection;
|
|
60
|
-
} else if (doctype == 'io.cozy.files') {
|
|
61
|
-
return fileCollection;
|
|
62
|
-
}
|
|
19
|
+
jest.spyOn(CozyClient.prototype, 'collection').mockImplementation(function () {
|
|
20
|
+
return triggerCollection;
|
|
63
21
|
});
|
|
64
22
|
return {
|
|
65
23
|
client: client,
|
|
66
|
-
triggerCollection: triggerCollection
|
|
67
|
-
permissionCollection: permissionCollection,
|
|
68
|
-
fileCollection: fileCollection
|
|
24
|
+
triggerCollection: triggerCollection
|
|
69
25
|
};
|
|
70
26
|
};
|
|
71
27
|
|
|
@@ -120,73 +76,4 @@ describe('Trigger mutations', function () {
|
|
|
120
76
|
}, _callee2);
|
|
121
77
|
})));
|
|
122
78
|
});
|
|
123
|
-
});
|
|
124
|
-
describe('when konnector needs folder', function () {
|
|
125
|
-
it('should create folder if it does not exist', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
126
|
-
var _setup3, client, permissionCollection, fileCollection, addReferencesTo;
|
|
127
|
-
|
|
128
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
129
|
-
while (1) {
|
|
130
|
-
switch (_context3.prev = _context3.next) {
|
|
131
|
-
case 0:
|
|
132
|
-
_setup3 = setup(), client = _setup3.client, permissionCollection = _setup3.permissionCollection, fileCollection = _setup3.fileCollection;
|
|
133
|
-
statDirectoryByPath.mockResolvedValue(null);
|
|
134
|
-
createDirectoryByPath.mockReturnValue(fixtures.folder);
|
|
135
|
-
_context3.next = 5;
|
|
136
|
-
return ensureTrigger(client, {
|
|
137
|
-
konnector: fixtures.konnectorWithFolder,
|
|
138
|
-
account: fixtures.account,
|
|
139
|
-
t: fakeT
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
case 5:
|
|
143
|
-
expect(statDirectoryByPath).toHaveBeenCalledTimes(1);
|
|
144
|
-
expect(createDirectoryByPath).toHaveBeenCalledTimes(1);
|
|
145
|
-
expect(createDirectoryByPath).toHaveBeenCalledWith(client, fixtures.folderPath);
|
|
146
|
-
expect(permissionCollection.add).toHaveBeenCalledTimes(1);
|
|
147
|
-
expect(permissionCollection.add).toHaveBeenCalledWith(fixtures.konnectorWithFolder, fixtures.folderPermission);
|
|
148
|
-
addReferencesTo = fileCollection.addReferencesTo;
|
|
149
|
-
expect(addReferencesTo).toHaveBeenCalledTimes(1);
|
|
150
|
-
expect(addReferencesTo).toHaveBeenCalledWith(fixtures.konnectorWithFolder, [fixtures.folder]);
|
|
151
|
-
|
|
152
|
-
case 13:
|
|
153
|
-
case "end":
|
|
154
|
-
return _context3.stop();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}, _callee3);
|
|
158
|
-
})));
|
|
159
|
-
it('should not create folder if it exists', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
160
|
-
var _setup4, client, permissionCollection, fileCollection, addPermission, addReferencesTo;
|
|
161
|
-
|
|
162
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
163
|
-
while (1) {
|
|
164
|
-
switch (_context4.prev = _context4.next) {
|
|
165
|
-
case 0:
|
|
166
|
-
_setup4 = setup(), client = _setup4.client, permissionCollection = _setup4.permissionCollection, fileCollection = _setup4.fileCollection;
|
|
167
|
-
statDirectoryByPath.mockResolvedValue(fixtures.folder);
|
|
168
|
-
_context4.next = 4;
|
|
169
|
-
return ensureTrigger(client, {
|
|
170
|
-
account: fixtures.account,
|
|
171
|
-
konnector: fixtures.konnectorWithFolder,
|
|
172
|
-
t: fakeT
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
case 4:
|
|
176
|
-
expect(statDirectoryByPath).toHaveBeenCalledTimes(1);
|
|
177
|
-
expect(createDirectoryByPath).toHaveBeenCalledTimes(0);
|
|
178
|
-
addPermission = permissionCollection.add;
|
|
179
|
-
expect(addPermission).toHaveBeenCalledTimes(1);
|
|
180
|
-
expect(addPermission).toHaveBeenCalledWith(fixtures.konnectorWithFolder, fixtures.folderPermission);
|
|
181
|
-
addReferencesTo = fileCollection.addReferencesTo;
|
|
182
|
-
expect(addReferencesTo).toHaveBeenCalledTimes(1);
|
|
183
|
-
expect(addReferencesTo).toHaveBeenCalledWith(fixtures.konnectorWithFolder, [fixtures.folder]);
|
|
184
|
-
|
|
185
|
-
case 12:
|
|
186
|
-
case "end":
|
|
187
|
-
return _context4.stop();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}, _callee4);
|
|
191
|
-
})));
|
|
192
79
|
});
|
package/dist/locales/en.json
CHANGED
|
@@ -227,6 +227,10 @@
|
|
|
227
227
|
"title": "Incorrect strong authentication code",
|
|
228
228
|
"description": "The second-factor code provided is incorrect, please start again."
|
|
229
229
|
},
|
|
230
|
+
"USER_ACTION_NEEDED.CGU_FORM": {
|
|
231
|
+
"title": "New terms of service validation needed",
|
|
232
|
+
"description": "It seems that a new validation of terms of service is needed. Please validate them on the [%{name}](%{link}) website and synchronize again."
|
|
233
|
+
},
|
|
230
234
|
"VENDOR_DOWN": {
|
|
231
235
|
"title": "Unavailable service",
|
|
232
236
|
"description": "It seems that the [%{name}](%{link}) service is unavailable at the moment. Please rerun the connector later."
|
package/dist/locales/fr.json
CHANGED
|
@@ -227,6 +227,10 @@
|
|
|
227
227
|
"title": "Le code fourni ne semble pas correct",
|
|
228
228
|
"description": "Le second facteur d’authentification fourni est incorrect, veuillez recommencer."
|
|
229
229
|
},
|
|
230
|
+
"USER_ACTION_NEEDED.CGU_FORM": {
|
|
231
|
+
"title": "Des nouvelles conditions générales d'utilisation sont à valider",
|
|
232
|
+
"description": "Il semble que le service ait de nouvelles conditions générales d'utilisation à valider. Merci de valider ces dernières sur le site [%{name}](%{link}) puis de synchroniser à nouveau."
|
|
233
|
+
},
|
|
230
234
|
"VENDOR_DOWN": {
|
|
231
235
|
"title": "Service non disponible",
|
|
232
236
|
"description": "Il semble que le service [%{name}](%{link}) ne nous ait pas répondu dans les temps. Vous pouvez tenter de synchroniser vos données manuellement maintenant ou ultérieurement."
|
|
@@ -37,12 +37,6 @@ jest.mock('../sentry', function () {
|
|
|
37
37
|
captureException: jest.fn()
|
|
38
38
|
};
|
|
39
39
|
});
|
|
40
|
-
jest.mock('../connections/files', function () {
|
|
41
|
-
return {
|
|
42
|
-
statDirectoryByPath: jest.fn(),
|
|
43
|
-
createDirectoryByPath: jest.fn()
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
40
|
KonnectorJobWatcher.prototype.watch = jest.fn();
|
|
47
41
|
jest.mock('date-fns');
|
|
48
42
|
var realtimeMock = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-harvest-lib",
|
|
3
|
-
"version": "22.0.
|
|
3
|
+
"version": "22.0.6",
|
|
4
4
|
"description": "Provides logic, modules and components for Cozy's harvest applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"react-router-dom": ">=4.3.1"
|
|
107
107
|
},
|
|
108
108
|
"sideEffects": false,
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "b7d55abbda1a057fcfe88f0a5558c10c84fdeab7"
|
|
110
110
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
+
import { ensureKonnectorFolder } from 'cozy-client/dist/models/konnectorFolder'
|
|
1
2
|
import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
|
|
2
|
-
import { CozyFolder as CozyFolderClass } from 'cozy-doctypes'
|
|
3
3
|
|
|
4
4
|
import { fetchAccount, updateAccount } from './accounts'
|
|
5
|
-
import { statDirectoryByPath, createDirectoryByPath } from './files'
|
|
6
5
|
import * as accounts from '../helpers/accounts'
|
|
7
6
|
import cron from '../helpers/cron'
|
|
8
7
|
import * as konnectors from '../helpers/konnectors'
|
|
9
8
|
|
|
10
|
-
const FILES_DOCTYPE = 'io.cozy.files'
|
|
11
|
-
const PERMISSIONS_DOCTYPE = 'io.cozy.permissions'
|
|
12
9
|
const TRIGGERS_DOCTYPE = 'io.cozy.triggers'
|
|
13
10
|
|
|
14
11
|
/**
|
|
@@ -71,34 +68,6 @@ export const triggersMutations = client => {
|
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
const ensureKonnectorFolder = async (client, { konnector, account, t }) => {
|
|
75
|
-
const permissions = client.collection(PERMISSIONS_DOCTYPE)
|
|
76
|
-
const files = client.collection(FILES_DOCTYPE)
|
|
77
|
-
const CozyFolder = CozyFolderClass.copyWithClient(client)
|
|
78
|
-
const [adminFolder, photosFolder] = await Promise.all([
|
|
79
|
-
CozyFolder.ensureMagicFolder(
|
|
80
|
-
CozyFolder.magicFolders.ADMINISTRATIVE,
|
|
81
|
-
`/${t('folder.administrative')}`
|
|
82
|
-
),
|
|
83
|
-
CozyFolder.ensureMagicFolder(
|
|
84
|
-
CozyFolder.magicFolders.PHOTOS,
|
|
85
|
-
`/${t('folder.photos')}`
|
|
86
|
-
)
|
|
87
|
-
])
|
|
88
|
-
const path = konnectors.buildFolderPath(konnector, account, {
|
|
89
|
-
administrative: adminFolder.path,
|
|
90
|
-
photos: photosFolder.path
|
|
91
|
-
})
|
|
92
|
-
const folder =
|
|
93
|
-
(await statDirectoryByPath(client, path)) ||
|
|
94
|
-
(await createDirectoryByPath(client, path))
|
|
95
|
-
|
|
96
|
-
await permissions.add(konnector, konnectors.buildFolderPermission(folder))
|
|
97
|
-
await files.addReferencesTo(konnector, [folder])
|
|
98
|
-
|
|
99
|
-
return folder
|
|
100
|
-
}
|
|
101
|
-
|
|
102
71
|
export const ensureTrigger = async (
|
|
103
72
|
client,
|
|
104
73
|
{ trigger, account, konnector, t }
|
|
@@ -110,7 +79,11 @@ export const ensureTrigger = async (
|
|
|
110
79
|
let folder
|
|
111
80
|
|
|
112
81
|
if (konnectors.needsFolder(konnector)) {
|
|
113
|
-
folder = await ensureKonnectorFolder(client, {
|
|
82
|
+
folder = await ensureKonnectorFolder(client, {
|
|
83
|
+
konnector,
|
|
84
|
+
account,
|
|
85
|
+
t
|
|
86
|
+
})
|
|
114
87
|
}
|
|
115
88
|
|
|
116
89
|
return await createTrigger(
|
|
@@ -1,43 +1,10 @@
|
|
|
1
1
|
/* eslint-env jest */
|
|
2
|
-
import {
|
|
3
|
-
createTrigger,
|
|
4
|
-
launchTrigger,
|
|
5
|
-
ensureTrigger
|
|
6
|
-
} from 'connections/triggers'
|
|
7
|
-
import Polyglot from 'node-polyglot'
|
|
2
|
+
import { createTrigger, launchTrigger } from 'connections/triggers'
|
|
8
3
|
|
|
9
4
|
import CozyClient from 'cozy-client'
|
|
10
|
-
import { CozyFolder } from 'cozy-doctypes'
|
|
11
5
|
|
|
12
|
-
import {
|
|
13
|
-
statDirectoryByPath,
|
|
14
|
-
createDirectoryByPath
|
|
15
|
-
} from '../../src/connections/files'
|
|
16
|
-
import en from '../../src/locales/en.json'
|
|
17
6
|
import fixtures from '../../test/fixtures'
|
|
18
7
|
|
|
19
|
-
jest.mock('../../src/connections/files', () => ({
|
|
20
|
-
statDirectoryByPath: jest.fn(),
|
|
21
|
-
createDirectoryByPath: jest.fn()
|
|
22
|
-
}))
|
|
23
|
-
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
jest.restoreAllMocks()
|
|
26
|
-
statDirectoryByPath.mockClear()
|
|
27
|
-
createDirectoryByPath.mockClear()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
CozyFolder.copyWithClient = () => ({
|
|
31
|
-
magicFolders: CozyFolder.magicFolders,
|
|
32
|
-
ensureMagicFolder: (id, path) => ({
|
|
33
|
-
path
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const polyglot = new Polyglot()
|
|
38
|
-
polyglot.extend(en)
|
|
39
|
-
const fakeT = polyglot.t.bind(polyglot)
|
|
40
|
-
|
|
41
8
|
const setup = () => {
|
|
42
9
|
const client = new CozyClient({})
|
|
43
10
|
const triggerCollection = {
|
|
@@ -49,29 +16,13 @@ const setup = () => {
|
|
|
49
16
|
})
|
|
50
17
|
}
|
|
51
18
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const fileCollection = {
|
|
57
|
-
addReferencesTo: jest.fn().mockResolvedValue({})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
jest.spyOn(CozyClient.prototype, 'collection').mockImplementation(doctype => {
|
|
61
|
-
if (doctype == 'io.cozy.triggers') {
|
|
62
|
-
return triggerCollection
|
|
63
|
-
} else if (doctype == 'io.cozy.permissions') {
|
|
64
|
-
return permissionCollection
|
|
65
|
-
} else if (doctype == 'io.cozy.files') {
|
|
66
|
-
return fileCollection
|
|
67
|
-
}
|
|
19
|
+
jest.spyOn(CozyClient.prototype, 'collection').mockImplementation(() => {
|
|
20
|
+
return triggerCollection
|
|
68
21
|
})
|
|
69
22
|
|
|
70
23
|
return {
|
|
71
24
|
client,
|
|
72
|
-
triggerCollection
|
|
73
|
-
permissionCollection,
|
|
74
|
-
fileCollection
|
|
25
|
+
triggerCollection
|
|
75
26
|
}
|
|
76
27
|
}
|
|
77
28
|
|
|
@@ -94,63 +45,3 @@ describe('Trigger mutations', () => {
|
|
|
94
45
|
})
|
|
95
46
|
})
|
|
96
47
|
})
|
|
97
|
-
|
|
98
|
-
describe('when konnector needs folder', () => {
|
|
99
|
-
it('should create folder if it does not exist', async () => {
|
|
100
|
-
const { client, permissionCollection, fileCollection } = setup()
|
|
101
|
-
statDirectoryByPath.mockResolvedValue(null)
|
|
102
|
-
createDirectoryByPath.mockReturnValue(fixtures.folder)
|
|
103
|
-
|
|
104
|
-
await ensureTrigger(client, {
|
|
105
|
-
konnector: fixtures.konnectorWithFolder,
|
|
106
|
-
account: fixtures.account,
|
|
107
|
-
t: fakeT
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
expect(statDirectoryByPath).toHaveBeenCalledTimes(1)
|
|
111
|
-
expect(createDirectoryByPath).toHaveBeenCalledTimes(1)
|
|
112
|
-
expect(createDirectoryByPath).toHaveBeenCalledWith(
|
|
113
|
-
client,
|
|
114
|
-
fixtures.folderPath
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
expect(permissionCollection.add).toHaveBeenCalledTimes(1)
|
|
118
|
-
expect(permissionCollection.add).toHaveBeenCalledWith(
|
|
119
|
-
fixtures.konnectorWithFolder,
|
|
120
|
-
fixtures.folderPermission
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
const addReferencesTo = fileCollection.addReferencesTo
|
|
124
|
-
expect(addReferencesTo).toHaveBeenCalledTimes(1)
|
|
125
|
-
expect(addReferencesTo).toHaveBeenCalledWith(fixtures.konnectorWithFolder, [
|
|
126
|
-
fixtures.folder
|
|
127
|
-
])
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it('should not create folder if it exists', async () => {
|
|
131
|
-
const { client, permissionCollection, fileCollection } = setup()
|
|
132
|
-
statDirectoryByPath.mockResolvedValue(fixtures.folder)
|
|
133
|
-
|
|
134
|
-
await ensureTrigger(client, {
|
|
135
|
-
account: fixtures.account,
|
|
136
|
-
konnector: fixtures.konnectorWithFolder,
|
|
137
|
-
t: fakeT
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
expect(statDirectoryByPath).toHaveBeenCalledTimes(1)
|
|
141
|
-
expect(createDirectoryByPath).toHaveBeenCalledTimes(0)
|
|
142
|
-
|
|
143
|
-
const addPermission = permissionCollection.add
|
|
144
|
-
expect(addPermission).toHaveBeenCalledTimes(1)
|
|
145
|
-
expect(addPermission).toHaveBeenCalledWith(
|
|
146
|
-
fixtures.konnectorWithFolder,
|
|
147
|
-
fixtures.folderPermission
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
const addReferencesTo = fileCollection.addReferencesTo
|
|
151
|
-
expect(addReferencesTo).toHaveBeenCalledTimes(1)
|
|
152
|
-
expect(addReferencesTo).toHaveBeenCalledWith(fixtures.konnectorWithFolder, [
|
|
153
|
-
fixtures.folder
|
|
154
|
-
])
|
|
155
|
-
})
|
|
156
|
-
})
|
package/src/locales/en.json
CHANGED
|
@@ -227,6 +227,10 @@
|
|
|
227
227
|
"title": "Incorrect strong authentication code",
|
|
228
228
|
"description": "The second-factor code provided is incorrect, please start again."
|
|
229
229
|
},
|
|
230
|
+
"USER_ACTION_NEEDED.CGU_FORM": {
|
|
231
|
+
"title": "New terms of service validation needed",
|
|
232
|
+
"description": "It seems that a new validation of terms of service is needed. Please validate them on the [%{name}](%{link}) website and synchronize again."
|
|
233
|
+
},
|
|
230
234
|
"VENDOR_DOWN": {
|
|
231
235
|
"title": "Unavailable service",
|
|
232
236
|
"description": "It seems that the [%{name}](%{link}) service is unavailable at the moment. Please rerun the connector later."
|
package/src/locales/fr.json
CHANGED
|
@@ -227,6 +227,10 @@
|
|
|
227
227
|
"title": "Le code fourni ne semble pas correct",
|
|
228
228
|
"description": "Le second facteur d’authentification fourni est incorrect, veuillez recommencer."
|
|
229
229
|
},
|
|
230
|
+
"USER_ACTION_NEEDED.CGU_FORM": {
|
|
231
|
+
"title": "Des nouvelles conditions générales d'utilisation sont à valider",
|
|
232
|
+
"description": "Il semble que le service ait de nouvelles conditions générales d'utilisation à valider. Merci de valider ces dernières sur le site [%{name}](%{link}) puis de synchroniser à nouveau."
|
|
233
|
+
},
|
|
230
234
|
"VENDOR_DOWN": {
|
|
231
235
|
"title": "Service non disponible",
|
|
232
236
|
"description": "Il semble que le service [%{name}](%{link}) ne nous ait pas répondu dans les temps. Vous pouvez tenter de synchroniser vos données manuellement maintenant ou ultérieurement."
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
var FILES_DOCTYPE = 'io.cozy.files';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a directory from a given path
|
|
6
|
-
* @param {Object} client CozyClient
|
|
7
|
-
* @param {string} path Directory path
|
|
8
|
-
* @return {Object} Directory attributes
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export var createDirectoryByPath = /*#__PURE__*/function () {
|
|
12
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(client, path) {
|
|
13
|
-
var _yield$client$collect, data;
|
|
14
|
-
|
|
15
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
16
|
-
while (1) {
|
|
17
|
-
switch (_context.prev = _context.next) {
|
|
18
|
-
case 0:
|
|
19
|
-
_context.next = 2;
|
|
20
|
-
return client.collection(FILES_DOCTYPE).createDirectoryByPath(path);
|
|
21
|
-
|
|
22
|
-
case 2:
|
|
23
|
-
_yield$client$collect = _context.sent;
|
|
24
|
-
data = _yield$client$collect.data;
|
|
25
|
-
return _context.abrupt("return", data);
|
|
26
|
-
|
|
27
|
-
case 5:
|
|
28
|
-
case "end":
|
|
29
|
-
return _context.stop();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}, _callee);
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
return function createDirectoryByPath(_x, _x2) {
|
|
36
|
-
return _ref.apply(this, arguments);
|
|
37
|
-
};
|
|
38
|
-
}();
|
|
39
|
-
/**
|
|
40
|
-
* Retrieves a directory from its path
|
|
41
|
-
* @param {Object} client CozyClient
|
|
42
|
-
* @param {string} path Directory path
|
|
43
|
-
* @return {Object} Created io.cozy.files document
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
export var statDirectoryByPath = /*#__PURE__*/function () {
|
|
47
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(client, path) {
|
|
48
|
-
var response;
|
|
49
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
50
|
-
while (1) {
|
|
51
|
-
switch (_context2.prev = _context2.next) {
|
|
52
|
-
case 0:
|
|
53
|
-
_context2.prev = 0;
|
|
54
|
-
_context2.next = 3;
|
|
55
|
-
return client.collection(FILES_DOCTYPE).statByPath(path);
|
|
56
|
-
|
|
57
|
-
case 3:
|
|
58
|
-
response = _context2.sent;
|
|
59
|
-
return _context2.abrupt("return", response.data);
|
|
60
|
-
|
|
61
|
-
case 7:
|
|
62
|
-
_context2.prev = 7;
|
|
63
|
-
_context2.t0 = _context2["catch"](0);
|
|
64
|
-
|
|
65
|
-
if (!(_context2.t0 && _context2.t0.status === 404)) {
|
|
66
|
-
_context2.next = 11;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return _context2.abrupt("return", null);
|
|
71
|
-
|
|
72
|
-
case 11:
|
|
73
|
-
throw new Error(_context2.t0.message);
|
|
74
|
-
|
|
75
|
-
case 12:
|
|
76
|
-
case "end":
|
|
77
|
-
return _context2.stop();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, _callee2, null, [[0, 7]]);
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
return function statDirectoryByPath(_x3, _x4) {
|
|
84
|
-
return _ref2.apply(this, arguments);
|
|
85
|
-
};
|
|
86
|
-
}();
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
|
|
4
|
-
/* eslint-env jest */
|
|
5
|
-
import { createDirectoryByPath, statDirectoryByPath } from 'connections/files';
|
|
6
|
-
import client from 'cozy-client';
|
|
7
|
-
jest.mock('cozy-client', function () {
|
|
8
|
-
return {
|
|
9
|
-
collection: jest.fn().mockReturnValue({
|
|
10
|
-
addReferencesTo: jest.fn(),
|
|
11
|
-
createDirectoryByPath: jest.fn(),
|
|
12
|
-
statByPath: jest.fn()
|
|
13
|
-
})
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
var fixtures = {
|
|
17
|
-
path: '/Administrative/KonnectTest/84595fcbc15242f2a69ac483b37ae999',
|
|
18
|
-
directory: {
|
|
19
|
-
_id: '326267e55ff0511c7f7b9ba56e04b334',
|
|
20
|
-
_rev: '2-510e5a2b3c84aba208c480a91fd39abf',
|
|
21
|
-
type: 'directory',
|
|
22
|
-
name: '84595fcbc15242f2a69ac483b37ae999',
|
|
23
|
-
dir_id: '326267e55ff0511c7f7b9ba56e00ca07',
|
|
24
|
-
created_at: '2018-12-18T11:22:41.065070118+01:00',
|
|
25
|
-
updated_at: '2018-12-18T11:22:41.065070118+01:00',
|
|
26
|
-
tags: [],
|
|
27
|
-
path: '/Administrative/KonnectTest/84595fcbc15242f2a69ac483b37ae999'
|
|
28
|
-
},
|
|
29
|
-
references: {
|
|
30
|
-
data: [{
|
|
31
|
-
type: 'io.cozy.files',
|
|
32
|
-
id: '326267e55ff0511c7f7b9ba56e04b334'
|
|
33
|
-
}]
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
describe('Files mutations', function () {
|
|
37
|
-
beforeAll(function () {
|
|
38
|
-
client.collection().addReferencesTo.mockResolvedValue({
|
|
39
|
-
data: fixtures.references
|
|
40
|
-
});
|
|
41
|
-
client.collection().createDirectoryByPath.mockResolvedValue({
|
|
42
|
-
data: fixtures.directory
|
|
43
|
-
});
|
|
44
|
-
client.collection().statByPath.mockResolvedValue({
|
|
45
|
-
data: fixtures.directory
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
afterEach(function () {
|
|
49
|
-
jest.clearAllMocks();
|
|
50
|
-
});
|
|
51
|
-
afterAll(function () {
|
|
52
|
-
jest.restoreAllMocks();
|
|
53
|
-
});
|
|
54
|
-
describe('createDirectoryByPath', function () {
|
|
55
|
-
it('calls Cozy Client and return io.cozy.files document', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
56
|
-
var directory;
|
|
57
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
58
|
-
while (1) {
|
|
59
|
-
switch (_context.prev = _context.next) {
|
|
60
|
-
case 0:
|
|
61
|
-
_context.next = 2;
|
|
62
|
-
return createDirectoryByPath(client, fixtures.path);
|
|
63
|
-
|
|
64
|
-
case 2:
|
|
65
|
-
directory = _context.sent;
|
|
66
|
-
expect(client.collection().createDirectoryByPath).toHaveBeenCalledWith(fixtures.path);
|
|
67
|
-
expect(directory).toEqual(fixtures.directory);
|
|
68
|
-
|
|
69
|
-
case 5:
|
|
70
|
-
case "end":
|
|
71
|
-
return _context.stop();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}, _callee);
|
|
75
|
-
})));
|
|
76
|
-
});
|
|
77
|
-
describe('statDirectoryByPath', function () {
|
|
78
|
-
it('calls Cozy Client and return io.cozy.files data', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
79
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
80
|
-
while (1) {
|
|
81
|
-
switch (_context2.prev = _context2.next) {
|
|
82
|
-
case 0:
|
|
83
|
-
_context2.t0 = expect;
|
|
84
|
-
_context2.next = 3;
|
|
85
|
-
return statDirectoryByPath(client, fixtures.path);
|
|
86
|
-
|
|
87
|
-
case 3:
|
|
88
|
-
_context2.t1 = _context2.sent;
|
|
89
|
-
(0, _context2.t0)(_context2.t1).toEqual(fixtures.directory);
|
|
90
|
-
|
|
91
|
-
case 5:
|
|
92
|
-
case "end":
|
|
93
|
-
return _context2.stop();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}, _callee2);
|
|
97
|
-
})));
|
|
98
|
-
it('returns null if Cozy Client returns a 404 error', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
99
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
100
|
-
while (1) {
|
|
101
|
-
switch (_context3.prev = _context3.next) {
|
|
102
|
-
case 0:
|
|
103
|
-
client.collection().statByPath.mockRejectedValue({
|
|
104
|
-
status: 404
|
|
105
|
-
});
|
|
106
|
-
_context3.t0 = expect;
|
|
107
|
-
_context3.next = 4;
|
|
108
|
-
return statDirectoryByPath(client, fixtures.path);
|
|
109
|
-
|
|
110
|
-
case 4:
|
|
111
|
-
_context3.t1 = _context3.sent;
|
|
112
|
-
(0, _context3.t0)(_context3.t1).toBeNull();
|
|
113
|
-
|
|
114
|
-
case 6:
|
|
115
|
-
case "end":
|
|
116
|
-
return _context3.stop();
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}, _callee3);
|
|
120
|
-
})));
|
|
121
|
-
it('throw error if Cozy Client returns any other error', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
122
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
123
|
-
while (1) {
|
|
124
|
-
switch (_context4.prev = _context4.next) {
|
|
125
|
-
case 0:
|
|
126
|
-
client.collection().statByPath.mockRejectedValue({
|
|
127
|
-
status: 403,
|
|
128
|
-
message: 'Test error'
|
|
129
|
-
});
|
|
130
|
-
_context4.next = 3;
|
|
131
|
-
return expect(statDirectoryByPath(client, fixtures.path)).rejects.toThrow('Test error');
|
|
132
|
-
|
|
133
|
-
case 3:
|
|
134
|
-
case "end":
|
|
135
|
-
return _context4.stop();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}, _callee4);
|
|
139
|
-
})));
|
|
140
|
-
});
|
|
141
|
-
});
|
package/src/connections/files.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const FILES_DOCTYPE = 'io.cozy.files'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a directory from a given path
|
|
5
|
-
* @param {Object} client CozyClient
|
|
6
|
-
* @param {string} path Directory path
|
|
7
|
-
* @return {Object} Directory attributes
|
|
8
|
-
*/
|
|
9
|
-
export const createDirectoryByPath = async (client, path) => {
|
|
10
|
-
const { data } = await client
|
|
11
|
-
.collection(FILES_DOCTYPE)
|
|
12
|
-
.createDirectoryByPath(path)
|
|
13
|
-
return data
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Retrieves a directory from its path
|
|
18
|
-
* @param {Object} client CozyClient
|
|
19
|
-
* @param {string} path Directory path
|
|
20
|
-
* @return {Object} Created io.cozy.files document
|
|
21
|
-
*/
|
|
22
|
-
export const statDirectoryByPath = async (client, path) => {
|
|
23
|
-
try {
|
|
24
|
-
const response = await client.collection(FILES_DOCTYPE).statByPath(path)
|
|
25
|
-
return response.data
|
|
26
|
-
} catch (error) {
|
|
27
|
-
if (error && error.status === 404) return null
|
|
28
|
-
throw new Error(error.message)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/* eslint-env jest */
|
|
2
|
-
|
|
3
|
-
import { createDirectoryByPath, statDirectoryByPath } from 'connections/files'
|
|
4
|
-
|
|
5
|
-
import client from 'cozy-client'
|
|
6
|
-
|
|
7
|
-
jest.mock('cozy-client', () => ({
|
|
8
|
-
collection: jest.fn().mockReturnValue({
|
|
9
|
-
addReferencesTo: jest.fn(),
|
|
10
|
-
createDirectoryByPath: jest.fn(),
|
|
11
|
-
statByPath: jest.fn()
|
|
12
|
-
})
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
const fixtures = {
|
|
16
|
-
path: '/Administrative/KonnectTest/84595fcbc15242f2a69ac483b37ae999',
|
|
17
|
-
directory: {
|
|
18
|
-
_id: '326267e55ff0511c7f7b9ba56e04b334',
|
|
19
|
-
_rev: '2-510e5a2b3c84aba208c480a91fd39abf',
|
|
20
|
-
type: 'directory',
|
|
21
|
-
name: '84595fcbc15242f2a69ac483b37ae999',
|
|
22
|
-
dir_id: '326267e55ff0511c7f7b9ba56e00ca07',
|
|
23
|
-
created_at: '2018-12-18T11:22:41.065070118+01:00',
|
|
24
|
-
updated_at: '2018-12-18T11:22:41.065070118+01:00',
|
|
25
|
-
tags: [],
|
|
26
|
-
path: '/Administrative/KonnectTest/84595fcbc15242f2a69ac483b37ae999'
|
|
27
|
-
},
|
|
28
|
-
references: {
|
|
29
|
-
data: [
|
|
30
|
-
{
|
|
31
|
-
type: 'io.cozy.files',
|
|
32
|
-
id: '326267e55ff0511c7f7b9ba56e04b334'
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
describe('Files mutations', () => {
|
|
39
|
-
beforeAll(() => {
|
|
40
|
-
client
|
|
41
|
-
.collection()
|
|
42
|
-
.addReferencesTo.mockResolvedValue({ data: fixtures.references })
|
|
43
|
-
|
|
44
|
-
client
|
|
45
|
-
.collection()
|
|
46
|
-
.createDirectoryByPath.mockResolvedValue({ data: fixtures.directory })
|
|
47
|
-
|
|
48
|
-
client
|
|
49
|
-
.collection()
|
|
50
|
-
.statByPath.mockResolvedValue({ data: fixtures.directory })
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
afterEach(() => {
|
|
54
|
-
jest.clearAllMocks()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
afterAll(() => {
|
|
58
|
-
jest.restoreAllMocks()
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
describe('createDirectoryByPath', () => {
|
|
62
|
-
it('calls Cozy Client and return io.cozy.files document', async () => {
|
|
63
|
-
const directory = await createDirectoryByPath(client, fixtures.path)
|
|
64
|
-
|
|
65
|
-
expect(client.collection().createDirectoryByPath).toHaveBeenCalledWith(
|
|
66
|
-
fixtures.path
|
|
67
|
-
)
|
|
68
|
-
expect(directory).toEqual(fixtures.directory)
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
describe('statDirectoryByPath', () => {
|
|
73
|
-
it('calls Cozy Client and return io.cozy.files data', async () => {
|
|
74
|
-
expect(await statDirectoryByPath(client, fixtures.path)).toEqual(
|
|
75
|
-
fixtures.directory
|
|
76
|
-
)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('returns null if Cozy Client returns a 404 error', async () => {
|
|
80
|
-
client.collection().statByPath.mockRejectedValue({ status: 404 })
|
|
81
|
-
expect(await statDirectoryByPath(client, fixtures.path)).toBeNull()
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('throw error if Cozy Client returns any other error', async () => {
|
|
85
|
-
client
|
|
86
|
-
.collection()
|
|
87
|
-
.statByPath.mockRejectedValue({ status: 403, message: 'Test error' })
|
|
88
|
-
|
|
89
|
-
await expect(statDirectoryByPath(client, fixtures.path)).rejects.toThrow(
|
|
90
|
-
'Test error'
|
|
91
|
-
)
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
})
|