@@ -101,40 +101,58 @@ describe('Cast Tutorial', function() {
101101 await query . exec ( ) ;
102102 } ) ;
103103
104- it ( 'strictQuery true' , async function ( ) {
105- mongoose . deleteModel ( 'Character' ) ;
106- const schema = new mongoose . Schema ( { name : String , age : Number } , {
107- strictQuery : true
104+ describe ( 'strictQuery' , function ( ) {
105+ it ( 'strictQuery true - simple object' , async function ( ) {
106+ mongoose . deleteModel ( 'Character' ) ;
107+ const schema = new mongoose . Schema ( { name : String , age : Number } , {
108+ strictQuery : true
109+ } ) ;
110+ Character = mongoose . model ( 'Character' , schema ) ;
111+
112+ const query = Character . findOne ( { notInSchema : { $lt : 'not a number' } } ) ;
113+
114+ await query . exec ( ) ;
115+ query . getFilter ( ) ; // Empty object `{}`, Mongoose removes `notInSchema`
116+ // acquit:ignore:start
117+ assert . deepEqual ( query . getFilter ( ) , { } ) ;
118+ // acquit:ignore:end
108119 } ) ;
109- Character = mongoose . model ( 'Character' , schema ) ;
110120
111- const query = Character . findOne ( { notInSchema : { $lt : 'not a number' } } ) ;
121+ it ( 'strictQuery true - conditions' , async function ( ) {
122+ mongoose . deleteModel ( 'Character' ) ;
123+ const schema = new mongoose . Schema ( { name : String , age : Number } , {
124+ strictQuery : true
125+ } ) ;
126+ Character = mongoose . model ( 'Character' , schema ) ;
112127
113- await query . exec ( ) ;
114- query . getFilter ( ) ; // Empty object `{}`, Mongoose removes `notInSchema`
115- // acquit:ignore:start
116- assert . deepEqual ( query . getFilter ( ) , { } ) ;
117- // acquit:ignore:end
118- } ) ;
128+ const query = Character . findOne ( { $or : [ { notInSchema : { $lt : 'not a number' } } ] , $and : [ { name : 'abc' } , { age : { $gt : 18 } } , { notInSchema : { $lt : 'not a number' } } ] } ) ;
119129
120- it ( 'strictQuery throw' , async function ( ) {
121- mongoose . deleteModel ( 'Character' ) ;
122- const schema = new mongoose . Schema ( { name : String , age : Number } , {
123- strictQuery : 'throw'
130+ await query . exec ( ) ;
131+ query . getFilter ( ) ; // Empty object `{}`, Mongoose removes `notInSchema`
132+ // acquit:ignore:start
133+ assert . deepEqual ( query . getFilter ( ) , { $and : [ { name : 'abc' } , { age : { $gt : 18 } } ] } ) ;
134+ // acquit:ignore:end
124135 } ) ;
125- Character = mongoose . model ( 'Character' , schema ) ;
126136
127- const query = Character . findOne ( { notInSchema : { $lt : 'not a number' } } ) ;
128-
129- const err = await query . exec ( ) . then ( ( ) => null , err => err ) ;
130- err . name ; // 'StrictModeError'
131- // Path "notInSchema" is not in schema and strictQuery is 'throw'.
132- err . message ;
133- // acquit:ignore:start
134- assert . equal ( err . name , 'StrictModeError' ) ;
135- assert . equal ( err . message , 'Path "notInSchema" is not in schema and ' +
136- 'strictQuery is \'throw\'.' ) ;
137- // acquit:ignore:end
137+ it ( 'strictQuery throw' , async function ( ) {
138+ mongoose . deleteModel ( 'Character' ) ;
139+ const schema = new mongoose . Schema ( { name : String , age : Number } , {
140+ strictQuery : 'throw'
141+ } ) ;
142+ Character = mongoose . model ( 'Character' , schema ) ;
143+
144+ const query = Character . findOne ( { notInSchema : { $lt : 'not a number' } } ) ;
145+
146+ const err = await query . exec ( ) . then ( ( ) => null , err => err ) ;
147+ err . name ; // 'StrictModeError'
148+ // Path "notInSchema" is not in schema and strictQuery is 'throw'.
149+ err . message ;
150+ // acquit:ignore:start
151+ assert . equal ( err . name , 'StrictModeError' ) ;
152+ assert . equal ( err . message , 'Path "notInSchema" is not in schema and ' +
153+ 'strictQuery is \'throw\'.' ) ;
154+ // acquit:ignore:end
155+ } ) ;
138156 } ) ;
139157
140158 it ( 'implicit in' , async function ( ) {
0 commit comments