1+ import * as JSData from 'js-data'
2+
13describe ( 'MongoDBAdapter#find' , function ( ) {
24 var adapter
35
4- // create a record to test update against
5- before ( function ( ) {
6- // var id
7-
8- // adapter = this.$$adapter
9- // User = this.$$user
10-
11- // return adapter.findAll(User, {
12- // name: 'John'
13- // }).then(function (users) {
14- // assert.equal(users.length, 0)
15- // return adapter.create(User, {name: 'John'})
16- // }).then(function (user) {
17- // id = user._id
18- // return adapter.find(User, id.toString())
19- // }).then(function (user) {
20- // assert.objectsEqual(user, {_id: id, name: 'John'})
21- // })
22- } )
23-
246 beforeEach ( function ( ) {
257 adapter = this . $$adapter
268 // User = this.$$user
@@ -29,4 +11,33 @@ describe('MongoDBAdapter#find', function () {
2911 it ( 'should not support updateMany' , function ( ) {
3012 return assert . throws ( adapter . updateMany )
3113 } )
14+
15+ it ( 'should ignore undefined when resource has schema' , function ( ) {
16+ var id
17+
18+ const schema = new JSData . Schema ( {
19+ 'type' : 'object' ,
20+ 'properties' : {
21+ 'name' : {
22+ 'type' : 'string'
23+ } ,
24+ 'b' : {
25+ 'type' : 'string'
26+ }
27+ }
28+ } )
29+ const User = this . $$store . defineMapper ( 'user' , { schema : schema } )
30+
31+ return adapter . findAll ( User , {
32+ name : 'John'
33+ } ) . then ( function ( users ) {
34+ assert . equal ( users . length , 0 )
35+ return adapter . create ( User , { name : 'John' } )
36+ } ) . then ( function ( user ) {
37+ id = user . _id
38+ return adapter . find ( User , id . toString ( ) )
39+ } ) . then ( function ( user ) {
40+ assert . objectsEqual ( user , { _id : id , name : 'John' } )
41+ } )
42+ } )
3243} )
0 commit comments