@@ -5,39 +5,39 @@ describe('QueryString: Fields', function () {
55
66 context ( 'when query fields are a simple string' , function ( ) {
77 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' }
99 verify ( fields . fields ( query , default_options ) )
1010 done ( )
1111 } )
1212 } )
1313
1414 context ( 'when query fields are an array of strings' , function ( ) {
1515 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' ] }
1717 verify ( fields . fields ( query , default_options ) )
1818 done ( )
1919 } )
2020 } )
2121
2222 context ( 'when there are blank spaces between query fields' , function ( ) {
2323 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' }
2525 verify ( fields . fields ( query , default_options ) )
2626 done ( )
2727 } )
2828 } )
2929
3030 context ( 'when there are null fields in query fields' , function ( ) {
3131 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,,' }
3333 verify ( fields . fields ( query , default_options ) )
3434 done ( )
3535 } )
3636 } )
3737
3838 context ( 'when there are special characters in query fields' , function ( ) {
3939 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 ' }
4141 verify ( fields . fields ( query , default_options ) )
4242 done ( )
4343
@@ -52,17 +52,21 @@ describe('QueryString: Fields', function () {
5252 } )
5353 } )
5454
55- context ( 'when use custom params without query ' , function ( ) {
55+ context ( 'when use custom params' , function ( ) {
5656 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 } } }
5858 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' )
6259 expect ( result . name ) . to . eql ( custom_options . default . fields . name )
6360 expect ( result . age ) . to . eql ( custom_options . default . fields . age )
6461 expect ( result . _id ) . to . eql ( custom_options . default . fields . _id )
62+ } )
6563
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 )
6670 } )
6771 } )
6872} )
0 commit comments