Postgres: $all, $and CLP and more (#2551)

* Adds passing tests

* Better containsAll implementation

* Full Geopoint support, fix inverted lat/lng

* Adds support for $and operator / PointerPermissions specs

* Fix issue updating CLPs on schema

* Extends query support

* Adds RestCreate to the specs

* Adds User specs

* Adds error handlers for failing tests

* nits

* Proper JSON update of AuthData

* fix for #1259 with PG

* Fix for Installations _PushStatus test

* Adds support for GlobalConfig

* Enables relations tests

* Exclude spec as legacy

* Makes corner case for 1 in GlobalConfig
This commit is contained in:
Florent Vilmart
2016-08-20 16:07:48 -04:00
committed by GitHub
parent e1de9f3a12
commit 9ab488b6a0
17 changed files with 276 additions and 138 deletions

View File

@@ -75,8 +75,7 @@ describe('InstallationsRouter', () => {
expect(results.length).toEqual(1);
done();
}).catch((err) => {
console.error(err);
fail(JSON.stringify(err));
jfail(err);
done();
});
});

View File

@@ -113,7 +113,7 @@ describe('miscellaneous', function() {
.catch(done);
});
it_exclude_dbs(['postgres'])('ensure that email is uniquely indexed', done => {
it('ensure that email is uniquely indexed', done => {
let numFailed = 0;
let numCreated = 0;
let user1 = new Parse.User();
@@ -212,7 +212,7 @@ describe('miscellaneous', function() {
});
});
it_exclude_dbs(['postgres'])('ensure that if you try to sign up a user with a unique username and email, but duplicates in some other field that has a uniqueness constraint, you get a regular duplicate value error', done => {
it('ensure that if you try to sign up a user with a unique username and email, but duplicates in some other field that has a uniqueness constraint, you get a regular duplicate value error', done => {
let config = new Config('test');
config.database.adapter.addFieldIfNotExists('_User', 'randomField', { type: 'String' })
.then(() => config.database.adapter.ensureUniqueness('_User', userSchema, ['randomField']))
@@ -233,7 +233,6 @@ it_exclude_dbs(['postgres'])('ensure that if you try to sign up a user with a un
return user.signUp()
})
.catch(error => {
console.error(error);
expect(error.code).toEqual(Parse.Error.DUPLICATE_VALUE);
done();
});
@@ -1363,7 +1362,7 @@ it_exclude_dbs(['postgres'])('ensure that if you try to sign up a user with a un
});
});
it_exclude_dbs(['postgres'])('does not change inner objects if the key has the same name as a geopoint field on the class, and the value is an array of length 2, or if the key has the same name as a file field on the class, and the value is a string', done => {
it('does not change inner objects if the key has the same name as a geopoint field on the class, and the value is an array of length 2, or if the key has the same name as a file field on the class, and the value is a string', done => {
let file = new Parse.File('myfile.txt', { base64: 'eAo=' });
file.save()
.then(f => {
@@ -1495,8 +1494,10 @@ it_exclude_dbs(['postgres'])('ensure that if you try to sign up a user with a un
done();
});
});
});
it_exclude_dbs(['postgres'])('should have _acl when locking down (regression for #2465)', (done) =>  {
describe_only_db('mongo')('legacy _acl', () => {
it('should have _acl when locking down (regression for #2465)', (done) =>  {
let headers = {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'

View File

@@ -273,7 +273,7 @@ describe('Parse.GeoPoint testing', () => {
});
});
it_exclude_dbs(['postgres'])('works with geobox queries', (done) => {
it('works with geobox queries', (done) => {
var inSF = new Parse.GeoPoint(37.75, -122.4);
var southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398);
var northeastOfSF = new Parse.GeoPoint(37.822802, -122.373962);

View File

@@ -7,15 +7,24 @@ let Config = require('../src/Config');
describe('a GlobalConfig', () => {
beforeEach(done => {
let config = new Config('test');
let query = on_db('mongo', () => {
// Legacy is with an int...
return { objectId: 1 };
}, () => {
return { objectId: "1" }
})
config.database.adapter.upsertOneObject(
'_GlobalConfig',
{ fields: {} },
{ objectId: 1 },
{ fields: { objectId: { type: 'Number' }, params: {type: 'Object'}} },
query,
{ params: { companies: ['US', 'DK'] } }
).then(done, done);
).then(done, (err) => {
jfail(err);
done();
});
});
it_exclude_dbs(['postgres'])('can be retrieved', (done) => {
it('can be retrieved', (done) => {
request.get({
url : 'http://localhost:8378/1/config',
json : true,
@@ -32,7 +41,7 @@ describe('a GlobalConfig', () => {
});
});
it_exclude_dbs(['postgres'])('can be updated when a master key exists', (done) => {
it('can be updated when a master key exists', (done) => {
request.put({
url : 'http://localhost:8378/1/config',
json : true,
@@ -48,7 +57,7 @@ describe('a GlobalConfig', () => {
});
});
it_exclude_dbs(['postgres'])('properly handles delete op', (done) => {
it('properly handles delete op', (done) => {
request.put({
url : 'http://localhost:8378/1/config',
json : true,
@@ -79,7 +88,7 @@ describe('a GlobalConfig', () => {
});
});
it_exclude_dbs(['postgres'])('fail to update if master key is missing', (done) => {
it('fail to update if master key is missing', (done) => {
request.put({
url : 'http://localhost:8378/1/config',
json : true,
@@ -95,12 +104,12 @@ describe('a GlobalConfig', () => {
});
});
it_exclude_dbs(['postgres'])('failed getting config when it is missing', (done) => {
it('failed getting config when it is missing', (done) => {
let config = new Config('test');
config.database.adapter.deleteObjectsByQuery(
'_GlobalConfig',
{ fields: { params: { __type: 'String' } } },
{ objectId: 1 }
{ objectId: "1" }
).then(() => {
request.get({
url : 'http://localhost:8378/1/config',

View File

@@ -665,13 +665,7 @@ describe('Parse.Object testing', () => {
expect(x3.get('stuff')).toEqual([1, {'foo': 'bar'}]);
done();
}, (error) => {
console.error(error);
on_db('mongo', () => {
jfail(error);
});
on_db('postgres', () => {
expect(error.message).toEqual("Postgres does not support Remove operator.");
});
jfail(error);
done();
});
});

View File

@@ -233,7 +233,7 @@ describe('Parse.Query testing', () => {
});
});
it_exclude_dbs(['postgres'])("containsAll date array queries", function(done) {
it("containsAll date array queries", function(done) {
var DateSet = Parse.Object.extend({ className: "DateSet" });
function parseDate(iso8601) {
@@ -289,7 +289,7 @@ describe('Parse.Query testing', () => {
});
});
it_exclude_dbs(['postgres'])("containsAll object array queries", function(done) {
it("containsAll object array queries", function(done) {
var MessageSet = Parse.Object.extend({ className: "MessageSet" });
@@ -872,7 +872,7 @@ describe('Parse.Query testing', () => {
});
});
it_exclude_dbs(['postgres'])("order by descending number and string", function(done) {
it("order by descending number and string", function(done) {
var strings = ["a", "b", "c", "d"];
var makeBoxedNumber = function(num, i) {
return new BoxedNumber({ number: num, string: strings[i] });
@@ -1579,7 +1579,7 @@ describe('Parse.Query testing', () => {
})
});
it_exclude_dbs(['postgres'])('properly includes array of mixed objects', (done) => {
it('properly includes array of mixed objects', (done) => {
let objects = [];
let total = 0;
while(objects.length != 5) {
@@ -2270,7 +2270,7 @@ describe('Parse.Query testing', () => {
});
});
it_exclude_dbs(['postgres'])('notEqual with array of pointers', (done) => {
it('notEqual with array of pointers', (done) => {
var children = [];
var parents = [];
var promises = [];
@@ -2364,7 +2364,7 @@ describe('Parse.Query testing', () => {
});
});
it_exclude_dbs(['postgres'])('query match on array with single object', (done) => {
it('query match on array with single object', (done) => {
var target = {__type: 'Pointer', className: 'TestObject', objectId: 'abc123'};
var obj = new Parse.Object('TestObject');
obj.set('someObjs', [target]);
@@ -2380,7 +2380,7 @@ describe('Parse.Query testing', () => {
});
});
it_exclude_dbs(['postgres'])('query match on array with multiple objects', (done) => {
it('query match on array with multiple objects', (done) => {
var target1 = {__type: 'Pointer', className: 'TestObject', objectId: 'abc'};
var target2 = {__type: 'Pointer', className: 'TestObject', objectId: '123'};
var obj= new Parse.Object('TestObject');
@@ -2449,7 +2449,7 @@ describe('Parse.Query testing', () => {
});
});
it_exclude_dbs(['postgres'])('should find objects with array of pointers', (done) => {
it('should find objects with array of pointers', (done) => {
var objects = [];
while(objects.length != 5) {
var object = new Parse.Object('ContainedObject');
@@ -2488,7 +2488,7 @@ describe('Parse.Query testing', () => {
})
})
it_exclude_dbs(['postgres'])('query with two OR subqueries (regression test #1259)', done => {
it('query with two OR subqueries (regression test #1259)', done => {
let relatedObject = new Parse.Object('Class2');
relatedObject.save().then(relatedObject => {
let anObject = new Parse.Object('Class1');

View File

@@ -296,7 +296,7 @@ describe('Parse.Relation testing', () => {
});
});
it_exclude_dbs(['postgres'])("query on pointer and relation fields with equal", (done) => {
it("query on pointer and relation fields with equal", (done) => {
var ChildObject = Parse.Object.extend("ChildObject");
var childObjects = [];
for (var i = 0; i < 10; i++) {
@@ -377,7 +377,7 @@ describe('Parse.Relation testing', () => {
});
});
it_exclude_dbs(['postgres'])("or queries on pointer and relation fields", (done) => {
it("or queries on pointer and relation fields", (done) => {
var ChildObject = Parse.Object.extend("ChildObject");
var childObjects = [];
for (var i = 0; i < 10; i++) {

View File

@@ -1273,7 +1273,7 @@ describe('Parse.User testing', () => {
// What this means is, only one Parse User can be linked to a
// particular Facebook account.
it_exclude_dbs(['postgres'])("link with provider for already linked user", (done) => {
it("link with provider for already linked user", (done) => {
var provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);
var user = new Parse.User();
@@ -1295,7 +1295,10 @@ describe('Parse.User testing', () => {
user2.signUp(null, {
success: function(model) {
user2._linkWith('facebook', {
success: fail,
success: (err) => {
jfail(err);
done();
},
error: function(model, error) {
expect(error.code).toEqual(
Parse.Error.ACCOUNT_ALREADY_LINKED);
@@ -2066,7 +2069,7 @@ describe('Parse.User testing', () => {
});
});
it_exclude_dbs(['postgres'])('get session only for current user', (done) => {
it('get session only for current user', (done) => {
Parse.Promise.as().then(() => {
return Parse.User.signUp("test1", "test", { foo: "bar" });
}).then(() => {
@@ -2094,7 +2097,7 @@ describe('Parse.User testing', () => {
});
});
it_exclude_dbs(['postgres'])('delete session by object', (done) => {
it('delete session by object', (done) => {
Parse.Promise.as().then(() => {
return Parse.User.signUp("test1", "test", { foo: "bar" });
}).then(() => {

View File

@@ -9,7 +9,7 @@ describe('Pointer Permissions', () => {
new Config(Parse.applicationId).database.schemaCache.clear();
});
it_exclude_dbs(['postgres'])('should work with find', (done) => {
it('should work with find', (done) => {
let config = new Config(Parse.applicationId);
let user = new Parse.User();
let user2 = new Parse.User();
@@ -48,7 +48,7 @@ describe('Pointer Permissions', () => {
});
it_exclude_dbs(['postgres'])('should work with write', (done) => {
it('should work with write', (done) => {
let config = new Config(Parse.applicationId);
let user = new Parse.User();
let user2 = new Parse.User();
@@ -113,7 +113,7 @@ describe('Pointer Permissions', () => {
})
});
it_exclude_dbs(['postgres'])('should let a proper user find', (done) => {
it('should let a proper user find', (done) => {
let config = new Config(Parse.applicationId);
let user = new Parse.User();
let user2 = new Parse.User();
@@ -199,7 +199,7 @@ describe('Pointer Permissions', () => {
})
});
it_exclude_dbs(['postgres'])('should handle multiple writeUserFields', done => {
it('should handle multiple writeUserFields', done => {
let config = new Config(Parse.applicationId);
let user = new Parse.User();
let user2 = new Parse.User();
@@ -281,7 +281,7 @@ describe('Pointer Permissions', () => {
})
});
it_exclude_dbs(['postgres'])('tests CLP / Pointer Perms / ACL write (PP Locked)', (done) => {
it('tests CLP / Pointer Perms / ACL write (PP Locked)', (done) => {
/*
tests:
CLP: update closed ({})
@@ -328,7 +328,7 @@ describe('Pointer Permissions', () => {
});
});
it_exclude_dbs(['postgres'])('tests CLP / Pointer Perms / ACL write (ACL Locked)', (done) => {
it('tests CLP / Pointer Perms / ACL write (ACL Locked)', (done) => {
/*
tests:
CLP: update closed ({})
@@ -373,7 +373,7 @@ describe('Pointer Permissions', () => {
});
});
it_exclude_dbs(['postgres'])('tests CLP / Pointer Perms / ACL write (ACL/PP OK)', (done) => {
it('tests CLP / Pointer Perms / ACL write (ACL/PP OK)', (done) => {
/*
tests:
CLP: update closed ({})
@@ -418,7 +418,7 @@ describe('Pointer Permissions', () => {
});
});
it_exclude_dbs(['postgres'])('tests CLP / Pointer Perms / ACL read (PP locked)', (done) => {
it('tests CLP / Pointer Perms / ACL read (PP locked)', (done) => {
/*
tests:
CLP: find/get open ({})

View File

@@ -357,7 +357,7 @@ describe('PushController', () => {
})
});
it_exclude_dbs(['postgres'])('should support full RESTQuery for increment', (done) => {
it('should support full RESTQuery for increment', (done) => {
var payload = {data: {
alert: "Hello World!",
badge: 'Increment',
@@ -392,7 +392,7 @@ describe('PushController', () => {
pushController.sendPush(payload, where, config, auth).then((result) => {
done();
}).catch((err) => {
fail('should not fail');
jfail(err);
done();
});
});

View File

@@ -11,6 +11,11 @@ var config = new Config('test');
let database = config.database;
describe('rest create', () => {
beforeEach(() => {
config = new Config('test');
});
it('handles _id', done => {
rest.create(config, auth.nobody(config), 'Foo', {})
.then(() => database.adapter.find('Foo', { fields: {} }, {}, {}))
@@ -167,7 +172,7 @@ describe('rest create', () => {
});
});
it_exclude_dbs(['postgres'])('handles anonymous user signup and upgrade to new user', (done) => {
it('handles anonymous user signup and upgrade to new user', (done) => {
var data1 = {
authData: {
anonymous: {
@@ -201,7 +206,7 @@ describe('rest create', () => {
expect(r.get('username')).toEqual('hello');
done();
}).catch((err) => {
fail('should not fail')
jfail(err);
done();
})
});
@@ -227,7 +232,7 @@ describe('rest create', () => {
})
});
it_exclude_dbs(['postgres'])('test facebook signup and login', (done) => {
it('test facebook signup and login', (done) => {
var data = {
authData: {
facebook: {
@@ -257,16 +262,19 @@ describe('rest create', () => {
var output = response.results[0];
expect(output.user.objectId).toEqual(newUserSignedUpByFacebookObjectId);
done();
});
}).catch(err => {
jfail(err);
done();
})
});
it_exclude_dbs(['postgres'])('stores pointers', done => {
it('stores pointers', done => {
let obj = {
foo: 'bar',
aPointer: {
__type: 'Pointer',
className: 'JustThePointer',
objectId: 'qwerty'
objectId: 'qwerty1234' // make it 10 chars to match PG storage
}
};
rest.create(config, auth.nobody(config), 'APointerDarkly', obj)
@@ -283,7 +291,7 @@ describe('rest create', () => {
expect(output.aPointer).toEqual({
__type: 'Pointer',
className: 'JustThePointer',
objectId: 'qwerty'
objectId: 'qwerty1234'
});
done();
});
@@ -344,7 +352,7 @@ describe('rest create', () => {
});
});
it_exclude_dbs(['postgres'])("test specified session length", (done) => {
it("test specified session length", (done) => {
var user = {
username: 'asdf',
password: 'zxcv',
@@ -376,11 +384,14 @@ describe('rest create', () => {
expect(actual.getHours()).toEqual(expected.getHours());
expect(actual.getMinutes()).toEqual(expected.getMinutes());
done();
}).catch(err => {
jfail(err);
done();
});
});
it_exclude_dbs(['postgres'])("can create a session with no expiration", (done) => {
it("can create a session with no expiration", (done) => {
var user = {
username: 'asdf',
password: 'zxcv',
@@ -404,6 +415,10 @@ describe('rest create', () => {
expect(session.expiresAt).toBeUndefined();
done();
});
}).catch(err => {
console.error(err);
fail(err);
done();
})
});
});

View File

@@ -10,7 +10,7 @@ global.on_db = (db, callback, elseCallback) => {
return callback();
}
if (elseCallback) {
elseCallback();
return elseCallback();
}
}

View File

@@ -1286,10 +1286,8 @@ describe('schemas', () => {
}).then((results) => {
expect(results.length).toBe(1);
done();
}, () => {
fail("should not fail!");
done();
}).catch( (err) => {
jfail(err);
done();
})
});
@@ -1351,15 +1349,13 @@ describe('schemas', () => {
}).then((results) => {
expect(results.length).toBe(1);
done();
}, (err) => {
fail("should not fail!");
done();
}).catch( (err) => {
jfail(err);
done();
})
});
it_exclude_dbs(['postgres'])('validate CLP 3', done => {
it('validate CLP 3', done => {
let user = new Parse.User();
user.setUsername('user');
user.setPassword('user');
@@ -1411,8 +1407,8 @@ describe('schemas', () => {
}).then((results) => {
expect(results.length).toBe(1);
done();
}, (err) => {
fail("should not fail!");
}).catch((err) => {
jfail(err);
done();
});
});
@@ -1477,10 +1473,8 @@ describe('schemas', () => {
}).then((results) => {
expect(results.length).toBe(1);
done();
}, (err) => {
fail("should not fail!");
done();
}).catch( (err) => {
jfail(err);
done();
})
});