Skip to content

Commit eb0f864

Browse files
committed
move utils to fp
1 parent 5611f2c commit eb0f864

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ function handleKeycloakValidation (tkn, reply) {
8888
*/
8989
function validate (field, reply) {
9090
const tkn = token(field)
91-
fakeReply(reply)
91+
const done = fakeReply(reply)
9292

9393
if (!tkn) {
94-
return reply(error('unauthorized', error.msg.missing))
94+
return done(error('unauthorized', error.msg.missing))
9595
}
9696

9797
cache.get(tkn.get(), (err, cached) => {
9898
const isCached = cached && !err
99-
isCached ? reply.continue(cached) : handleKeycloakValidation(tkn, reply)
99+
isCached ? done.continue(cached) : handleKeycloakValidation(tkn, done)
100100
})
101101
}
102102

src/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ error.msg = {
8989
* error-first but error-less `continue` method.
9090
*
9191
* @param {Function} reply
92+
* @returns {Function} The decorated function
9293
*/
9394
function fakeReply (reply) {
9495
if (!reply.continue) {
9596
reply.continue = reply.bind(undefined, null)
9697
}
98+
99+
return reply
97100
}
98101

99102
module.exports = {

test/utils.spec.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ test('get boom error with error message', (t) => {
2525

2626
test('decorate callback function with `continue`', (t) => {
2727
const mockFn = function () {}
28+
const fake = utils.fakeReply(mockFn)
2829

29-
utils.fakeReply(mockFn)
3030
t.truthy(mockFn.continue)
31+
t.truthy(fake.continue)
32+
t.deepEqual(mockFn, fake)
3133
})
3234

3335
test('ignore callback function with exsting `continue`', (t) => {
3436
const mockFn = function () {}
3537
mockFn.continue = 'foo'
38+
const fake = utils.fakeReply(mockFn)
3639

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)
4043
})
4144

4245
test('throw error if options are empty', (t) => {

0 commit comments

Comments
 (0)