Skip to content

Commit

Permalink
Removes adaptiveCollection from DatabaseController
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
flovilmart committed Mar 31, 2016
1 parent 69dd1ab commit ce1e5bf
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 269 deletions.
34 changes: 32 additions & 2 deletions spec/ParseGlobalConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ let Config = require('../src/Config');
describe('a GlobalConfig', () => {
beforeEach(done => {
let config = new Config('test');
config.database.adaptiveCollection('_GlobalConfig')
let prefix = config.database.collectionPrefix;
config.database.adapter.adaptiveCollection(prefix + '_GlobalConfig')
.then(coll => coll.upsertOne({ '_id': 1 }, { $set: { params: { companies: ['US', 'DK'] } } }))
.then(() => { done(); });
});
Expand Down Expand Up @@ -43,6 +44,35 @@ describe('a GlobalConfig', () => {
});
});

it('properly handles delete op', (done) => {
request.put({
url : 'http://localhost:8378/1/config',
json : true,
body : { params: { companies: {__op: 'Delete'}, foo: 'bar' } },
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key' : 'test'
}
}, (error, response, body) => {
expect(response.statusCode).toEqual(200);
expect(body.result).toEqual(true);
request.get({
url : 'http://localhost:8378/1/config',
json : true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key' : 'test'
}
}, (error, response, body) => {
expect(response.statusCode).toEqual(200);
expect(body.params.companies).toBeUndefined();
expect(body.params.foo).toBe('bar');
expect(Object.keys(body.params).length).toBe(1);
done();
});
});
});

