Merge pull request #2053 from drew-gross/postgres-3

Continue with postgres support
This commit is contained in:
Fosco Marotto
2016-06-16 10:19:07 -07:00
committed by GitHub
18 changed files with 412 additions and 196 deletions

View File

@@ -49,7 +49,7 @@ describe('MongoStorageAdapter', () => {
it('stores objectId in _id', done => {
let adapter = new MongoStorageAdapter({ uri: databaseURI });
adapter.createObject('Foo', {}, { objectId: 'abcde' })
adapter.createObject('Foo', { fields: {} }, { objectId: 'abcde' })
.then(() => adapter._rawFind('Foo', {}))
.then(results => {
expect(results.length).toEqual(1);

View File

@@ -37,7 +37,10 @@ describe('miscellaneous', function() {
expect(obj2.id).toEqual(obj.id);
done();
},
error: fail
error: error => {
fail(JSON.stringify(error));
done();
}
});
});
});
@@ -48,8 +51,8 @@ describe('miscellaneous', function() {
expect(data.getSessionToken()).not.toBeUndefined();
expect(data.get('password')).toBeUndefined();
done();
}, function(err) {
fail(err);
}, error => {
fail(JSON.stringify(error));
done();
});
});
@@ -86,9 +89,8 @@ describe('miscellaneous', function() {
});
it('ensure that email is uniquely indexed', done => {
let numCreated = 0;
let numFailed = 0;
let numCreated = 0;
let user1 = new Parse.User();
user1.setPassword('asdf');
user1.setUsername('u1');
@@ -215,8 +217,9 @@ describe('miscellaneous', function() {
expect(user.get('password')).toBeUndefined();
expect(user.getSessionToken()).not.toBeUndefined();
Parse.User.logOut().then(done);
}, error: function(error) {
fail(error);
}, error: error => {
fail(JSON.stringify(error));
done();
}
});
}, fail);
@@ -232,15 +235,14 @@ describe('miscellaneous', function() {
expect(user.get('foo')).toEqual(1);
user.increment('foo');
return user.save();
}).then(() => {
Parse.User.logOut();
return Parse.User.logIn('test', 'moon-y');
}).then((user) => {
}).then(() => Parse.User.logOut())
.then(() => Parse.User.logIn('test', 'moon-y'))
.then((user) => {
expect(user.get('foo')).toEqual(2);
Parse.User.logOut()
.then(done);
}, (error) => {
fail(error);
fail(JSON.stringify(error));
done();
});
});

View File

