This repository was archived by the owner on Aug 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathprotect.test.js
More file actions
89 lines (78 loc) · 1.96 KB
/
protect.test.js
File metadata and controls
89 lines (78 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* eslint-disable no-unused-expressions */
const chai = require('chai');
const { protect } = require('../../lib/hooks');
const { expect } = chai;
function testOmit (title, property) {
describe(title, () => {
const fn = protect('password');
it('omits from object', () => {
const data = {
email: 'test@user.com',
password: 'supersecret'
};
const context = {
[property]: data
};
const result = fn(context);
expect(result).to.deep.equal({
[property]: data,
dispatch: { email: 'test@user.com' }
});
});
it('omits from array', () => {
const data = [{
email: 'test1@user.com',
password: 'supersecret'
}, {
email: 'test2@user.com',
password: 'othersecret'
}];
const context = {
[property]: data
};
const result = fn(context);
expect(result).to.deep.equal({
[property]: data,
dispatch: [
{ email: 'test1@user.com' },
{ email: 'test2@user.com' }
]
});
});
it('omits from pagination object', () => {
const data = {
total: 2,
data: [{
email: 'test1@user.com',
password: 'supersecret'
}, {
email: 'test2@user.com',
password: 'othersecret'
}]
};
const context = {
[property]: data
};
const result = fn(context);
expect(result).to.deep.equal({
[property]: data,
dispatch: {
total: 2,
data: [
{ email: 'test1@user.com' },
{ email: 'test2@user.com' }
]
}
});
});
});
}
describe('hooks:protect', () => {
it('does nothing when called with no result', () => {
const fn = protect();
const original = {};
expect(fn(original)).to.deep.equal(original);
});
testOmit('with hook.result', 'result');
testOmit('with hook.dispatch already set', 'dispatch');
});