@@ -5,39 +5,39 @@ describe('QueryString: Fields', function () {
5
5
6
6
context ( 'when query fields are a simple string' , function ( ) {
7
7
it ( 'should return a JSON with field params' , function ( done ) {
8
- const query = { fields : 'name,age,created_at' }
8
+ const query = { fields : 'name,age,created_at' }
9
9
verify ( fields . fields ( query , default_options ) )
10
10
done ( )
11
11
} )
12
12
} )
13
13
14
14
context ( 'when query fields are an array of strings' , function ( ) {
15
15
it ( 'should return a JSON with field params' , function ( done ) {
16
- const query = { fields : [ 'name,age' , 'created_at' ] }
16
+ const query = { fields : [ 'name,age' , 'created_at' ] }
17
17
verify ( fields . fields ( query , default_options ) )
18
18
done ( )
19
19
} )
20
20
} )
21
21
22
22
context ( 'when there are blank spaces between query fields' , function ( ) {
23
23
it ( 'should return a JSON with field params, ignoring the blank space' , function ( done ) {
24
- const query = { fields : ' name , name, age , created_at' }
24
+ const query = { fields : ' name , name, age , created_at' }
25
25
verify ( fields . fields ( query , default_options ) )
26
26
done ( )
27
27
} )
28
28
} )
29
29
30
30
context ( 'when there are null fields in query fields' , function ( ) {
31
31
it ( 'should return a JSON with field params, ignoring the null fields' , function ( done ) {
32
- const query = { fields : ',,name,,,age,,,,,created_at,,' }
32
+ const query = { fields : ',,name,,,age,,,,,created_at,,' }
33
33
verify ( fields . fields ( query , default_options ) )
34
34
done ( )
35
35
} )
36
36
} )
37
37
38
38
context ( 'when there are special characters in query fields' , function ( ) {
39
39
it ( 'should return a JSON with field params, ignoring the special characteres' , function ( done ) {
40
- const query = { fields : ' ,,, ^ & * ( ´) @!n@a"m "e,$%ag" e",created _a t ' }
40
+ const query = { fields : ' ,,, ^ & * ( ´) @!n@a"m "e,$%ag" e",created _a t ' }
41
41
verify ( fields . fields ( query , default_options ) )
42
42
done ( )
43
43
@@ -52,17 +52,21 @@ describe('QueryString: Fields', function () {
52
52
} )
53
53
} )
54
54
55
- context ( 'when use custom params without query ' , function ( ) {
55
+ context ( 'when use custom params' , function ( ) {
56
56
it ( 'should return a JSON with custom params' , function ( ) {
57
- const custom_options = { default : { fields : { name : 1 , age : 1 , _id : 0 } } }
57
+ const custom_options = { default : { fields : { name : 1 , age : 1 , _id : 0 } } }
58
58
const result = fields . fields ( { } , custom_options )
59
- expect ( result ) . to . have . property ( 'name' )
60
- expect ( result ) . to . have . property ( 'age' )
61
- expect ( result ) . to . have . property ( '_id' )
62
59
expect ( result . name ) . to . eql ( custom_options . default . fields . name )
63
60
expect ( result . age ) . to . eql ( custom_options . default . fields . age )
64
61
expect ( result . _id ) . to . eql ( custom_options . default . fields . _id )
62
+ } )
65
63
64
+ it ( 'should return a JSON with custom params and those of the query' , function ( ) {
65
+ const custom_options = { default : { fields : { name : 1 , _id : 1 } } }
66
+ const result = fields . fields ( { fields : 'age' } , custom_options )
67
+ expect ( result . name ) . to . eql ( custom_options . default . fields . name )
68
+ expect ( result . _id ) . to . eql ( custom_options . default . fields . _id )
69
+ expect ( result . age ) . to . eql ( 1 )
66
70
} )
67
71
} )
68
72
} )
0 commit comments