File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -88,15 +88,15 @@ function handleKeycloakValidation (tkn, reply) {
88
88
*/
89
89
function validate ( field , reply ) {
90
90
const tkn = token ( field )
91
- fakeReply ( reply )
91
+ const done = fakeReply ( reply )
92
92
93
93
if ( ! tkn ) {
94
- return reply ( error ( 'unauthorized' , error . msg . missing ) )
94
+ return done ( error ( 'unauthorized' , error . msg . missing ) )
95
95
}
96
96
97
97
cache . get ( tkn . get ( ) , ( err , cached ) => {
98
98
const isCached = cached && ! err
99
- isCached ? reply . continue ( cached ) : handleKeycloakValidation ( tkn , reply )
99
+ isCached ? done . continue ( cached ) : handleKeycloakValidation ( tkn , done )
100
100
} )
101
101
}
102
102
Original file line number Diff line number Diff line change @@ -89,11 +89,14 @@ error.msg = {
89
89
* error-first but error-less `continue` method.
90
90
*
91
91
* @param {Function } reply
92
+ * @returns {Function } The decorated function
92
93
*/
93
94
function fakeReply ( reply ) {
94
95
if ( ! reply . continue ) {
95
96
reply . continue = reply . bind ( undefined , null )
96
97
}
98
+
99
+ return reply
97
100
}
98
101
99
102
module . exports = {
Original file line number Diff line number Diff line change @@ -25,18 +25,21 @@ test('get boom error with error message', (t) => {
25
25
26
26
test ( 'decorate callback function with `continue`' , ( t ) => {
27
27
const mockFn = function ( ) { }
28
+ const fake = utils . fakeReply ( mockFn )
28
29
29
- utils . fakeReply ( mockFn )
30
30
t . truthy ( mockFn . continue )
31
+ t . truthy ( fake . continue )
32
+ t . deepEqual ( mockFn , fake )
31
33
} )
32
34
33
35
test ( 'ignore callback function with exsting `continue`' , ( t ) => {
34
36
const mockFn = function ( ) { }
35
37
mockFn . continue = 'foo'
38
+ const fake = utils . fakeReply ( mockFn )
36
39
37
- utils . fakeReply ( mockFn )
38
- t . truthy ( mockFn . continue )
39
- t . is ( mockFn . continue , 'foo' )
40
+ t . truthy ( fake . continue )
41
+ t . is ( fake . continue , 'foo' )
42
+ t . deepEqual ( mockFn , fake )
40
43
} )
41
44
42
45
test ( 'throw error if options are empty' , ( t ) => {
You can’t perform that action at this time.
0 commit comments