File tree Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 1
1
module . exports = function ( req , res , next ) {
2
- req . appState = req . appState || { } ;
2
+ if ( typeof req . arch === 'undefined' ) throw new Error ( 'request.arch not defined. Use arch default middlewares first.' ) ;
3
+ if ( typeof req . arch . appState === 'undefined' ) throw new Error ( 'request.arch.appState not defined. Use arch default middlewares first.' ) ;
3
4
4
- req . appState . requestInfo = {
5
+ req . arch . appState . requestInfo = {
5
6
ip : req . ip
6
7
} ;
7
8
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " arch-request" ,
3
- "version" : " 1.0.1 " ,
3
+ "version" : " 1.1.0 " ,
4
4
"description" : " Express middleware for arch-server to update application state with request information" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -3,24 +3,42 @@ var middleware = require('../index');
3
3
describe ( "request middleware" , function ( ) {
4
4
it ( "puts the ip address in appState" , function ( done ) {
5
5
var request = {
6
- appState : { } ,
6
+ arch : {
7
+ appState : { }
8
+ } ,
7
9
ip : '127.0.0.1'
8
10
} ;
9
11
10
12
middleware ( request , null , function ( ) {
11
- expect ( request . appState . requestInfo . ip ) . toBe ( request . ip ) ;
13
+ expect ( request . arch . appState . requestInfo . ip ) . toBe ( request . ip ) ;
12
14
done ( ) ;
13
15
} ) ;
14
16
} ) ;
15
17
16
- it ( "creates an appState object when none provided " , function ( done ) {
18
+ it ( "throws when arch not defined " , function ( done ) {
17
19
var request = {
18
20
ip : '127.0.0.1'
19
21
} ;
20
22
21
- middleware ( request , null , function ( ) {
22
- expect ( request . appState ) . toBeDefined ( ) ;
23
+ try {
24
+ middleware ( request , null , fail ) ;
25
+ } catch ( e ) {
26
+ expect ( e . message ) . toEqual ( 'request.arch not defined. Use arch default middlewares first.' )
27
+ done ( ) ;
28
+ }
29
+ } ) ;
30
+
31
+ it ( "throws when arch.appState not defined" , function ( done ) {
32
+ var request = {
33
+ arch : { } ,
34
+ ip : '127.0.0.1'
35
+ } ;
36
+
37
+ try {
38
+ middleware ( request , null , fail ) ;
39
+ } catch ( e ) {
40
+ expect ( e . message ) . toEqual ( 'request.arch.appState not defined. Use arch default middlewares first.' )
23
41
done ( ) ;
24
- } )
42
+ }
25
43
} ) ;
26
44
} ) ;
You can’t perform that action at this time.
0 commit comments