cozy-harvest-lib 9.6.1 → 9.7.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
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
+ ## [9.7.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.7.1...cozy-harvest-lib@9.7.2) (2022-06-07)
7
+
8
+ **Note:** Version bump only for package cozy-harvest-lib
9
+
10
+
11
+
12
+
13
+
14
+ ## [9.7.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.7.0...cozy-harvest-lib@9.7.1) (2022-06-03)
15
+
16
+ **Note:** Version bump only for package cozy-harvest-lib
17
+
18
+
19
+
20
+
21
+
22
+ # [9.7.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.6.1...cozy-harvest-lib@9.7.0) (2022-06-01)
23
+
24
+
25
+ ### Features
26
+
27
+ * Add a synchronization button after Contract list ([2e0fe2d](https://github.com/cozy/cozy-libs/commit/2e0fe2de4cc7408973017ccc1f263605b9befa31))
28
+
29
+
30
+
31
+
32
+
6
33
  ## [9.6.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.6.0...cozy-harvest-lib@9.6.1) (2022-06-01)
7
34
 
8
35
  **Note:** Version bump only for package cozy-harvest-lib
@@ -0,0 +1,194 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import React from 'react';
4
+ import CozyClient from 'cozy-client';
5
+ import { render, fireEvent, act, waitFor } from '@testing-library/react';
6
+ import AppLike from '../../../../test/AppLike';
7
+ import BIContractActivationWindow from './BiContractActivationWindow';
8
+ var fetchContractSynchronizationUrl = jest.fn();
9
+ var refreshContracts = jest.fn();
10
+ jest.mock('../../../konnector-policies', function () {
11
+ return {
12
+ findKonnectorPolicy: jest.fn()
13
+ };
14
+ });
15
+ jest.mock('cozy-ui/transpiled/react/Popup', function () {
16
+ return jest.fn().mockImplementation(function (_ref) {
17
+ var onClose = _ref.onClose;
18
+ setTimeout(onClose, 1);
19
+ return null;
20
+ });
21
+ });
22
+ jest.mock('../../InAppBrowser', function () {
23
+ return jest.fn().mockImplementation(function (_ref2) {
24
+ var onClose = _ref2.onClose;
25
+ setTimeout(onClose, 1);
26
+ return null;
27
+ });
28
+ });
29
+ jest.mock('cozy-device-helper');
30
+ import { findKonnectorPolicy } from '../../../konnector-policies';
31
+ import Popup from 'cozy-ui/transpiled/react/Popup';
32
+ import InAppBrowser from '../../InAppBrowser';
33
+ import { isFlagshipApp } from 'cozy-device-helper';
34
+ findKonnectorPolicy.mockImplementation(function () {
35
+ return {
36
+ fetchContractSynchronizationUrl: fetchContractSynchronizationUrl,
37
+ refreshContracts: refreshContracts
38
+ };
39
+ });
40
+ var mockKonnector = {
41
+ slug: 'mockkonnector'
42
+ };
43
+ var mockAccount = {};
44
+
45
+ var setup = function setup() {
46
+ var client = new CozyClient({});
47
+ return render( /*#__PURE__*/React.createElement(AppLike, {
48
+ client: client
49
+ }, /*#__PURE__*/React.createElement(BIContractActivationWindow, {
50
+ konnector: mockKonnector,
51
+ account: mockAccount
52
+ })));
53
+ };
54
+
55
+ describe('BIContractActivationWindow', function () {
56
+ afterEach(function () {
57
+ jest.clearAllMocks();
58
+ });
59
+ afterAll(function () {
60
+ jest.resetAllMocks();
61
+ });
62
+ it('should display popup with url from policy and update contract after popup is closed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
63
+ var _setup, getByRole;
64
+
65
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
66
+ while (1) {
67
+ switch (_context3.prev = _context3.next) {
68
+ case 0:
69
+ isFlagshipApp.mockImplementation(function () {
70
+ return false;
71
+ });
72
+ fetchContractSynchronizationUrl.mockResolvedValue('bi url');
73
+ _setup = setup(), getByRole = _setup.getByRole;
74
+ _context3.next = 5;
75
+ return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
76
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
77
+ while (1) {
78
+ switch (_context.prev = _context.next) {
79
+ case 0:
80
+ _context.next = 2;
81
+ return waitFor(function () {
82
+ expect(getByRole('button').getAttribute('class')).not.toContain('Mui-disabled');
83
+ });
84
+
85
+ case 2:
86
+ case "end":
87
+ return _context.stop();
88
+ }
89
+ }
90
+ }, _callee);
91
+ })));
92
+
93
+ case 5:
94
+ _context3.next = 7;
95
+ return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
96
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
97
+ while (1) {
98
+ switch (_context2.prev = _context2.next) {
99
+ case 0:
100
+ fireEvent.click(getByRole('button'));
101
+ _context2.next = 3;
102
+ return waitFor(function () {
103
+ expect(refreshContracts).toHaveBeenCalled();
104
+ });
105
+
106
+ case 3:
107
+ case "end":
108
+ return _context2.stop();
109
+ }
110
+ }
111
+ }, _callee2);
112
+ })));
113
+
114
+ case 7:
115
+ expect(fetchContractSynchronizationUrl).toHaveBeenCalled();
116
+ expect(refreshContracts).toHaveBeenCalledTimes(1);
117
+ expect(Popup).toHaveBeenCalledWith(expect.objectContaining({
118
+ initialUrl: 'bi url'
119
+ }), expect.anything());
120
+
121
+ case 10:
122
+ case "end":
123
+ return _context3.stop();
124
+ }
125
+ }
126
+ }, _callee3);
127
+ })));
128
+ it('should call InAppBrowser display if in flagship app context', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
129
+ var _setup2, getByRole;
130
+
131
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
132
+ while (1) {
133
+ switch (_context6.prev = _context6.next) {
134
+ case 0:
135
+ isFlagshipApp.mockImplementation(function () {
136
+ return true;
137
+ });
138
+ fetchContractSynchronizationUrl.mockResolvedValue('bi url');
139
+ _setup2 = setup(), getByRole = _setup2.getByRole;
140
+ _context6.next = 5;
141
+ return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
142
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
143
+ while (1) {
144
+ switch (_context4.prev = _context4.next) {
145
+ case 0:
146
+ _context4.next = 2;
147
+ return waitFor(function () {
148
+ expect(getByRole('button').getAttribute('class')).not.toContain('Mui-disabled');
149
+ });
150
+
151
+ case 2:
152
+ case "end":
153
+ return _context4.stop();
154
+ }
155
+ }
156
+ }, _callee4);
157
+ })));
158
+
159
+ case 5:
160
+ _context6.next = 7;
161
+ return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
162
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
163
+ while (1) {
164
+ switch (_context5.prev = _context5.next) {
165
+ case 0:
166
+ fireEvent.click(getByRole('button'));
167
+ _context5.next = 3;
168
+ return waitFor(function () {
169
+ expect(refreshContracts).toHaveBeenCalled();
170
+ });
171
+
172
+ case 3:
173
+ case "end":
174
+ return _context5.stop();
175
+ }
176
+ }
177
+ }, _callee5);
178
+ })));
179
+
180
+ case 7:
181
+ expect(fetchContractSynchronizationUrl).toHaveBeenCalled();
182
+ expect(refreshContracts).toHaveBeenCalledTimes(1);
183
+ expect(InAppBrowser).toHaveBeenCalledWith(expect.objectContaining({
184
+ url: 'bi url'
185
+ }), expect.anything());
186
+
187
+ case 10:
188
+ case "end":
189
+ return _context6.stop();
190
+ }
191
+ }
192
+ }, _callee6);
193
+ })));
194
+ });
@@ -0,0 +1,136 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import React, { useState, useEffect } from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { useClient } from 'cozy-client';
7
+ import Button from 'cozy-ui/transpiled/react/MuiCozyTheme/Buttons';
8
+ import Popup from 'cozy-ui/transpiled/react/Popup';
9
+ import ListItem from 'cozy-ui/transpiled/react/MuiCozyTheme/ListItem';
10
+ import { findKonnectorPolicy } from '../../../konnector-policies';
11
+ import { isFlagshipApp } from 'cozy-device-helper';
12
+ import InAppBrowser from '../../InAppBrowser';
13
+ import withLocales from '../../hoc/withLocales';
14
+
15
+ var BIContractActivationWindow = function BIContractActivationWindow(_ref) {
16
+ var konnector = _ref.konnector,
17
+ account = _ref.account,
18
+ t = _ref.t;
19
+
20
+ var _useState = useState(null),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ initialUrl = _useState2[0],
23
+ setInitialUrl = _useState2[1];
24
+
25
+ var _useState3 = useState(false),
26
+ _useState4 = _slicedToArray(_useState3, 2),
27
+ isWindowVisible = _useState4[0],
28
+ setWindowVisible = _useState4[1];
29
+
30
+ var _useState5 = useState(false),
31
+ _useState6 = _slicedToArray(_useState5, 2),
32
+ shouldRefreshContracts = _useState6[0],
33
+ setShouldRefreshContracts = _useState6[1];
34
+
35
+ var konnectorPolicy = findKonnectorPolicy(konnector);
36
+ var client = useClient();
37
+
38
+ var onPopupClosed = function onPopupClosed() {
39
+ setWindowVisible(false);
40
+ setShouldRefreshContracts(true);
41
+ };
42
+
43
+ useEffect(function () {
44
+ function refreshContracts() {
45
+ return _refreshContracts.apply(this, arguments);
46
+ }
47
+
48
+ function _refreshContracts() {
49
+ _refreshContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
50
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
51
+ while (1) {
52
+ switch (_context.prev = _context.next) {
53
+ case 0:
54
+ _context.next = 2;
55
+ return konnectorPolicy.refreshContracts({
56
+ client: client,
57
+ account: account,
58
+ konnector: konnector
59
+ });
60
+
61
+ case 2:
62
+ setShouldRefreshContracts(false);
63
+
64
+ case 3:
65
+ case "end":
66
+ return _context.stop();
67
+ }
68
+ }
69
+ }, _callee);
70
+ }));
71
+ return _refreshContracts.apply(this, arguments);
72
+ }
73
+
74
+ if (shouldRefreshContracts) {
75
+ refreshContracts();
76
+ }
77
+ }, [account, client, konnectorPolicy, shouldRefreshContracts, konnector]);
78
+ useEffect(function () {
79
+ function handleLinkFetch() {
80
+ return _handleLinkFetch.apply(this, arguments);
81
+ }
82
+
83
+ function _handleLinkFetch() {
84
+ _handleLinkFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
85
+ var result;
86
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
87
+ while (1) {
88
+ switch (_context2.prev = _context2.next) {
89
+ case 0:
90
+ _context2.next = 2;
91
+ return konnectorPolicy.fetchContractSynchronizationUrl({
92
+ client: client,
93
+ account: account,
94
+ konnector: konnector
95
+ });
96
+
97
+ case 2:
98
+ result = _context2.sent;
99
+ setInitialUrl(result);
100
+
101
+ case 4:
102
+ case "end":
103
+ return _context2.stop();
104
+ }
105
+ }
106
+ }, _callee2);
107
+ }));
108
+ return _handleLinkFetch.apply(this, arguments);
109
+ }
110
+
111
+ if (konnectorPolicy.fetchContractSynchronizationUrl) {
112
+ handleLinkFetch();
113
+ }
114
+ }, [konnector, account, client, konnectorPolicy]);
115
+ return konnectorPolicy.fetchContractSynchronizationUrl && /*#__PURE__*/React.createElement(ListItem, null, /*#__PURE__*/React.createElement(Button, {
116
+ disabled: !initialUrl,
117
+ onClick: function onClick() {
118
+ return setWindowVisible(true);
119
+ }
120
+ }, t('contracts.handle-synchronization')), isWindowVisible && (isFlagshipApp() ? /*#__PURE__*/React.createElement(InAppBrowser, {
121
+ url: initialUrl,
122
+ onClose: onPopupClosed
123
+ }) : /*#__PURE__*/React.createElement(Popup, {
124
+ initialUrl: initialUrl,
125
+ width: "800",
126
+ height: "800",
127
+ onClose: onPopupClosed
128
+ })));
129
+ };
130
+
131
+ BIContractActivationWindow.propTypes = {
132
+ t: PropTypes.func,
133
+ account: PropTypes.object,
134
+ konnector: PropTypes.object
135
+ };
136
+ export default withLocales(BIContractActivationWindow);
@@ -17,6 +17,7 @@ import RightIcon from 'cozy-ui/transpiled/react/Icons/Right';
17
17
  import withLocales from '../../hoc/withLocales';
