Skip to content

Add more postgres support #2080

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 2 commits into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 20 additions & 14 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ var request = require('request');
const rp = require('request-promise');
const Parse = require("parse/node");
let Config = require('../src/Config');
let defaultColumns = require('../src/Controllers/SchemaController').defaultColumns;
const SchemaController = require('../src/Controllers/SchemaController');
var TestUtils = require('../src/index').TestUtils;
const deepcopy = require('deepcopy');

const requiredUserFields = { fields: Object.assign({}, defaultColumns._Default, defaultColumns._User) };
const userSchema = SchemaController.convertSchemaToAdapterSchema({ className: '_User', fields: Object.assign({}, SchemaController.defaultColumns._Default, SchemaController.defaultColumns._User) });

describe('miscellaneous', function() {
it('create a GameScore object', function(done) {
Expand Down Expand Up @@ -131,24 +132,27 @@ describe('miscellaneous', function() {
let config = new Config('test');
// Remove existing data to clear out unique index
TestUtils.destroyAllDataPermanently()
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'x', username: 'u' }))
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'y', username: 'u' }))
.then(() => config.database.adapter.createClass('_User', userSchema))
.then(() => config.database.adapter.createObject('_User', userSchema, { objectId: 'x', username: 'u' }).catch(fail))
.then(() => config.database.adapter.createObject('_User', userSchema, { objectId: 'y', username: 'u' }).catch(fail))
// Create a new server to try to recreate the unique indexes
.then(reconfigureServer)
.catch(() => {
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('zxcv');
// Sign up with new email still works
return user.signUp().catch(fail);
})
.then(() => {
let user = new Parse.User();
user.setPassword('asdf');
user.setUsername('u');
// sign up with duplicate username doens't
return user.signUp()
})
.then(result => {
fail('should not have been able to sign up');
done();
})
.catch(error => {
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
done();
Expand All @@ -159,8 +163,9 @@ describe('miscellaneous', function() {
let config = new Config('test');
// Remove existing data to clear out unique index
TestUtils.destroyAllDataPermanently()
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'x', email: '[email protected]' }))
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'y', email: '[email protected]' }))
.then(() => config.database.adapter.createClass('_User', userSchema))
.then(() => config.database.adapter.createObject('_User', userSchema, { objectId: 'x', email: '[email protected]' }))
.then(() => config.database.adapter.createObject('_User', userSchema, { objectId: 'y', email: '[email protected]' }))
.then(reconfigureServer)
.catch(() => {
let user = new Parse.User();
Expand All @@ -184,7 +189,8 @@ describe('miscellaneous', function() {

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.ensureUniqueness('_User', requiredUserFields, ['randomField'])
config.database.adapter.addFieldIfNotExists('_User', 'randomField', { type: 'String' })
.then(() => config.database.adapter.ensureUniqueness('_User', userSchema, ['randomField']))
.then(() => {
let user = new Parse.User();
user.setPassword('asdf');
Expand Down Expand Up @@ -277,7 +283,7 @@ describe('miscellaneous', function() {
expect(results.length).toEqual(1);
done();
}, (error) => {
fail(error);
fail(JSON.stringify(error));
done();
});
});
Expand All @@ -292,8 +298,8 @@ describe('miscellaneous', function() {
}).then((results) => {
expect(results.length).toEqual(100);
done();
}, (error) => {
fail(error);
}, error => {
fail(JSON.stringify(error));
done();
});
});
Expand Down Expand Up @@ -335,8 +341,8 @@ describe('miscellaneous', function() {
fail(error);
done();
});
}, function(error) {
fail(error);
}, error => {
fail(JSON.stringify(error));
done();
});
});
Expand Down
3 changes: 1 addition & 2 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,10 @@ describe('SchemaController', () => {
_id: '_User',
username: { type: 'String' },
password: { type: 'String' },
authData: { type: 'Object' },
email: { type: 'String' },
emailVerified: { type: 'Boolean' },
},{
authData: { type: 'String' },
emailVerified: { type: 'String' },
customField: { type: 'String' },
})).toEqual({
customField: { type: 'String' }
Expand Down
72 changes: 48 additions & 24 deletions spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ var pointersAndRelationsSchema = {
classLevelPermissions: defaultClassLevelPermissions
}

const userSchema = {
"className": "_User",
"fields": {
"objectId": {"type": "String"},
"createdAt": {"type": "Date"},
"updatedAt": {"type": "Date"},
"ACL": {"type": "ACL"},
"username": {"type": "String"},
"password": {"type": "String"},
"email": {"type": "String"},
"emailVerified": {"type": "Boolean"}
},
"classLevelPermissions": defaultClassLevelPermissions,
}

var noAuthHeaders = {
'X-Parse-Application-Id': 'test',
};
Expand Down Expand Up @@ -139,13 +154,13 @@ describe('schemas', () => {
});
});

