This commit is contained in:
committed by
Florent Vilmart
parent
4ea455b20a
commit
1eff210a51
@@ -149,7 +149,7 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles array, object, date', (done) => {
|
it('handles creating an array, object, date', (done) => {
|
||||||
let adapter = new MongoStorageAdapter({ uri: databaseURI });
|
let adapter = new MongoStorageAdapter({ uri: databaseURI });
|
||||||
let obj = {
|
let obj = {
|
||||||
array: [1, 2, 3],
|
array: [1, 2, 3],
|
||||||
@@ -189,4 +189,52 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("handles updating a single object with array, object date", (done) => {
|
||||||
|
let adapter = new MongoStorageAdapter({ uri: databaseURI });
|
||||||
|
|
||||||
|
let schema = { fields: {
|
||||||
|
array: { type: 'Array' },
|
||||||
|
object: { type: 'Object' },
|
||||||
|
date: { type: 'Date' },
|
||||||
|
} };
|
||||||
|
|
||||||
|
|
||||||
|
adapter.createObject('MyClass', schema, {})
|
||||||
|
.then(() => adapter._rawFind('MyClass', {}))
|
||||||
|
.then(results => {
|
||||||
|
expect(results.length).toEqual(1);
|
||||||
|
let update = {
|
||||||
|
array: [1, 2, 3],
|
||||||
|
object: {foo: 'bar'},
|
||||||
|
date: {
|
||||||
|
__type: 'Date',
|
||||||
|
iso: '2016-05-26T20:55:01.154Z',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let query = {};
|
||||||
|
return adapter.findOneAndUpdate('MyClass', schema, query, update)
|
||||||
|
})
|
||||||
|
.then(results => {
|
||||||
|
let mob = results;
|
||||||
|
expect(mob.array instanceof Array).toBe(true);
|
||||||
|
expect(typeof mob.object).toBe('object');
|
||||||
|
expect(mob.date.__type).toBe('Date');
|
||||||
|
expect(mob.date.iso).toBe('2016-05-26T20:55:01.154Z');
|
||||||
|
return adapter._rawFind('MyClass', {});
|
||||||
|
})
|
||||||
|
.then(results => {
|
||||||
|
expect(results.length).toEqual(1);
|
||||||
|
let mob = results[0];
|
||||||
|
expect(mob.array instanceof Array).toBe(true);
|
||||||
|
expect(typeof mob.object).toBe('object');
|
||||||
|
expect(mob.date instanceof Date).toBe(true);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log(error);
|
||||||
|
fail();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ export class MongoStorageAdapter {
|
|||||||
const mongoWhere = transformWhere(className, query, schema);
|
const mongoWhere = transformWhere(className, query, schema);
|
||||||
return this._adaptiveCollection(className)
|
return this._adaptiveCollection(className)
|
||||||
.then(collection => collection._mongoCollection.findAndModify(mongoWhere, [], mongoUpdate, { new: true }))
|
.then(collection => collection._mongoCollection.findAndModify(mongoWhere, [], mongoUpdate, { new: true }))
|
||||||
.then(result => result.value);
|
.then(result => mongoObjectToParseObject(className, result.value, schema));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hopefully we can get rid of this. It's only used for config and hooks.
|
// Hopefully we can get rid of this. It's only used for config and hooks.
|
||||||
|
|||||||
Reference in New Issue
Block a user