cozy-keys-lib 6.1.1 → 6.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-keys-lib",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "Interactions between cozy-keys and a bitwarden server",
|
|
5
5
|
"browser": "transpiled/index.js",
|
|
6
6
|
"main": "transpiled/index.node.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@semantic-release/git": "7.0.18",
|
|
44
44
|
"@semantic-release/npm": "5.3.5",
|
|
45
45
|
"@testing-library/react": "11.2.7",
|
|
46
|
-
"@testing-library/react-hooks": "
|
|
46
|
+
"@testing-library/react-hooks": "8.0.1",
|
|
47
47
|
"babel-loader": "8.2.4",
|
|
48
48
|
"babel-plugin-inline-react-svg": "1.1.2",
|
|
49
49
|
"babel-plugin-mock-imports": "1.2.0",
|
|
@@ -53,13 +53,11 @@
|
|
|
53
53
|
"cozy-flags": "2.8.6",
|
|
54
54
|
"cozy-intent": "2.13.1",
|
|
55
55
|
"cozy-ui": "93.1.1",
|
|
56
|
-
"enzyme": "3.11.0",
|
|
57
|
-
"enzyme-adapter-react-16": "1.15.7",
|
|
58
|
-
"enzyme-to-json": "3.4.0",
|
|
59
56
|
"eslint-config-cozy-app": "1.6.0",
|
|
60
57
|
"jest": "26.2.2",
|
|
61
58
|
"react": "16.14.0",
|
|
62
59
|
"react-dom": "16.14.0",
|
|
60
|
+
"react-test-renderer": "16.14.0",
|
|
63
61
|
"semantic-release": "^15.13.24"
|
|
64
62
|
},
|
|
65
63
|
"files": [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { EventEmitter } from 'events'
|
|
3
3
|
import {
|
|
4
4
|
VaultContext,
|
|
5
5
|
VaultProvider,
|
|
@@ -7,65 +7,78 @@ import {
|
|
|
7
7
|
useVaultClient
|
|
8
8
|
} from './VaultContext'
|
|
9
9
|
import WebVaultClient from '../WebVaultClient'
|
|
10
|
+
import { render, waitFor } from '@testing-library/react'
|
|
10
11
|
import { renderHook } from '@testing-library/react-hooks'
|
|
11
12
|
|
|
12
13
|
jest.mock('../WebVaultClient')
|
|
13
14
|
|
|
15
|
+
const createFakeVaultClient = () => {
|
|
16
|
+
const vaultClient = new EventEmitter()
|
|
17
|
+
|
|
18
|
+
vaultClient.on('lock', () => {
|
|
19
|
+
vaultClient.locked = true
|
|
20
|
+
})
|
|
21
|
+
vaultClient.on('unlock', () => {
|
|
22
|
+
vaultClient.locked = false
|
|
23
|
+
})
|
|
24
|
+
vaultClient.isLocked = () => vaultClient.locked
|
|
25
|
+
|
|
26
|
+
return vaultClient
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
describe('VaultProvider', () => {
|
|
15
30
|
it('should rerender when the locked state changes', async () => {
|
|
16
|
-
const ChildComponent = jest.fn()
|
|
31
|
+
const ChildComponent = jest.fn(() => null)
|
|
32
|
+
const vaultClient = createFakeVaultClient()
|
|
17
33
|
|
|
18
|
-
|
|
19
|
-
<VaultProvider instance={'test@example.com'}>
|
|
34
|
+
render(
|
|
35
|
+
<VaultProvider vaultClient={vaultClient} instance={'test@example.com'}>
|
|
20
36
|
<VaultContext.Consumer>{ChildComponent}</VaultContext.Consumer>
|
|
21
37
|
</VaultProvider>
|
|
22
38
|
)
|
|
23
39
|
|
|
24
|
-
|
|
40
|
+
expect(ChildComponent).toHaveBeenCalledWith({
|
|
41
|
+
vaultClient,
|
|
42
|
+
locked: true
|
|
43
|
+
})
|
|
25
44
|
|
|
26
|
-
|
|
45
|
+
vaultClient.emit('unlock')
|
|
27
46
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
expect(ChildComponent).toHaveBeenCalledTimes(3)
|
|
33
|
-
expect(ChildComponent).toHaveBeenCalledWith({
|
|
34
|
-
vaultClient,
|
|
35
|
-
locked: false
|
|
36
|
-
})
|
|
37
|
-
resolve()
|
|
47
|
+
await waitFor(() => {
|
|
48
|
+
expect(ChildComponent).toHaveBeenCalledWith({
|
|
49
|
+
vaultClient,
|
|
50
|
+
locked: false
|
|
38
51
|
})
|
|
39
|
-
)
|
|
52
|
+
})
|
|
40
53
|
|
|
41
|
-
vaultClient.lock
|
|
54
|
+
vaultClient.emit('lock')
|
|
42
55
|
|
|
43
|
-
await
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
vaultClient,
|
|
48
|
-
locked: true
|
|
49
|
-
})
|
|
50
|
-
resolve()
|
|
56
|
+
await waitFor(() => {
|
|
57
|
+
expect(ChildComponent).toHaveBeenCalledWith({
|
|
58
|
+
vaultClient,
|
|
59
|
+
locked: true
|
|
51
60
|
})
|
|
52
|
-
)
|
|
61
|
+
})
|
|
53
62
|
})
|
|
54
63
|
})
|
|
55
64
|
|
|
56
65
|
describe('withVaultClient', () => {
|
|
57
|
-
it('should inject vaultClient as a prop', () => {
|
|
58
|
-
const ChildComponent = () =>
|
|
66
|
+
it('should inject vaultClient as a prop', async () => {
|
|
67
|
+
const ChildComponent = jest.fn(() => null)
|
|
68
|
+
|
|
59
69
|
const ChildWithClient = withVaultClient(ChildComponent)
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
render(
|
|
62
72
|
<VaultProvider instance={'test@example.com'}>
|
|
63
73
|
<ChildWithClient />
|
|
64
74
|
</VaultProvider>
|
|
65
75
|
)
|
|
66
76
|
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
// Check if the vault is correctly injected as a prop
|
|
78
|
+
const propsPassedToChildComponent = Object.keys(
|
|
79
|
+
ChildComponent.mock.calls[0][0]
|
|
80
|
+
)
|
|
81
|
+
expect(propsPassedToChildComponent).toContain('vaultClient')
|
|
69
82
|
})
|
|
70
83
|
})
|
|
71
84
|
|
|
@@ -1,49 +1,58 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
5
|
import { VaultContext, VaultProvider, withVaultClient, useVaultClient } from './VaultContext';
|
|
6
6
|
import WebVaultClient from '../WebVaultClient';
|
|
7
|
+
import { render, waitFor } from '@testing-library/react';
|
|
7
8
|
import { renderHook } from '@testing-library/react-hooks';
|
|
8
9
|
jest.mock('../WebVaultClient');
|
|
10
|
+
var createFakeVaultClient = function createFakeVaultClient() {
|
|
11
|
+
var vaultClient = new EventEmitter();
|
|
12
|
+
vaultClient.on('lock', function () {
|
|
13
|
+
vaultClient.locked = true;
|
|
14
|
+
});
|
|
15
|
+
vaultClient.on('unlock', function () {
|
|
16
|
+
vaultClient.locked = false;
|
|
17
|
+
});
|
|
18
|
+
vaultClient.isLocked = function () {
|
|
19
|
+
return vaultClient.locked;
|
|
20
|
+
};
|
|
21
|
+
return vaultClient;
|
|
22
|
+
};
|
|
9
23
|
describe('VaultProvider', function () {
|
|
10
24
|
it('should rerender when the locked state changes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
11
|
-
var ChildComponent,
|
|
25
|
+
var ChildComponent, vaultClient;
|
|
12
26
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
13
27
|
while (1) switch (_context.prev = _context.next) {
|
|
14
28
|
case 0:
|
|
15
|
-
ChildComponent = jest.fn()
|
|
16
|
-
|
|
29
|
+
ChildComponent = jest.fn(function () {
|
|
30
|
+
return null;
|
|
31
|
+
});
|
|
32
|
+
vaultClient = createFakeVaultClient();
|
|
33
|
+
render( /*#__PURE__*/React.createElement(VaultProvider, {
|
|
34
|
+
vaultClient: vaultClient,
|
|
17
35
|
instance: 'test@example.com'
|
|
18
36
|
}, /*#__PURE__*/React.createElement(VaultContext.Consumer, null, ChildComponent)));
|
|
19
|
-
vaultClient = component.state('vaultClient');
|
|
20
37
|
expect(ChildComponent).toHaveBeenCalledWith({
|
|
21
38
|
vaultClient: vaultClient,
|
|
22
39
|
locked: true
|
|
23
40
|
});
|
|
24
|
-
vaultClient.unlock
|
|
41
|
+
vaultClient.emit('unlock');
|
|
25
42
|
_context.next = 7;
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
vaultClient: vaultClient,
|
|
31
|
-
locked: false
|
|
32
|
-
});
|
|
33
|
-
resolve();
|
|
43
|
+
return waitFor(function () {
|
|
44
|
+
expect(ChildComponent).toHaveBeenCalledWith({
|
|
45
|
+
vaultClient: vaultClient,
|
|
46
|
+
locked: false
|
|
34
47
|
});
|
|
35
48
|
});
|
|
36
49
|
case 7:
|
|
37
|
-
vaultClient.lock
|
|
50
|
+
vaultClient.emit('lock');
|
|
38
51
|
_context.next = 10;
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
vaultClient: vaultClient,
|
|
44
|
-
locked: true
|
|
45
|
-
});
|
|
46
|
-
resolve();
|
|
52
|
+
return waitFor(function () {
|
|
53
|
+
expect(ChildComponent).toHaveBeenCalledWith({
|
|
54
|
+
vaultClient: vaultClient,
|
|
55
|
+
locked: true
|
|
47
56
|
});
|
|
48
57
|
});
|
|
49
58
|
case 10:
|
|
@@ -54,22 +63,33 @@ describe('VaultProvider', function () {
|
|
|
54
63
|
})));
|
|
55
64
|
});
|
|
56
65
|
describe('withVaultClient', function () {
|
|
57
|
-
it('should inject vaultClient as a prop', function () {
|
|
58
|
-
var ChildComponent
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
it('should inject vaultClient as a prop', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
67
|
+
var ChildComponent, ChildWithClient, propsPassedToChildComponent;
|
|
68
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
69
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
ChildComponent = jest.fn(function () {
|
|
72
|
+
return null;
|
|
73
|
+
});
|
|
74
|
+
ChildWithClient = withVaultClient(ChildComponent);
|
|
75
|
+
render( /*#__PURE__*/React.createElement(VaultProvider, {
|
|
76
|
+
instance: 'test@example.com'
|
|
77
|
+
}, /*#__PURE__*/React.createElement(ChildWithClient, null)));
|
|
78
|
+
|
|
79
|
+
// Check if the vault is correctly injected as a prop
|
|
80
|
+
propsPassedToChildComponent = Object.keys(ChildComponent.mock.calls[0][0]);
|
|
81
|
+
expect(propsPassedToChildComponent).toContain('vaultClient');
|
|
82
|
+
case 5:
|
|
83
|
+
case "end":
|
|
84
|
+
return _context2.stop();
|
|
85
|
+
}
|
|
86
|
+
}, _callee2);
|
|
87
|
+
})));
|
|
68
88
|
});
|
|
69
89
|
describe('useVaultClient', function () {
|
|
70
90
|
it('should return the vault client from the context', function () {
|
|
71
|
-
var wrapper = function wrapper(
|
|
72
|
-
var children =
|
|
91
|
+
var wrapper = function wrapper(_ref3) {
|
|
92
|
+
var children = _ref3.children;
|
|
73
93
|
return /*#__PURE__*/React.createElement(VaultProvider, {
|
|
74
94
|
instance: "test@example.com"
|
|
75
95
|
}, children);
|