Diff to HTML by rtfpessoa

template-skip-remaining-hooks.unit.test.js → skip-remaining-hooks.unit.test.js RENAMED
@@ -1,19 +1,17 @@
1
2
const assert = require('assert');
3
const skipRemainingHooks = require('../../src/hooks/skip-remaining-hooks');
4
5
describe('Test /hooks/skip-remaining-hooks.unit.test.js', () => {
6
- // eslint-disable-next-line no-unused-vars
7
- let contextBefore, contextAfterPaginated,
8
- // eslint-disable-next-line no-unused-vars
9
- contextAfter, contextAfterMultiple;
10
11
beforeEach(() => {
12
contextBefore = {
13
type: 'before',
14
params: { provider: 'socketio' },
15
data: {
16
-
17
}
18
};
19
@@ -21,45 +19,50 @@
21
type: 'after',
22
params: { provider: 'socketio' },
23
result: {
24
-
25
- }
26
- };
27
-
28
- contextAfterMultiple = {
29
- type: 'after',
30
- params: { provider: 'socketio' },
31
- result: [
32
-
33
- ]
34
- };
35
-
36
- contextAfterPaginated = {
37
- type: 'after',
38
- method: 'find',
39
- params: { provider: 'socketio' },
40
- result: {
41
- data: [
42
-
43
- ]
44
}
45
};
46
- contextAfterPaginated.result.total = contextAfterPaginated.result.data.length;
47
});
48
49
it('Hook exists', () => {
50
assert(typeof skipRemainingHooks === 'function', 'Hook is not a function.');
51
});
52
53
- it('???', () => {
54
- contextBefore.method = 'create';
55
- assert(true);
56
57
- /*
58
- skipRemainingHooks()(contextBefore);
59
60
- assert.deepEqual(contextBefore.data, {
61
62
});
63
- */
64
});
65
});
1
2
const assert = require('assert');
3
+ const SKIP = require('@feathersjs/feathers').SKIP;
4
const skipRemainingHooks = require('../../src/hooks/skip-remaining-hooks');
5
6
describe('Test /hooks/skip-remaining-hooks.unit.test.js', () => {
7
+ let contextBefore, contextAfter;
8
9
beforeEach(() => {
10
contextBefore = {
11
type: 'before',
12
params: { provider: 'socketio' },
13
data: {
14
+ first: 'John', last: 'Doe'
15
}
16
};
17
19
type: 'after',
20
params: { provider: 'socketio' },
21
result: {
22
+ first: 'Jane', last: 'Doe'
23
}
24
};
25
});
26
27
it('Hook exists', () => {
28
assert(typeof skipRemainingHooks === 'function', 'Hook is not a function.');
29
});
30
31
+ describe('Predicate is not a function', () => {
32
+ it('False returns context', () => {
33
+ const result = skipRemainingHooks(false)(contextBefore);
34
+ assert.equal(result, contextBefore);
35
+ });
36
37
+ it('True returns SKIP token', () => {
38
+ const result = skipRemainingHooks(true)(contextBefore);
39
+ assert.equal(result, SKIP);
40
+ });
41
+ });
42
43
+ describe('Predicate is a function', () => {
44
+ it('False returns context', () => {
45
+ const result = skipRemainingHooks(() => false)(contextBefore);
46
+ assert.equal(result, contextBefore);
47
+ });
48
+
49
+ it('True returns SKIP token', () => {
50
+ const result = skipRemainingHooks(() => true)(contextBefore);
51
+ assert.equal(result, SKIP);
52
+ });
53
+ });
54
55
+ describe('Default predicate is "context => !!context.result"', () => {
56
+ it('No context.result', () => {
57
+ const result = skipRemainingHooks()(contextBefore);
58
+ assert.equal(result, contextBefore);
59
+ });
60
+
61
+ it('Has context.result', () => {
62
+ const result = skipRemainingHooks()(contextAfter);
63
+ assert.equal(result, SKIP);
64
});
65
});
66
});
67
+
68
+