18
18
  import { getAccountLabel } from './bankAccountHelpers';
19
19
  import EditContract from './EditContract';
20
+ import BIContractActivationWindow from './BiContractActivationWindow';
20
21
 
21
22
  var makeContractsConn = function makeContractsConn(_ref) {
22
23
  var account = _ref.account;
@@ -111,6 +112,9 @@ var DumbContracts = function DumbContracts(_ref3) {
111
112
  contract: contract,
112
113
  divider: i !== contractData.length - 1
113
114
  });
115
+ }), /*#__PURE__*/React.createElement(BIContractActivationWindow, {
116
+ konnector: konnector,
117
+ account: account
114
118
  }))));
115
119
  };
116
120
 
@@ -29,7 +29,8 @@
29
29
  "default": "Contracts"
30
30
  },
31
31
  "deleted": "Deleted",
32
- "no-contracts": "No contracts anymore"
32
+ "no-contracts": "No contracts anymore",
33
+ "handle-synchronization": "Handle my synchronizations"
33
34
  },
34
35
  "contractForm": {
35
36
  "details": "Details",
@@ -29,7 +29,8 @@
29
29
  "default": "Contrats"
30
30
  },
31
31
  "deleted": "Supprimé",
32
- "no-contracts": "Vous n'avez plus de contrats"
32
+ "no-contracts": "Vous n'avez plus de contrats",
33
+ "handle-synchronization": "Gérer mes synchronisations"
33
34
  },