@@ -24,7 +24,7 @@ describe('Installations', () => {
'deviceType': device
};
rest.create(config, auth.nobody(config), '_Installation', input)
.then(() => config.database.adapter.find('_Installation', installationSchema, {}, {}))
.then(() => database.adapter.find('_Installation', installationSchema, {}, {}))
.then(results => {
expect(results.length).toEqual(1);
var obj = results[0];
@@ -42,7 +42,7 @@ describe('Installations', () => {
'deviceType': device
};
rest.create(config, auth.nobody(config), '_Installation', input)
.then(() => config.database.adapter.find('_Installation', installationSchema, {}, {}))
.then(() => database.adapter.find('_Installation', installationSchema, {}, {}))
.then(results => {
expect(results.length).toEqual(1);
var obj = results[0];
@@ -60,7 +60,7 @@ describe('Installations', () => {
'deviceType': device
};
rest.create(config, auth.nobody(config), '_Installation', input)
.then(() => config.database.adapter.find('_Installation', installationSchema, {}, {}))
.then(() => database.adapter.find('_Installation', installationSchema, {}, {}))
.then(results => {
expect(results.length).toEqual(1);
var obj = results[0];

View File

@@ -10,6 +10,7 @@
var request = require('request');
var passwordCrypto = require('../src/password');
var Config = require('../src/Config');
const rp = require('request-promise');
function verifyACL(user) {
const ACL = user.getACL();
@@ -2131,7 +2132,7 @@ describe('Parse.User testing', () => {
let database = new Config(Parse.applicationId).database;
database.create('_User', {
username: 'user',
password: '$2a$10$8/wZJyEuiEaobBBqzTG.jeY.XSFJd0rzaN//ososvEI4yLqI.4aie',
_hashed_password: '$2a$10$8/wZJyEuiEaobBBqzTG.jeY.XSFJd0rzaN//ososvEI4yLqI.4aie',
_auth_data_facebook: null
}, {}).then(() => {
return new Promise((resolve, reject) => {
@@ -2258,42 +2259,43 @@ describe('Parse.User testing', () => {
});
it('should fail to become user with expired token', (done) => {
Parse.User.signUp("auser", "somepass", null, {
success: function(user) {
request.get({
url: 'http://localhost:8378/1/classes/_Session',
json: true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
}, (error, response, body) => {
var id = body.results[0].objectId;
var expiresAt = new Date((new Date()).setYear(2015));
var token = body.results[0].sessionToken;
request.put({
url: "http://localhost:8378/1/classes/_Session/" + id,
json: true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
body: {
expiresAt: { __type: "Date", iso: expiresAt.toISOString() },
},
}, (error, response, body) => {
Parse.User.become(token)
.then(() => { fail("Should not have succeded"); })
.fail((err) => {
expect(err.code).toEqual(209);
expect(err.message).toEqual("Session token is expired.");
Parse.User.logOut() // Logout to prevent polluting CLI with messages
.then(done());
});
});
});
}
});
let token;
Parse.User.signUp("auser", "somepass", null)
.then(user => rp({
method: 'GET',
url: 'http://localhost:8378/1/classes/_Session',
json: true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
}))
.then(body => {
var id = body.results[0].objectId;
var expiresAt = new Date((new Date()).setYear(2015));
token = body.results[0].sessionToken;
return rp({
method: 'PUT',
url: "http://localhost:8378/1/classes/_Session/" + id,
json: true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
body: {
expiresAt: { __type: "Date", iso: expiresAt.toISOString() },
},
})
})
.then(() => Parse.User.become(token))
.then(() => {
fail("Should not have succeded")
done();
}, error => {
expect(error.code).toEqual(209);
expect(error.message).toEqual("Session token is expired.");
done();
})
});
it('should not create extraneous session tokens', (done) => {

View File

@@ -36,8 +36,8 @@ describe('Pointer Permissions', () => {
expect(res.length).toBe(1);
expect(res[0].id).toBe(obj.id);
done();
}).catch((err) => {
fail('Should not fail');
}).catch(error => {
fail(JSON.stringify(error));
done();
});
});

View File

@@ -693,7 +693,7 @@ describe('SchemaController', () => {
objectId: { type: 'String' },
updatedAt: { type: 'Date' },
createdAt: { type: 'Date' },
ACL: { type: 'ACL' }
ACL: { type: 'ACL' },
};
expect(dd(schema.data.NewClass, expectedSchema)).toEqual(undefined);
done();

View File

@@ -11,7 +11,6 @@ var ParseServer = require('../src/index').ParseServer;
var path = require('path');
var TestUtils = require('../src/index').TestUtils;
var MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
const GridStoreAdapter = require('../src/Adapters/Files/GridStoreAdapter').GridStoreAdapter;
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
@@ -30,7 +29,6 @@ if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
})
}
var port = 8378;
let gridStoreAdapter = new GridStoreAdapter(mongoURI);
@@ -142,6 +140,12 @@ beforeEach(done => {
});
afterEach(function(done) {
let afterLogOut = () => {
if (Object.keys(openConnections).length > 0) {
fail('There were open connections to the server left after the test finished');
}
done();
};
Parse.Cloud._removeAllHooks();
databaseAdapter.getAllClasses()
.then(allSchemas => {
@@ -159,16 +163,7 @@ afterEach(function(done) {
});
})
.then(() => Parse.User.logOut())
.then(() => {
if (Object.keys(openConnections).length > 0) {
fail('There were open connections to the server left after the test finished');
}
done();
})
.catch(error => {
fail(JSON.stringify(error));
done();
});
.then(afterLogOut, afterLogOut)
});
var TestObject = Parse.Object.extend({