Skip to content

Commit cd52580

Browse files
drew-grossflovilmart
authored andcommitted
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
1 parent 17374ef commit cd52580

File tree

7 files changed

+349
-259
lines changed

7 files changed

+349
-259
lines changed

spec/MongoStorageAdapter.spec.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

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

7+
// These tests are specific to the mongo storage adapter + mongo storage format
8+
// and will eventually be moved into their own repo
69
describe('MongoStorageAdapter', () => {
10+
beforeEach(done => {
11+
new MongoStorageAdapter({ uri: databaseURI })
12+
.deleteAllSchemas()
13+
.then(done, fail);
14+
});
15+
716
it('auto-escapes symbols in auth information', () => {
817
spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(null));
918
new MongoStorageAdapter({
@@ -37,4 +46,110 @@ describe('MongoStorageAdapter', () => {
3746
jasmine.any(Object)
3847
);
3948
});
49+
50+
it('stores objectId in _id', done => {
51+
let adapter = new MongoStorageAdapter({ uri: databaseURI });
52+
adapter.createObject('Foo', { objectId: 'abcde' }, { fields: { objectId: 'String' } })
53+
.then(() => adapter._rawFind('Foo', {}))
54+
.then(results => {
55+
expect(results.length).toEqual(1);
56+
var obj = results[0];
57+
expect(typeof obj._id).toEqual('string');
58+
expect(obj.objectId).toBeUndefined();
59+
done();
60+
});
61+
});
62+
63+
it('stores pointers with a _p_ prefix', (done) => {
64+
let obj = {
65+
objectId: 'bar',
66+
aPointer: {
67+
__type: 'Pointer',
68+
className: 'JustThePointer',
69+
objectId: 'qwerty'
70+
}
71+
};
72+
let adapter = new MongoStorageAdapter({ uri: databaseURI });
73+
adapter.createObject('APointerDarkly', obj, { fields: {
74+
objectId: { type: 'String' },
75+
aPointer: { type: 'Pointer', targetClass: 'JustThePointer' },
76+
}})
77+
.then(() => adapter._rawFind('APointerDarkly', {}))
78+
.then(results => {
79+
expect(results.length).toEqual(1);
80+
let output = results[0];
81+
expect(typeof output._id).toEqual('string');
82+
expect(typeof output._p_aPointer).toEqual('string');
83+
expect(output._p_aPointer).toEqual('JustThePointer$qwerty');
84+
expect(output.aPointer).toBeUndefined();
85+
done();
86+
});
87+
});
88+
89+
it('handles object and subdocument', done => {
90+
let adapter = new MongoStorageAdapter({ uri: databaseURI });
91+
let schema = { fields : { subdoc: { type: 'Object' } } };
92+
let obj = { subdoc: {foo: 'bar', wu: 'tan'} };
93+
adapter.createObject('MyClass', obj, schema)
94+
.then(() => adapter._rawFind('MyClass', {}))
95+
.then(results => {
96+
expect(results.length).toEqual(1);
97+
let mob = results[0];
98+
expect(typeof mob.subdoc).toBe('object');
99+
expect(mob.subdoc.foo).toBe('bar');
100+
expect(mob.subdoc.wu).toBe('tan');
101+
let obj = { 'subdoc.wu': 'clan' };
102+
return adapter.findOneAndUpdate('MyClass', {}, schema, obj);
103+
})
104+
.then(() => adapter._rawFind('MyClass', {}))
105+
.then(results => {
106+
expect(results.length).toEqual(1);
107+
let mob = results[0];
108+
expect(typeof mob.subdoc).toBe('object');
109+
expect(mob.subdoc.foo).toBe('bar');
110+
expect(mob.subdoc.wu).toBe('clan');
111+
done();
112+
});
113+
});
114+
115+
it('handles array, object, date', (done) => {
116+
let adapter = new MongoStorageAdapter({ uri: databaseURI });
117+
let obj = {
118+
array: [1, 2, 3],
119+
object: {foo: 'bar'},
120+
date: {
121+
__type: 'Date',
122+
iso: '2016-05-26T20:55:01.154Z',
123+
},
124+
};
125+
let schema = { fields: {
126+
array: { type: 'Array' },
127+
object: { type: 'Object' },
128+
date: { type: 'Date' },
129+
} };
130+
adapter.createObject('MyClass', obj, schema)
131+
.then(() => adapter._rawFind('MyClass', {}))
132+
.then(results => {
133+
expect(results.length).toEqual(1);
134+
let mob = results[0];
135+
expect(mob.array instanceof Array).toBe(true);
136+
expect(typeof mob.object).toBe('object');
137+
expect(mob.date instanceof Date).toBe(true);
138+
return adapter.find('MyClass', {}, schema, {});
139+
})
140+
.then(results => {
141+
expect(results.length).toEqual(1);
142+
let mob = results[0];
143+
expect(mob.array instanceof Array).toBe(true);
144+
expect(typeof mob.object).toBe('object');
145+
expect(mob.date.__type).toBe('Date');
146+
expect(mob.date.iso).toBe('2016-05-26T20:55:01.154Z');
147+
done();
148+
})
149+
.catch(error => {
150+
console.log(error);
151+
fail();
152+
done();
153+
});
154+
});
40155
});

spec/OAuth.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var OAuth = require("../src/authDataManager/OAuth1Client");
22
var request = require('request');
33
var Config = require("../src/Config");
4+
var defaultColumns = require('../src/Controllers/SchemaController').defaultColumns;
45

56
describe('OAuth', function() {
67

@@ -283,9 +284,10 @@ describe('OAuth', function() {
283284
"Expiration should be cleared");
284285
// make sure the auth data is properly deleted
285286
var config = new Config(Parse.applicationId);
286-
config.database.mongoFind('_User', {
287-
_id: model.id
288-
}).then((res) => {
287+
config.database.adapter.find('_User', { objectId: model.id }, {
288+
fields: Object.assign({}, defaultColumns._Default, defaultColumns._Installation),
289+
}, {})
290+
.then(res => {
289291
expect(res.length).toBe(1);
290292
expect(res[0]._auth_data_myoauth).toBeUndefined();
291293
expect(res[0]._auth_data_myoauth).not.toBeNull();

spec/ParseAPI.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('miscellaneous', function() {
203203
return obj.save();
204204
}).then(() => {
205205
var db = DatabaseAdapter.getDatabaseConnection(appId, 'test_');
206-
return db.mongoFind('TestObject', {}, {});
206+
return db.adapter.find('TestObject', {}, { fields: {} }, {});
207207
}).then((results) => {
208208
expect(results.length).toEqual(1);
209209
expect(results[0]['foo']).toEqual('bar');

0 commit comments

Comments
 (0)