Skip to content

Commit 56c97bb

Browse files
committed
Removes adaptiveCollection from DatabaseController
- All collections manipulations are now handled by a DBController - Adds optional flags to configure an unsafe databaseController for direct access - Adds ability to configure RestWrite with multiple writes - Moves some transfirmations to MongoTransform as they output specific code
1 parent 899de49 commit 56c97bb

15 files changed

+294
-273
lines changed

spec/ParseGlobalConfig.spec.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ let Config = require('../src/Config');
77
describe('a GlobalConfig', () => {
88
beforeEach(done => {
99
let config = new Config('test');
10-
config.database.adaptiveCollection('_GlobalConfig')
10+
let prefix = config.database.collectionPrefix;
11+
config.database.adapter.adaptiveCollection(prefix + '_GlobalConfig')
1112
.then(coll => coll.upsertOne({ '_id': 1 }, { $set: { params: { companies: ['US', 'DK'] } } }))
1213
.then(() => { done(); });
1314
});
@@ -43,6 +44,35 @@ describe('a GlobalConfig', () => {
4344
});
4445
});
4546

47+
it('properly handles delete op', (done) => {
48+
request.put({
49+
url : 'http://localhost:8378/1/config',
50+
json : true,
51+
body : { params: { companies: {__op: 'Delete'}, foo: 'bar' } },
52+
headers: {
53+
'X-Parse-Application-Id': 'test',
54+
'X-Parse-Master-Key' : 'test'
55+
}
56+
}, (error, response, body) => {
57+
expect(response.statusCode).toEqual(200);
58+
expect(body.result).toEqual(true);
59+
request.get({
60+
url : 'http://localhost:8378/1/config',
61+
json : true,
62+
headers: {
63+
'X-Parse-Application-Id': 'test',
64+
'X-Parse-Master-Key' : 'test'
65+
}
66+
}, (error, response, body) => {
67+
expect(response.statusCode).toEqual(200);
68+
expect(body.params.companies).toBeUndefined();
69+
expect(body.params.foo).toBe('bar');
70+
expect(Object.keys(body.params).length).toBe(1);
71+
done();
72+
});
73+
});
74+
});
75+
4676
it('fail to update if master key is missing', (done) => {
4777
request.put({
4878
url : 'http://localhost:8378/1/config',
@@ -61,7 +91,7 @@ describe('a GlobalConfig', () => {
6191

6292
it('failed getting config when it is missing', (done) => {
6393
let config = new Config('test');
64-
config.database.adaptiveCollection('_GlobalConfig')
94+
config.database.adapter.adaptiveCollection(config.database.collectionPrefix + '_GlobalConfig')
6595
.then(coll => coll.deleteOne({ '_id': 1 }))
6696
.then(() => {
6797
request.get({

spec/ParseHooks.spec.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ app.listen(12345);
1616

1717

1818
describe('Hooks', () => {
19-
19+
2020
it("should have some hooks registered", (done) => {
2121
Parse.Hooks.getFunctions().then((res) => {
2222
expect(res.constructor).toBe(Array.prototype.constructor);
@@ -26,7 +26,7 @@ describe('Hooks', () => {
2626
done();
2727
});
2828
});
29-
29+
3030
it("should have some triggers registered", (done) => {
3131
Parse.Hooks.getTriggers().then( (res) => {
3232
expect(res.constructor).toBe(Array.prototype.constructor);
@@ -59,7 +59,7 @@ describe('Hooks', () => {
5959
}).then((res) => {
6060
expect(res.functionName).toBe("My-Test-Function");
6161
expect(res.url).toBe("http://anotherurl")
62-
62+
6363
return Parse.Hooks.deleteFunction("My-Test-Function");
6464
}, (err) => {
6565
fail(err);
@@ -81,7 +81,7 @@ describe('Hooks', () => {
8181
done();
8282
})
8383
});
84-
84+
8585
it("should CRUD a trigger registration", (done) => {
8686
// Create
8787
Parse.Hooks.createTrigger("MyClass","beforeDelete", "http://someurl").then((res) => {
@@ -105,7 +105,7 @@ describe('Hooks', () => {
105105
}).then((res) => {
106106
expect(res.className).toBe("MyClass");
107107
expect(res.url).toBe("http://anotherurl")
108-
108+
109109
return Parse.Hooks.deleteTrigger("MyClass","beforeDelete");
110110
}, (err) => {
111111
fail(err);
@@ -127,7 +127,7 @@ describe('Hooks', () => {
127127
done();
128128
});
129129
});
130-
130+
131131
it("should fail to register hooks without Master Key", (done) => {
132132
request.post(Parse.serverURL+"/hooks/functions", {
133133
headers: {
@@ -141,7 +141,7 @@ describe('Hooks', () => {
141141
done();
142142
})
143143
});
144-
144+
145145
it("should fail trying to create two times the same function", (done) => {
146146
Parse.Hooks.createFunction("my_new_function", "http://url.com").then( () => {
147147
return Parse.Hooks.createFunction("my_new_function", "http://url.com")
@@ -162,7 +162,7 @@ describe('Hooks', () => {
162162
done();
163163
})
164164
});
165-
165+
166166
it("should fail trying to create two times the same trigger", (done) => {
167167
Parse.Hooks.createTrigger("MyClass", "beforeSave", "http://url.com").then( () => {
168168
return Parse.Hooks.createTrigger("MyClass", "beforeSave", "http://url.com")
@@ -181,7 +181,7 @@ describe('Hooks', () => {
181181
done();
182182
})
183183
});
184-
184+
185185
it("should fail trying to update a function that don't exist", (done) => {
186186
Parse.Hooks.updateFunction("A_COOL_FUNCTION", "http://url.com").then( () => {
187187
fail("Should not succeed")
@@ -198,7 +198,7 @@ describe('Hooks', () => {
198198
done();
199199
});
200200
});
201-
201+
202202
it("should fail trying to update a trigger that don't exist", (done) => {
203203
Parse.Hooks.updateTrigger("AClassName","beforeSave", "http://url.com").then( () => {
204204
fail("Should not succeed")
@@ -215,8 +215,8 @@ describe('Hooks', () => {
215215
done();
216216
});
217217
});
218-
219-
218+
219+
220220
it("should fail trying to create a malformed function", (done) => {
221221
Parse.Hooks.createFunction("MyFunction").then( (res) => {
222222
fail(res);
@@ -226,7 +226,7 @@ describe('Hooks', () => {
226226
done();
227227
});
228228
});
229-
229+
230230
it("should fail trying to create a malformed function (REST)", (done) => {
231231
request.post(Parse.serverURL+"/hooks/functions", {
232232
headers: {
@@ -241,16 +241,16 @@ describe('Hooks', () => {
241241
done();
242242
})
243243
});
244-
245-
244+
245+
246246
it("should create hooks and properly preload them", (done) => {
247-
247+
248248
var promises = [];
249249
for (var i = 0; i<5; i++) {
250250
promises.push(Parse.Hooks.createTrigger("MyClass"+i, "beforeSave", "http://url.com/beforeSave/"+i));
251251
promises.push(Parse.Hooks.createFunction("AFunction"+i, "http://url.com/function"+i));
252252
}
253-
253+
254254
Parse.Promise.when(promises).then(function(results){
255255
for (var i=0; i<5; i++) {
256256
// Delete everything from memory, as the server just started
@@ -263,7 +263,7 @@ describe('Hooks', () => {
263263
return hooksController.load()
264264
}, (err) => {
265265
console.error(err);
266-
fail();
266+
fail('Should properly create all hooks');
267267
done();
268268
}).then(function() {
269269
for (var i=0; i<5; i++) {
@@ -273,17 +273,17 @@ describe('Hooks', () => {
273273
done();
274274
}, (err) => {
275275
console.error(err);
276-
fail();
276+
fail('should properly load all hooks');
277277
done();
278278
})
279279
});
280-
280+
281281
it("should run the function on the test server", (done) => {
282-
282+
283283
app.post("/SomeFunction", function(req, res) {
284284
res.json({success:"OK!"});
285285
});
286-
286+
287287
Parse.Hooks.createFunction("SOME_TEST_FUNCTION", hookServerURL+"/SomeFunction").then(function(){
288288
return Parse.Cloud.run("SOME_TEST_FUNCTION")
289289
}, (err) => {
@@ -299,9 +299,9 @@ describe('Hooks', () => {
299299
done();
300300
})
301301
});
302-
302+
303303
it("should run the function on the test server", (done) => {
304-
304+
305305
app.post("/SomeFunctionError", function(req, res) {
306306
res.json({error: {code: 1337, error: "hacking that one!"}});
307307
});
@@ -322,8 +322,8 @@ describe('Hooks', () => {
322322
done();
323323
});
324324
});
325-
326-
325+
326+
327327
it("should run the beforeSave hook on the test server", (done) => {
328328
var triggerCount = 0;
329329
app.post("/BeforeSaveSome", function(req, res) {
@@ -350,7 +350,7 @@ describe('Hooks', () => {
350350
done();
351351
});
352352
});
353-
353+
354354
it("should run the afterSave hook on the test server", (done) => {
355355
var triggerCount = 0;
356356
var newObjectId;
@@ -387,4 +387,4 @@ describe('Hooks', () => {
387387
done();
388388
});
389389
});
390-
});
390+
});

spec/PushController.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ describe('PushController', () => {
184184
}).then((result) => {
185185
done();
186186
}, (err) => {
187-
console.error(err);
188187
fail("should not fail");
189188
done();
190189
});
@@ -233,7 +232,6 @@ describe('PushController', () => {
233232
}).then((result) => {
234233
done();
235234
}, (err) => {
236-
console.error(err);
237235
fail("should not fail");
238236
done();
239237
});

spec/Schema.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,10 @@ describe('Schema', () => {
715715
done();
716716
Parse.Object.enableSingleInstance();
717717
});
718-
});
718+
}).catch(err => {
719+
console.error(err);
720+
done();
721+
})
719722
});
720723

721724
it('can delete pointer fields and resave as string', done => {

spec/ValidationAndPasswordsReset.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ describe("Email Verification", () => {
266266
.then((user) => {
267267
return user.save();
268268
}).then((user) => {
269-
return Parse.User.requestPasswordReset("cool_guy@parse.com");
269+
return Parse.User.requestPasswordReset("cool_guy@parse.com").catch((err) => {
270+
fail('Should not fail requesting a password');
271+
done();
272+
})
270273
}).then(() => {
271274
expect(calls).toBe(2);
272275
done();
@@ -551,7 +554,7 @@ describe("Password Reset", () => {
551554
Parse.User.requestPasswordReset('user@parse.com', {
552555
error: (err) => {
553556
console.error(err);
554-
fail("Should not fail");
557+
fail("Should not fail requesting a password");
555558
done();
556559
}
557560
});
@@ -628,7 +631,7 @@ describe("Password Reset", () => {
628631

629632
Parse.User.logIn("zxcv", "hello").then(function(user){
630633
let config = new Config('test');
631-
config.database.adaptiveCollection('_User')
634+
config.database.adapter.adaptiveCollection(config.database.collectionPrefix+'_User')
632635
.then(coll => coll.find({ 'username': 'zxcv' }, { limit: 1 }))
633636
.then((results) => {
634637
// _perishable_token should be unset after reset password

0 commit comments

Comments
 (0)