@@ -5,56 +5,60 @@ const rsqlMongoDB = require('./');
5
5
6
6
describe ( 'rsql-mongodb' , function ( ) {
7
7
it ( "Test operator Equal To ('==')" , function ( ) {
8
- assert . equal ( rsqlMongoDB ( 'lastName=="doe"' ) , ' { "lastName" : "doe" }' ) ;
9
- assert . equal ( rsqlMongoDB ( 'birthday=="1959-10-21"' ) , ' { "birthday" : "1959-10-21" }' ) ;
10
- assert . equal ( rsqlMongoDB ( 'birthday==1959-10-21' ) , '{ "birthday" : new Date("1959-10-21") } ') ;
11
- assert . equal ( rsqlMongoDB ( 'married==true' ) , ' { "married" : true }' ) ;
12
- assert . equal ( rsqlMongoDB ( 'childs==2' ) , ' { "childs" : 2 }' ) ;
8
+ expect ( rsqlMongoDB ( 'lastName=="doe"' ) ) . to . deep . include ( { "lastName" : "doe" } ) ;
9
+ expect ( rsqlMongoDB ( 'birthday=="1959-10-21"' ) ) . to . deep . include ( { "birthday" : "1959-10-21" } ) ;
10
+ expect ( rsqlMongoDB ( 'birthday==1959-10-21' ) ) . to . be . a ( 'object ') ;
11
+ expect ( rsqlMongoDB ( 'married==true' ) ) . to . deep . include ( { "married" : true } ) ;
12
+ expect ( rsqlMongoDB ( 'childs==2' ) ) . to . deep . include ( { "childs" : 2 } ) ;
13
13
} ) ;
14
14
it ( "Test operator Not Equal To ('!=')" , function ( ) {
15
- assert . equal ( rsqlMongoDB ( 'lastName!="doe"' ) , '{ "lastName": { $ne: "doe" } }' ) ;
16
- assert . equal ( rsqlMongoDB ( 'birthday!="1959-10-21"' ) , '{ "birthday": { $ne: "1959-10-21" } }' ) ;
17
- assert . equal ( rsqlMongoDB ( 'birthday!=1959-10-21' ) , '{ "birthday": { $ne: new Date("1959-10-21") } }' ) ;
18
- assert . equal ( rsqlMongoDB ( 'married!=true' ) , '{ "married": { $ne: true } }' ) ;
19
- assert . equal ( rsqlMongoDB ( 'childs!=2' ) , '{ "childs": { $ne: 2 } }' ) ;
15
+ expect ( rsqlMongoDB ( 'lastName!="doe"' ) ) . to . deep . include ( { "lastName" : { $ne : "doe" } } ) ;
16
+ expect ( rsqlMongoDB ( 'birthday!="1959-10-21"' ) ) . to . deep . include ( { "birthday" : { $ne : "1959-10-21" } } ) ;
17
+ expect ( rsqlMongoDB ( 'birthday!=1959-10-21' ) ) . to . be . a ( 'object' ) ;
18
+ expect ( rsqlMongoDB ( 'married!=true' ) ) . to . deep . include ( { "married" : { $ne : true } } ) ;
19
+ expect ( rsqlMongoDB ( 'childs!=2' ) ) . to . deep . include ( { "childs" : { $ne : 2 } } ) ;
20
+
20
21
} ) ;
21
22
it ( "Test operator Greater Than ('=gt=')" , function ( ) {
22
- assert . equal ( rsqlMongoDB ( 'birthday=gt="1959-10-21"' ) , ' { "birthday": { $gt: "1959-10-21" } }' ) ;
23
- assert . equal ( rsqlMongoDB ( 'birthday=gt=1959-10-21' ) , '{ "birthday": { $gt: new Date("1959-10-21") } } ') ;
24
- assert . equal ( rsqlMongoDB ( 'childs=gt=2' ) , ' { "childs": { $gt: 2 } }' ) ;
23
+ expect ( rsqlMongoDB ( 'birthday=gt="1959-10-21"' ) ) . to . deep . include ( { "birthday" : { $gt : "1959-10-21" } } ) ;
24
+ expect ( rsqlMongoDB ( 'birthday=gt=1959-10-21' ) ) . to . be . a ( 'object ') ;
25
+ expect ( rsqlMongoDB ( 'childs=gt=2' ) ) . to . deep . include ( { "childs" : { $gt : 2 } } ) ;
25
26
} ) ;
26
27
it ( "Test operator Greater Or Equal To ('=ge=')" , function ( ) {
27
- assert . equal ( rsqlMongoDB ( 'birthday=ge="1959-10-21"' ) , ' { "birthday": { $gte: "1959-10-21" } }' ) ;
28
- assert . equal ( rsqlMongoDB ( 'birthday=ge=1959-10-21' ) , '{ "birthday": { $gte: new Date("1959-10-21") } } ') ;
29
- assert . equal ( rsqlMongoDB ( 'childs=ge=2' ) , ' { "childs": { $gte: 2 } }' ) ;
28
+ expect ( rsqlMongoDB ( 'birthday=ge="1959-10-21"' ) ) . to . deep . include ( { "birthday" : { $gte : "1959-10-21" } } ) ;
29
+ expect ( rsqlMongoDB ( 'birthday=ge=1959-10-21' ) ) . to . be . a ( 'object ') ;
30
+ expect ( rsqlMongoDB ( 'childs=ge=2' ) ) . to . deep . include ( { "childs" : { $gte : 2 } } ) ;
30
31
} ) ;
31
32
it ( "Test operator Less Than ('=lt=')" , function ( ) {
32
- assert . equal ( rsqlMongoDB ( 'birthday=lt="1959-10-21"' ) , ' { "birthday": { $lt: "1959-10-21" } }' ) ;
33
- assert . equal ( rsqlMongoDB ( 'birthday=lt=1959-10-21' ) , '{ "birthday": { $lt: new Date("1959-10-21") } } ') ;
34
- assert . equal ( rsqlMongoDB ( 'childs=lt=2' ) , ' { "childs": { $lt: 2 } }' ) ;
33
+ expect ( rsqlMongoDB ( 'birthday=lt="1959-10-21"' ) ) . to . deep . include ( { "birthday" : { $lt : "1959-10-21" } } ) ;
34
+ expect ( rsqlMongoDB ( 'birthday=lt=1959-10-21' ) ) . to . be . a ( 'object ') ;
35
+ expect ( rsqlMongoDB ( 'childs=lt=2' ) ) . to . deep . include ( { "childs" : { $lt : 2 } } ) ;
35
36
} ) ;
36
37
it ( "Test operator Less Or Equal To ('=le=')" , function ( ) {
37
- assert . equal ( rsqlMongoDB ( 'birthday=le="1959-10-21"' ) , ' { "birthday": { $lte: "1959-10-21" } }' ) ;
38
- assert . equal ( rsqlMongoDB ( 'birthday=le=1959-10-21' ) , '{ "birthday": { $lte: new Date("1959-10-21") } } ') ;
39
- assert . equal ( rsqlMongoDB ( 'childs=le=2' ) , ' { "childs": { $lte: 2 } }' ) ;
38
+ expect ( rsqlMongoDB ( 'birthday=le="1959-10-21"' ) ) . to . deep . include ( { "birthday" : { $lte : "1959-10-21" } } ) ;
39
+ expect ( rsqlMongoDB ( 'birthday=le=1959-10-21' ) ) . to . be . a ( 'object ') ;
40
+ expect ( rsqlMongoDB ( 'childs=le=2' ) ) . to . deep . include ( { "childs" : { $lte : 2 } } ) ;
40
41
} ) ;
41
42
it ( "Test operator In ('=in=')" , function ( ) {
42
- assert . equal ( rsqlMongoDB ( 'childs=in=(1,2,3)' ) , '{ "childs": { $in: [1,2,3] } }' ) ;
43
+ expect ( rsqlMongoDB ( 'childs=in=(1,2,3)' ) ) . to . deep . include ( { "childs" : { $in : [ 1 , 2 , 3 ] } } ) ;
44
+ expect ( rsqlMongoDB ( 'childs=in=("1","2","3")' ) ) . to . deep . include ( { "childs" : { $in : [ "1" , "2" , "3" ] } } ) ;
43
45
} ) ;
44
46
it ( "Test operator Out ('=out=')" , function ( ) {
45
- assert . equal ( rsqlMongoDB ( 'childs=out=(1,2,3)' ) , '{ "childs": { $nin: [1,2,3] } }' ) ;
47
+ expect ( rsqlMongoDB ( 'childs=out=(1,2,3)' ) ) . to . deep . include ( { "childs" : { $nin : [ 1 , 2 , 3 ] } } ) ;
48
+ expect ( rsqlMongoDB ( 'childs=out=("1","2","3")' ) ) . to . deep . include ( { "childs" : { $nin : [ "1" , "2" , "3" ] } } ) ;
46
49
} ) ;
47
50
it ( "Test logical operator AND (';')" , function ( ) {
48
- assert . equal ( rsqlMongoDB ( 'firstName=="john";lastName=="doe"' ) , ' { $and: [ { "firstName" : "john" } , { "lastName" : "doe" } ] }' ) ;
51
+ expect ( rsqlMongoDB ( 'firstName=="john";lastName=="doe"' ) ) . to . deep . include ( { $and : [ { "firstName" : "john" } , { "lastName" : "doe" } ] } ) ;
49
52
} ) ;
50
53
it ( "Test logical operator OR (',')" , function ( ) {
51
- assert . equal ( rsqlMongoDB ( 'firstName=="john",firstName=="janne"' ) , ' { $or: [ { "firstName" : "john" } , { "firstName" : "janne" } ] }' ) ;
54
+ expect ( rsqlMongoDB ( 'firstName=="john",firstName=="janne"' ) ) . to . deep . include ( { $or : [ { "firstName" : "john" } , { "firstName" : "janne" } ] } ) ;
52
55
} ) ;
53
56
it ( "Test groups" , function ( ) {
54
- assert . equal ( rsqlMongoDB ( '(firstName=="john";lastName=="doe"),(firstName=="janne";lastName=="doe")' ) , '{ $or: [ { $and: [ { "firstName" : "john" } , { "lastName" : "doe" } ] } , { $and: [ { "firstName" : "janne" } , { "lastName" : "doe" } ] } ] }' ) ;
57
+ expect ( rsqlMongoDB ( '(firstName=="john";lastName=="doe"),(firstName=="janne";lastName=="doe")' ) ) . to . deep . include ( { $or : [ { $and : [ { "firstName" : "john" } , { "lastName" : "doe" } ] } , { $and : [ { "firstName" : "janne" } , { "lastName" : "doe" } ] } ] } ) ;
58
+ expect ( rsqlMongoDB ( '(firstName==john;lastName==doe),(firstName=="janne";lastName=="doe")' ) ) . to . deep . include ( { $or : [ { $and : [ { "firstName" : "john" } , { "lastName" : "doe" } ] } , { $and : [ { "firstName" : "janne" } , { "lastName" : "doe" } ] } ] } ) ;
55
59
} ) ;
56
60
it ( "Test errors" , function ( ) {
57
- expect ( function ( ) { rsqlMongoDB ( 'azerty' ) } ) . to . throw ( 'Wrong RSQL query.' ) ;
61
+ expect ( function ( ) { rsqlMongoDB ( 'azerty' ) } ) . to . throw ( 'Wrong RSQL query. No operator found. ' ) ;
58
62
expect ( function ( ) { rsqlMongoDB ( 'firstName=={ $where: [ { lastName : "doe" } ] }' ) } ) . to . throw ( 'Injection detected.' ) ;
59
63
} ) ;
60
64
} ) ;
0 commit comments