3
3
JSData ,
4
4
JSDataExpress
5
5
} from './_setup'
6
+ import request from 'supertest'
7
+ import express from 'express'
6
8
7
9
describe ( 'js-data-express' , function ( ) {
8
10
it ( 'should have correct exports' , function ( ) {
@@ -21,4 +23,57 @@ describe('js-data-express', function () {
21
23
assert . equal ( typeof JSDataExpress . parseQuery , 'function' )
22
24
assert . equal ( typeof JSDataExpress . queryParser , 'function' )
23
25
} )
26
+
27
+ it ( 'should use custom router request middleware' , function ( ) {
28
+ const store = new JSData . Container ( )
29
+ const userMapper = store . defineMapper ( 'user' )
30
+ JSDataExpress . Router ( userMapper , {
31
+ request : ( req , res , next ) => { }
32
+ } )
33
+ } )
34
+
35
+ it ( 'should use custom getEndpoint method' , function ( ) {
36
+ const store = new JSData . Container ( )
37
+ store . defineMapper ( 'user' )
38
+ JSDataExpress . Router ( store , {
39
+ getEndpoint : ( mapper ) => { return '/user' }
40
+ } )
41
+ } )
42
+
43
+ it ( 'makeHandler errors should be executed' , function ( ) {
44
+ const _app = express ( )
45
+ const __app = express ( )
46
+ const store = new JSData . Container ( )
47
+ store . defineMapper ( 'user' )
48
+ const _config = {
49
+ 'find' : {
50
+ request : ( req , res , next ) => {
51
+ next ( 'error' )
52
+ }
53
+ }
54
+ }
55
+ const __config = {
56
+ 'find' : {
57
+ action : ( component , req ) => {
58
+ return new Promise ( ( resolve , reject ) => {
59
+ reject ( 'error' )
60
+ } )
61
+ }
62
+ }
63
+ }
64
+
65
+ JSDataExpress . mount ( _app , store , _config )
66
+ JSDataExpress . mount ( __app , store , __config )
67
+
68
+ request ( _app )
69
+ . get ( '/user/abc' )
70
+ . end ( function ( err , response ) {
71
+ if ( err ) { }
72
+ } )
73
+ request ( __app )
74
+ . get ( '/user/abc' )
75
+ . end ( function ( err , response ) {
76
+ if ( err ) { }
77
+ } )
78
+ } )
24
79
} )
0 commit comments