@@ -149,7 +149,7 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
149
149
} ) ;
150
150
} ) ;
151
151
152
- it ( 'handles array, object, date' , ( done ) => {
152
+ it ( 'handles creating an array, object, date' , ( done ) => {
153
153
let adapter = new MongoStorageAdapter ( { uri : databaseURI } ) ;
154
154
let obj = {
155
155
array : [ 1 , 2 , 3 ] ,
@@ -189,4 +189,52 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
189
189
done ( ) ;
190
190
} ) ;
191
191
} ) ;
192
+
193
+ it ( "handles updating a single object with array, object date" , ( done ) => {
194
+ let adapter = new MongoStorageAdapter ( { uri : databaseURI } ) ;
195
+
196
+ let schema = { fields : {
197
+ array : { type : 'Array' } ,
198
+ object : { type : 'Object' } ,
199
+ date : { type : 'Date' } ,
200
+ } } ;
201
+
202
+
203
+ adapter . createObject ( 'MyClass' , schema , { } )
204
+ . then ( ( ) => adapter . _rawFind ( 'MyClass' , { } ) )
205
+ . then ( results => {
206
+ expect ( results . length ) . toEqual ( 1 ) ;
207
+ let update = {
208
+ array : [ 1 , 2 , 3 ] ,
209
+ object : { foo : 'bar' } ,
210
+ date : {
211
+ __type : 'Date' ,
212
+ iso : '2016-05-26T20:55:01.154Z' ,
213
+ } ,
214
+ } ;
215
+ let query = { } ;
216
+ return adapter . findOneAndUpdate ( 'MyClass' , schema , query , update )
217
+ } )
218
+ . then ( results => {
219
+ let mob = results ;
220
+ expect ( mob . array instanceof Array ) . toBe ( true ) ;
221
+ expect ( typeof mob . object ) . toBe ( 'object' ) ;
222
+ expect ( mob . date . __type ) . toBe ( 'Date' ) ;
223
+ expect ( mob . date . iso ) . toBe ( '2016-05-26T20:55:01.154Z' ) ;
224
+ return adapter . _rawFind ( 'MyClass' , { } ) ;
225
+ } )
226
+ . then ( results => {
227
+ expect ( results . length ) . toEqual ( 1 ) ;
228
+ let mob = results [ 0 ] ;
229
+ expect ( mob . array instanceof Array ) . toBe ( true ) ;
230
+ expect ( typeof mob . object ) . toBe ( 'object' ) ;
231
+ expect ( mob . date instanceof Date ) . toBe ( true ) ;
232
+ done ( ) ;
233
+ } )
234
+ . catch ( error => {
235
+ console . log ( error ) ;
236
+ fail ( ) ;
237
+ done ( ) ;
238
+ } ) ;
239
+ } ) ;
192
240
} ) ;
0 commit comments