34
35
  "contractForm": {
35
36
  "details": "Détails",
@@ -373,4 +373,29 @@ export var setBIConnectionSyncStatus = /*#__PURE__*/function () {
373
373
  return function setBIConnectionSyncStatus(_x24, _x25, _x26, _x27, _x28) {
374
374
  return _ref8.apply(this, arguments);
375
375
  };
376
+ }();
377
+ export var getBIConnectionAccountsList = /*#__PURE__*/function () {
378
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(config, connId, biAccessToken) {
379
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
380
+ while (1) {
381
+ switch (_context9.prev = _context9.next) {
382
+ case 0:
383
+ assert(connId, "Must pass connection id to getBIConnectionAccountList (".concat(connId, " was passed)"));
384
+ _context9.next = 3;
385
+ return biRequest('GET', "/users/me/connections/".concat(connId, "/accounts?all"), config, null, biAccessToken);
386
+
387
+ case 3:
388
+ return _context9.abrupt("return", _context9.sent);
389
+
390
+ case 4:
391
+ case "end":
392
+ return _context9.stop();
393
+ }
394
+ }
395
+ }, _callee9);
396
+ }));
397
+
398
+ return function getBIConnectionAccountsList(_x29, _x30, _x31) {
399
+ return _ref9.apply(this, arguments);
400
+ };
376
401
  }();