it('responds with empty list when there are no schemas', done => {
it('creates _User schema when server starts', done => {
request.get({
url: 'http://localhost:8378/1/schemas',
json: true,
headers: masterKeyHeaders,
}, (error, response, body) => {
expect(body.results).toEqual([]);
expect(dd(body.results, [userSchema])).toEqual();
done();
});
});
Expand All @@ -165,9 +180,9 @@ describe('schemas', () => {
headers: masterKeyHeaders,
}, (error, response, body) => {
var expected = {
results: [plainOldDataSchema,pointersAndRelationsSchema]
results: [userSchema,plainOldDataSchema,pointersAndRelationsSchema]
};
expect(body).toEqual(expected);
expect(dd(body, expected)).toEqual(undefined);
done();
})
});
Expand Down Expand Up @@ -328,31 +343,43 @@ describe('schemas', () => {

it('responds with all fields when getting incomplete schema', done => {
config.database.loadSchema()
.then(schemaController => schemaController.addClassIfNotExists('_User', {}, defaultClassLevelPermissions))
.then(schemaController => schemaController.addClassIfNotExists('_Installation', {}, defaultClassLevelPermissions))
.then(() => {
request.get({
url: 'http://localhost:8378/1/schemas/_User',
url: 'http://localhost:8378/1/schemas/_Installation',
headers: masterKeyHeaders,
json: true
}, (error, response, body) => {
expect(body).toEqual({
className: '_User',
expect(dd(body,{
className: '_Installation',
fields: {
objectId: {type: 'String'},
updatedAt: {type: 'Date'},
createdAt: {type: 'Date'},
username: {type: 'String'},
password: {type: 'String'},
authData: {type: 'Object'},
email: {type: 'String'},
emailVerified: {type: 'Boolean'},
installationId: {type: 'String'},
deviceToken: {type: 'String'},
channels: {type: 'Array'},
deviceType: {type: 'String'},
pushType: {type: 'String'},
GCMSenderId: {type: 'String'},
timeZone: {type: 'String'},
badge: {type: 'Number'},
appIdentifier: {type: 'String'},
localeIdentifier: {type: 'String'},
appVersion: {type: 'String'},
appName: {type: 'String'},
parseVersion: {type: 'String'},
ACL: {type: 'ACL'}
},
classLevelPermissions: defaultClassLevelPermissions
});
})).toBeUndefined();
done();
});
})
.catch(error => {
fail(JSON.stringify(error))
done();
});
});

it('lets you specify class name in both places', done => {
Expand Down Expand Up @@ -634,43 +661,41 @@ describe('schemas', () => {
}
}
}, (error, response, body) => {
expect(body).toEqual({
expect(dd(body,{
className: '_User',
fields: {
objectId: {type: 'String'},
updatedAt: {type: 'Date'},
createdAt: {type: 'Date'},
username: {type: 'String'},
password: {type: 'String'},
authData: {type: 'Object'},
email: {type: 'String'},
emailVerified: {type: 'Boolean'},
newField: {type: 'String'},
ACL: {type: 'ACL'}
},
classLevelPermissions: defaultClassLevelPermissions
});
})).toBeUndefined();
request.get({
url: 'http://localhost:8378/1/schemas/_User',
headers: masterKeyHeaders,
json: true
}, (error, response, body) => {
expect(body).toEqual({
expect(dd(body,{
className: '_User',
fields: {
objectId: {type: 'String'},
updatedAt: {type: 'Date'},
createdAt: {type: 'Date'},
username: {type: 'String'},
password: {type: 'String'},
authData: {type: 'Object'},
email: {type: 'String'},
emailVerified: {type: 'Boolean'},
newField: {type: 'String'},
ACL: {type: 'ACL'}
},
classLevelPermissions: defaultClassLevelPermissions
});
})).toBeUndefined();
done();
});
});
Expand Down Expand Up @@ -1541,14 +1566,13 @@ describe('schemas', () => {
setPermissionsOnClass('_User', {
'create': {'*': true},
'addField': {}
}).then(() => {
}, true).then(() => {
return Parse.User.signUp('foo', 'bar');
}).then((user) => {
expect(user.getUsername()).toBe('foo');
done()
}, (err) => {
console.error(err);
fail('should create user');
}, error => {
fail(JSON.stringify(error));
done();
})
})
Expand Down
Loading