Commit d2e8d75 Michael A. Plikk
committed
1 parent 2721844 commit d2e8d75 Copy full SHA for d2e8d75
File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ module.exports = {
9
9
const data = { version : options . version } ;
10
10
options . pre = options . pre || [ ] ;
11
11
12
+ const cb = typeof options . callback === 'function' ? options . callback : ( data ) => data ;
13
+
12
14
if ( ! options . revisionFile ) {
13
15
return done ( data ) ;
14
16
}
@@ -30,7 +32,7 @@ module.exports = {
30
32
config : {
31
33
auth : false ,
32
34
handler ( ) {
33
- return data ;
35
+ return cb ( data ) ;
34
36
} ,
35
37
pre : options . pre ,
36
38
description : 'Show status' ,
Original file line number Diff line number Diff line change @@ -31,4 +31,34 @@ describe('Status Route Plugin', () => {
31
31
res . statusCode . should . equal ( 200 ) ;
32
32
res . result . should . have . property ( 'version' , '1.0.0' ) ;
33
33
} ) ;
34
+
35
+ it ( 'should support callback to modify data' , async ( ) => {
36
+ const srv = new Hapi . Server ( { debug : { request : '*' } } ) ;
37
+ await srv . register ( {
38
+ plugin,
39
+ options : {
40
+ version : '1.0.0' ,
41
+ callback : ( data ) => {
42
+ data . count = n ;
43
+ return data ;
44
+ }
45
+ }
46
+ } ) ;
47
+ let n = 1 ;
48
+ const options = {
49
+ method : 'GET' ,
50
+ url : '/status'
51
+ } ;
52
+
53
+ let res = await srv . inject ( options ) ;
54
+ res . statusCode . should . equal ( 200 ) ;
55
+ res . result . should . have . property ( 'version' , '1.0.0' ) ;
56
+ res . result . should . have . property ( 'count' , 1 ) ;
57
+
58
+ n = 2 ;
59
+ res = await srv . inject ( options ) ;
60
+ res . statusCode . should . equal ( 200 ) ;
61
+ res . result . should . have . property ( 'version' , '1.0.0' ) ;
62
+ res . result . should . have . property ( 'count' , 2 ) ;
63
+ } ) ;
34
64
} ) ;
You can’t perform that action at this time.
0 commit comments