Remove mongoFind and mostly remove adaptiveCollection (#1924)
* Use adapter.count * use adapter.upsertOneObject * Use adapter.deleteObjectsByQuery * Use adapter.find * use adapter.find * Update tests to avoid mongoFind * Fix a test to not use mongoFind * Fix a test to not use mongoFind * remove some mongoFind * Remove some mongoFind * Remove some mongoFind * Remove more mongoFind * remove more mongoFind * remove more mongoFind * remove more mongoFind * remove more mongoFind * remove more mongoFind * remove more mongoFind * remove more mongoFind * remove more mongoFind * Restore update ios device token with duplicate device token to original * remove a mongoFind * remove a mongoFind * formatting * formatting * remove a mongoFind * remove a mongoFind * remove a mongoFind * kill mongoFind * Fix tests * Fix tests * fix syntax * Fix test
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
// These tests check the "create" / "update" functionality of the REST API.
|
||||
var auth = require('../src/Auth');
|
||||
var cache = require('../src/cache');
|
||||
@@ -11,65 +12,69 @@ var config = new Config('test');
|
||||
var database = DatabaseAdapter.getDatabaseConnection('test', 'test_');
|
||||
|
||||
describe('rest create', () => {
|
||||
it('handles _id', (done) => {
|
||||
rest.create(config, auth.nobody(config), 'Foo', {}).then(() => {
|
||||
return database.mongoFind('Foo', {});
|
||||
}).then((results) => {
|
||||
it('handles _id', done => {
|
||||
rest.create(config, auth.nobody(config), 'Foo', {})
|
||||
.then(() => database.adapter.find('Foo', {}, { fields: {} }, {}))
|
||||
.then(results => {
|
||||
expect(results.length).toEqual(1);
|
||||
var obj = results[0];
|
||||
expect(typeof obj._id).toEqual('string');
|
||||
expect(obj.objectId).toBeUndefined();
|
||||
expect(typeof obj.objectId).toEqual('string');
|
||||
expect(obj._id).toBeUndefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles array, object, date', (done) => {
|
||||
let now = new Date();
|
||||
var obj = {
|
||||
array: [1, 2, 3],
|
||||
object: {foo: 'bar'},
|
||||
date: Parse._encode(new Date()),
|
||||
date: Parse._encode(now),
|
||||
};
|
||||
rest.create(config, auth.nobody(config), 'MyClass', obj).then(() => {
|
||||
return database.mongoFind('MyClass', {}, {});
|
||||
}).then((results) => {
|
||||
rest.create(config, auth.nobody(config), 'MyClass', obj)
|
||||
.then(() => database.adapter.find('MyClass', {}, { fields: {
|
||||
array: { type: 'Array' },
|
||||
object: { type: 'Object' },
|
||||
date: { type: 'Date' },
|
||||
} }, {}))
|
||||
.then(results => {
|
||||
expect(results.length).toEqual(1);
|
||||
var mob = results[0];
|
||||
expect(mob.array instanceof Array).toBe(true);
|
||||
expect(typeof mob.object).toBe('object');
|
||||
expect(mob.date instanceof Date).toBe(true);
|
||||
expect(mob.date.__type).toBe('Date');
|
||||
expect(new Date(mob.date.iso).getTime()).toBe(now.getTime());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles object and subdocument', (done) => {
|
||||
var obj = {
|
||||
subdoc: {foo: 'bar', wu: 'tan'},
|
||||
};
|
||||
rest.create(config, auth.nobody(config), 'MyClass', obj).then(() => {
|
||||
return database.mongoFind('MyClass', {}, {});
|
||||
}).then((results) => {
|
||||
it('handles object and subdocument', done => {
|
||||
let obj = { subdoc: {foo: 'bar', wu: 'tan'} };
|
||||
rest.create(config, auth.nobody(config), 'MyClass', obj)
|
||||
.then(() => database.adapter.find('MyClass', {}, { fields: {} }, {}))
|
||||
.then(results => {
|
||||
expect(results.length).toEqual(1);
|
||||
var mob = results[0];
|
||||
let mob = results[0];
|
||||
expect(typeof mob.subdoc).toBe('object');
|
||||
expect(mob.subdoc.foo).toBe('bar');
|
||||
expect(mob.subdoc.wu).toBe('tan');
|
||||
expect(typeof mob._id).toEqual('string');
|
||||
|
||||
var obj = {
|
||||
'subdoc.wu': 'clan',
|
||||
};
|
||||
|
||||
rest.update(config, auth.nobody(config), 'MyClass', mob._id, obj).then(() => {
|
||||
return database.mongoFind('MyClass', {}, {});
|
||||
}).then((results) => {
|
||||
expect(results.length).toEqual(1);
|
||||
var mob = results[0];
|
||||
expect(typeof mob.subdoc).toBe('object');
|
||||
expect(mob.subdoc.foo).toBe('bar');
|
||||
expect(mob.subdoc.wu).toBe('clan');
|
||||
done();
|
||||
});
|
||||
|
||||
expect(typeof mob.objectId).toEqual('string');
|
||||
let obj = { 'subdoc.wu': 'clan' };
|
||||
return rest.update(config, auth.nobody(config), 'MyClass', mob.objectId, obj)
|
||||
})
|
||||
.then(() => database.adapter.find('MyClass', {}, { fields: {} }, {}))
|
||||
.then(results => {
|
||||
expect(results.length).toEqual(1);
|
||||
let mob = results[0];
|
||||
expect(typeof mob.subdoc).toBe('object');
|
||||
expect(mob.subdoc.foo).toBe('bar');
|
||||
expect(mob.subdoc.wu).toBe('clan');
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
fail();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -240,8 +245,8 @@ describe('rest create', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('stores pointers with a _p_ prefix', (done) => {
|
||||
var obj = {
|
||||
it('stores pointers', done => {
|
||||
let obj = {
|
||||
foo: 'bar',
|
||||
aPointer: {
|
||||
__type: 'Pointer',
|
||||
@@ -250,17 +255,23 @@ describe('rest create', () => {
|
||||
}
|
||||
};
|
||||
rest.create(config, auth.nobody(config), 'APointerDarkly', obj)
|
||||
.then((r) => {
|
||||
return database.mongoFind('APointerDarkly', {});
|
||||
}).then((results) => {
|
||||
expect(results.length).toEqual(1);
|
||||
var output = results[0];
|
||||
expect(typeof output._id).toEqual('string');
|
||||
expect(typeof output._p_aPointer).toEqual('string');
|
||||
expect(output._p_aPointer).toEqual('JustThePointer$qwerty');
|
||||
expect(output.aPointer).toBeUndefined();
|
||||
done();
|
||||
.then(() => database.adapter.find('APointerDarkly', {}, { fields: {
|
||||
foo: { type: 'String' },
|
||||
aPointer: { type: 'Pointer', targetClass: 'JustThePointer' },
|
||||
}}, {}))
|
||||
.then(results => {
|
||||
expect(results.length).toEqual(1);
|
||||
let output = results[0];
|
||||
expect(typeof output.foo).toEqual('string');
|
||||
expect(typeof output._p_aPointer).toEqual('undefined');
|
||||
expect(output._p_aPointer).toBeUndefined();
|
||||
expect(output.aPointer).toEqual({
|
||||
__type: 'Pointer',
|
||||
className: 'JustThePointer',
|
||||
objectId: 'qwerty'
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("cannot set objectId", (done) => {
|
||||
|
||||
Reference in New Issue
Block a user