it('fail to update if master key is missing', (done) => {
request.put({
url : 'http://localhost:8378/1/config',
Expand All @@ -61,7 +91,7 @@ describe('a GlobalConfig', () => {

it('failed getting config when it is missing', (done) => {
let config = new Config('test');
config.database.adaptiveCollection('_GlobalConfig')
config.database.adapter.adaptiveCollection(config.database.collectionPrefix + '_GlobalConfig')
.then(coll => coll.deleteOne({ '_id': 1 }))
.then(() => {
request.get({
Expand Down
56 changes: 28 additions & 28 deletions spec/ParseHooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ app.listen(12345);


describe('Hooks', () => {

it("should have some hooks registered", (done) => {
Parse.Hooks.getFunctions().then((res) => {
expect(res.constructor).toBe(Array.prototype.constructor);
Expand All @@ -26,7 +26,7 @@ describe('Hooks', () => {
done();
});
});

it("should have some triggers registered", (done) => {
Parse.Hooks.getTriggers().then( (res) => {
expect(res.constructor).toBe(Array.prototype.constructor);
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('Hooks', () => {
}).then((res) => {
expect(res.functionName).toBe("My-Test-Function");
expect(res.url).toBe("http://anotherurl")

return Parse.Hooks.deleteFunction("My-Test-Function");
}, (err) => {
fail(err);
Expand All @@ -81,7 +81,7 @@ describe('Hooks', () => {
done();
})
});

it("should CRUD a trigger registration", (done) => {
// Create
Parse.Hooks.createTrigger("MyClass","beforeDelete", "http://someurl").then((res) => {
Expand All @@ -105,7 +105,7 @@ describe('Hooks', () => {
}).then((res) => {
expect(res.className).toBe("MyClass");
expect(res.url).toBe("http://anotherurl")

return Parse.Hooks.deleteTrigger("MyClass","beforeDelete");
}, (err) => {
fail(err);
Expand All @@ -127,7 +127,7 @@ describe('Hooks', () => {
done();
});
});

it("should fail to register hooks without Master Key", (done) => {
request.post(Parse.serverURL+"/hooks/functions", {
headers: {
Expand All @@ -141,7 +141,7 @@ describe('Hooks', () => {
done();
})
});

it("should fail trying to create two times the same function", (done) => {
Parse.Hooks.createFunction("my_new_function", "http://url.com").then( () => {
return Parse.Hooks.createFunction("my_new_function", "http://url.com")
Expand All @@ -162,7 +162,7 @@ describe('Hooks', () => {
done();
})
});

it("should fail trying to create two times the same trigger", (done) => {
Parse.Hooks.createTrigger("MyClass", "beforeSave", "http://url.com").then( () => {
return Parse.Hooks.createTrigger("MyClass", "beforeSave", "http://url.com")
Expand All @@ -181,7 +181,7 @@ describe('Hooks', () => {
done();
})
});

it("should fail trying to update a function that don't exist", (done) => {
Parse.Hooks.updateFunction("A_COOL_FUNCTION", "http://url.com").then( () => {
fail("Should not succeed")
Expand All @@ -198,7 +198,7 @@ describe('Hooks', () => {
done();
});
});

it("should fail trying to update a trigger that don't exist", (done) => {
Parse.Hooks.updateTrigger("AClassName","beforeSave", "http://url.com").then( () => {
fail("Should not succeed")
Expand All @@ -215,8 +215,8 @@ describe('Hooks', () => {
done();
});
});


it("should fail trying to create a malformed function", (done) => {
Parse.Hooks.createFunction("MyFunction").then( (res) => {
fail(res);
Expand All @@ -226,7 +226,7 @@ describe('Hooks', () => {
done();
});
});

it("should fail trying to create a malformed function (REST)", (done) => {
request.post(Parse.serverURL+"/hooks/functions", {
headers: {
Expand All @@ -241,16 +241,16 @@ describe('Hooks', () => {
done();
})
});


it("should create hooks and properly preload them", (done) => {

var promises = [];
for (var i = 0; i<5; i++) {
promises.push(Parse.Hooks.createTrigger("MyClass"+i, "beforeSave", "http://url.com/beforeSave/"+i));
promises.push(Parse.Hooks.createFunction("AFunction"+i, "http://url.com/function"+i));
}

Parse.Promise.when(promises).then(function(results){
for (var i=0; i<5; i++) {
// Delete everything from memory, as the server just started
Expand All @@ -263,7 +263,7 @@ describe('Hooks', () => {
return hooksController.load()
}, (err) => {
console.error(err);
fail();
fail('Should properly create all hooks');
done();
}).then(function() {
for (var i=0; i<5; i++) {
Expand All @@ -273,17 +273,17 @@ describe('Hooks', () => {
done();
}, (err) => {
console.error(err);
fail();
fail('should properly load all hooks');
done();
})
});

it("should run the function on the test server", (done) => {

app.post("/SomeFunction", function(req, res) {
res.json({success:"OK!"});
});

Parse.Hooks.createFunction("SOME_TEST_FUNCTION", hookServerURL+"/SomeFunction").then(function(){
return Parse.Cloud.run("SOME_TEST_FUNCTION")
}, (err) => {
Expand All @@ -299,9 +299,9 @@ describe('Hooks', () => {
done();
})
});

it("should run the function on the test server", (done) => {

app.post("/SomeFunctionError", function(req, res) {
res.json({error: {code: 1337, error: "hacking that one!"}});
});
Expand All @@ -322,8 +322,8 @@ describe('Hooks', () => {
done();
});
});


it("should run the beforeSave hook on the test server", (done) => {
var triggerCount = 0;
app.post("/BeforeSaveSome", function(req, res) {
Expand All @@ -350,7 +350,7 @@ describe('Hooks', () => {
done();
});
});

it("should run the afterSave hook on the test server", (done) => {
var triggerCount = 0;
var newObjectId;
Expand Down Expand Up @@ -387,4 +387,4 @@ describe('Hooks', () => {
done();
});
});
});
});
2 changes: 0 additions & 2 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ describe('PushController', () => {
}).then((result) => {
done();
}, (err) => {
console.error(err);
fail("should not fail");
done();
});
Expand Down Expand Up @@ -233,7 +232,6 @@ describe('PushController', () => {
}).then((result) => {
done();
}, (err) => {
console.error(err);
fail("should not fail");
done();
});
Expand Down
5 changes: 4 additions & 1 deletion spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,10 @@ describe('Schema', () => {
done();
Parse.Object.enableSingleInstance();
});
});
}).catch(err => {
console.error(err);
done();
})
});

it('can delete pointer fields and resave as string', done => {
Expand Down
9 changes: 6 additions & 3 deletions spec/ValidationAndPasswordsReset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ describe("Email Verification", () => {
.then((user) => {
return user.save();
}).then((user) => {
return Parse.User.requestPasswordReset("cool_guy@parse.com");
return Parse.User.requestPasswordReset("cool_guy@parse.com").catch((err) => {
fail('Should not fail requesting a password');
done();
})
}).then(() => {
expect(calls).toBe(2);
done();
Expand Down Expand Up @@ -551,7 +554,7 @@ describe("Password Reset", () => {
Parse.User.requestPasswordReset('user@parse.com', {
error: (err) => {
console.error(err);
fail("Should not fail");
fail("Should not fail requesting a password");
done();
}
});
Expand Down Expand Up @@ -628,7 +631,7 @@ describe("Password Reset", () => {

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

0 comments on commit ce1e5bf

Please sign in to comment.