@@ -2,42 +2,42 @@ const expect = require('chai').expect
2
2
const ordination = require ( '../../lib/mapper/ordination' )
3
3
4
4
describe ( 'QueryString: Ordination' , function ( ) {
5
-
5
+
6
6
context ( 'when ordination query is a simple string' , function ( ) {
7
7
it ( 'should return a JSON with order params' , function ( done ) {
8
- verify ( ordination . sort ( { sort : '-name,age,created_at' } , default_options ) )
8
+ verify ( ordination . sort ( { sort : '-name,age,created_at' } , default_options ) )
9
9
done ( )
10
10
} )
11
11
} )
12
12
13
13
context ( 'when ordination query is an array of strings' , function ( ) {
14
14
it ( 'should return a JSON with order params' , function ( done ) {
15
- verify ( ordination . sort ( { sort : [ '-name,age' , 'created_at' ] } , default_options ) )
15
+ verify ( ordination . sort ( { sort : [ '-name,age' , 'created_at' ] } , default_options ) )
16
16
done ( )
17
17
} )
18
18
} )
19
19
20
20
context ( 'when there are blank spaces between ordination query' , function ( ) {
21
21
it ( 'should return a JSON with order params, ignoring the blank space' , function ( done ) {
22
- verify ( ordination . sort ( { sort : '-na m e, age, cr eat ed_at' } , default_options ) )
22
+ verify ( ordination . sort ( { sort : '-na m e, age, cr eat ed_at' } , default_options ) )
23
23
done ( )
24
24
} )
25
25
} )
26
26
27
27
context ( 'when there are null fields in ordination query' , function ( ) {
28
28
it ( 'should return a JSON with order params, ignoring the null fields' , function ( done ) {
29
- verify ( ordination . sort ( { sort : ',,,,,-name,,,,age,,,created_at,,,,,,,' } , default_options ) )
29
+ verify ( ordination . sort ( { sort : ',,,,,-name,,,,age,,,created_at,,,,,,,' } , default_options ) )
30
30
done ( )
31
31
} )
32
32
} )
33
33
34
34
context ( 'when there are special characters in ordination query' , function ( ) {
35
35
it ( 'should return a JSON with order params, ignoring the special characteres' , function ( done ) {
36
- verify ( ordination . sort ( { sort : '-$%n@am#$e??,!!ag%e,c***r$@$eated_at' } , default_options ) )
36
+ verify ( ordination . sort ( { sort : '-$%n@am#$e??,!!ag%e,c***r$@$eated_at' } , default_options ) )
37
37
done ( )
38
38
} )
39
39
40
- } )
40
+ } )
41
41
42
42
context ( 'when use the default options without query' , function ( ) {
43
43
it ( 'should return a JSON with default ordination params' , function ( done ) {
@@ -48,16 +48,23 @@ describe('QueryString: Ordination', function () {
48
48
} )
49
49
} )
50
50
51
- context ( 'when use custom params without query ' , function ( ) {
51
+ context ( 'when use custom params' , function ( ) {
52
52
it ( 'should return a JSON with custom params' , function ( ) {
53
- const custom_options = { default : { sort : { created_at : 'asc' } } }
53
+ const custom_options = { default : { sort : { created_at : 'asc' } } }
54
54
const result = ordination . sort ( { } , custom_options )
55
55
expect ( result ) . is . not . null
56
56
expect ( result ) . to . have . property ( 'created_at' )
57
57
expect ( result . created_at ) . to . eql ( 'asc' )
58
58
} )
59
- } )
60
59
60
+ it ( 'should return a JSON with custom parameters and those of the query' , function ( ) {
61
+ const custom_options = { default : { sort : { created_at : 'asc' } } }
62
+ const result = ordination . sort ( { sort : '-created_at,-age,name' } , custom_options )
63
+ expect ( result . created_at ) . to . eql ( 'desc' )
64
+ expect ( result . age ) . to . eql ( 'desc' )
65
+ expect ( result . name ) . to . eql ( 'asc' )
66
+ } )
67
+ } )
61
68
} )
62
69
63
70
function verify ( result ) {
@@ -68,4 +75,4 @@ function verify(result) {
68
75
expect ( result . age ) . to . eql ( 'asc' )
69
76
expect ( result . created_at ) . to . eql ( 'asc' )
70
77
71
- }
78
+ }
0 commit comments