Skip to content

Remove mongoFind and mostly remove adaptiveCollection #1924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8d6940d
Use adapter.count
drew-gross May 25, 2016
1c69adc
use adapter.upsertOneObject
drew-gross May 25, 2016
93a5846
Use adapter.deleteObjectsByQuery
drew-gross May 25, 2016
5b0d3c5
Use adapter.find
drew-gross May 25, 2016
e95bc0d
use adapter.find
drew-gross May 25, 2016
76fdff8
Update tests to avoid mongoFind
drew-gross May 25, 2016
7bac020
Fix a test to not use mongoFind
drew-gross May 25, 2016
dafaace
Fix a test to not use mongoFind
drew-gross May 25, 2016
8831927
remove some mongoFind
drew-gross May 26, 2016
ab3bb3d
Remove some mongoFind
drew-gross May 26, 2016
32489eb
Remove some mongoFind
drew-gross May 26, 2016
c7e3e55
Remove more mongoFind
drew-gross May 26, 2016
94e46de
remove more mongoFind
drew-gross May 26, 2016
cd2c75f
remove more mongoFind
drew-gross May 26, 2016
0cd238f
remove more mongoFind
drew-gross May 26, 2016
811c9f0
remove more mongoFind
drew-gross May 26, 2016
61ff645
remove more mongoFind
drew-gross May 26, 2016
7cbdf09
remove more mongoFind
drew-gross May 26, 2016
4e0cdca
remove more mongoFind
drew-gross May 26, 2016
ef61711
remove more mongoFind
drew-gross May 26, 2016
be93049
Restore update ios device token with duplicate device token to original
drew-gross May 26, 2016
bbbba34
remove a mongoFind
drew-gross May 26, 2016
15f4fd7
remove a mongoFind
drew-gross May 26, 2016
7d49ec6
formatting
drew-gross May 26, 2016
0cc2d13
formatting
drew-gross May 26, 2016
4071c98
remove a mongoFind
drew-gross May 26, 2016
af12859
remove a mongoFind
drew-gross May 26, 2016
8a98186
remove a mongoFind
drew-gross May 26, 2016
7c38999
kill mongoFind
drew-gross May 26, 2016
5e57bd9
Fix tests
drew-gross May 26, 2016
088e6c2
Fix tests
drew-gross May 26, 2016
bb401e3
fix syntax
drew-gross May 26, 2016
2acff1a
Fix test
drew-gross May 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions spec/MongoStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
const MongoClient = require('mongodb').MongoClient;
const databaseURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';

// These tests are specific to the mongo storage adapter + mongo storage format
// and will eventually be moved into their own repo
describe('MongoStorageAdapter', () => {
beforeEach(done => {
new MongoStorageAdapter({ uri: databaseURI })
.deleteAllSchemas()
.then(done, fail);
});

it('auto-escapes symbols in auth information', () => {
spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(null));
new MongoStorageAdapter({
Expand Down Expand Up @@ -37,4 +46,110 @@ describe('MongoStorageAdapter', () => {
jasmine.any(Object)
);
});

it('stores objectId in _id', done => {
let adapter = new MongoStorageAdapter({ uri: databaseURI });
adapter.createObject('Foo', { objectId: 'abcde' }, { fields: { objectId: 'String' } })
.then(() => adapter._rawFind('Foo', {}))
.then(results => {
expect(results.length).toEqual(1);
var obj = results[0];
expect(typeof obj._id).toEqual('string');
expect(obj.objectId).toBeUndefined();
done();
});
});

it('stores pointers with a _p_ prefix', (done) => {
let obj = {
objectId: 'bar',
aPointer: {
__type: 'Pointer',
className: 'JustThePointer',
objectId: 'qwerty'
}
};
let adapter = new MongoStorageAdapter({ uri: databaseURI });
adapter.createObject('APointerDarkly', obj, { fields: {
objectId: { type: 'String' },
aPointer: { type: 'Pointer', targetClass: 'JustThePointer' },
}})
.then(() => adapter._rawFind('APointerDarkly', {}))
.then(results => {
expect(results.length).toEqual(1);
let 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();
});
});

it('handles object and subdocument', done => {
let adapter = new MongoStorageAdapter({ uri: databaseURI });
let schema = { fields : { subdoc: { type: 'Object' } } };
let obj = { subdoc: {foo: 'bar', wu: 'tan'} };
adapter.createObject('MyClass', obj, schema)
.then(() => adapter._rawFind('MyClass', {}))
.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('tan');
let obj = { 'subdoc.wu': 'clan' };
return adapter.findOneAndUpdate('MyClass', {}, schema, obj);
})
.then(() => adapter._rawFind('MyClass', {}))
.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();
});
});

it('handles array, object, date', (done) => {
let adapter = new MongoStorageAdapter({ uri: databaseURI });
let obj = {
array: [1, 2, 3],
object: {foo: 'bar'},
date: {
__type: 'Date',
iso: '2016-05-26T20:55:01.154Z',
},
};
let schema = { fields: {
array: { type: 'Array' },
object: { type: 'Object' },
date: { type: 'Date' },
} };
adapter.createObject('MyClass', obj, schema)
.then(() => 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);
return adapter.find('MyClass', {}, schema, {});
})
.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.__type).toBe('Date');
expect(mob.date.iso).toBe('2016-05-26T20:55:01.154Z');
done();
})
.catch(error => {
console.log(error);
fail();
done();
});
});
});
8 changes: 5 additions & 3 deletions spec/OAuth.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var OAuth = require("../src/authDataManager/OAuth1Client");
var request = require('request');
var Config = require("../src/Config");
var defaultColumns = require('../src/Controllers/SchemaController').defaultColumns;

describe('OAuth', function() {

Expand Down Expand Up @@ -283,9 +284,10 @@ describe('OAuth', function() {
"Expiration should be cleared");
// make sure the auth data is properly deleted
var config = new Config(Parse.applicationId);
config.database.mongoFind('_User', {
_id: model.id
}).then((res) => {
config.database.adapter.find('_User', { objectId: model.id }, {
fields: Object.assign({}, defaultColumns._Default, defaultColumns._Installation),
}, {})
.then(res => {
expect(res.length).toBe(1);
expect(res[0]._auth_data_myoauth).toBeUndefined();
expect(res[0]._auth_data_myoauth).not.toBeNull();
Expand Down
2 changes: 1 addition & 1 deletion spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('miscellaneous', function() {
return obj.save();
}).then(() => {
var db = DatabaseAdapter.getDatabaseConnection(appId, 'test_');
return db.mongoFind('TestObject', {}, {});
return db.adapter.find('TestObject', {}, { fields: {} }, {});
}).then((results) => {
expect(results.length).toEqual(1);
expect(results[0]['foo']).toEqual('bar');
Expand Down
Loading