Skip to content

Commit 3c12559

Browse files
committed
Use isolated parse-server to not impeed on other specs
1 parent cb6d7f8 commit 3c12559

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

spec/PostgresInitOptions.spec.js

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const Parse = require('parse/node').Parse;
22
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
33
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
4-
const Config = require('../src/Config');
4+
var ParseServer = require("../src/index");
5+
var express = require('express');
56
//public schema
67
const databaseOptions1 = {
78
initOptions: {
@@ -28,47 +29,54 @@ const GameScore = Parse.Object.extend({
2829
className: "GameScore"
2930
});
3031

32+
function createParseServer(options) {
33+
return new Promise((resolve, reject) => {
34+
const parseServer = new ParseServer.default(Object.assign({},
35+
defaultConfiguration, options, {
36+
serverURL: "http://localhost:12666/parse",
37+
__indexBuildCompletionCallbackForTests: promise => {
38+
promise
39+
.then(() => {
40+
expect(Parse.applicationId).toEqual("test");
41+
var app = express();
42+
app.use('/parse', parseServer.app);
43+
44+
const server = app.listen(12666);
45+
Parse.serverURL = "http://localhost:12666/parse";
46+
resolve(server);
47+
}, reject);
48+
}}));
49+
});
50+
}
51+
3152
describe_only_db('postgres')('Postgres database init options', () => {
53+
let server;
54+
3255
afterEach(() => {
33-
defaultConfiguration.databaseAdapter = new PostgresStorageAdapter({
34-
uri: process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI,
35-
collectionPrefix: 'test_',
36-
});
37-
});
56+
if (server) {
57+
server.close();
58+
}
59+
})
3860

3961
it('should create server with public schema databaseOptions', (done) => {
40-
const config = new Config('test');
41-
// Close the current DB before continueing
42-
config.database.adapter._pgp.end();
43-
reconfigureServer({
44-
databaseAdapter: new PostgresStorageAdapter({
45-
uri: postgresURI, collectionPrefix: 'test_',
46-
databaseOptions: databaseOptions1
47-
})
62+
const adapter = new PostgresStorageAdapter({
63+
uri: postgresURI, collectionPrefix: 'test_',
64+
databaseOptions: databaseOptions1
4865
})
49-
.then(() => {
50-
var score = new GameScore({ "score": 1337, "playerName": "Sean Plott", "cheatMode": false });
51-
return score.save();
52-
})
53-
.then(done, done.fail);
66+
67+
createParseServer({ databaseAdapter: adapter }).then((newServer) => {
68+
server = newServer;
69+
var score = new GameScore({ "score": 1337, "playerName": "Sean Plott", "cheatMode": false });
70+
return score.save();
71+
}).then(done, done.fail);
5472
});
5573

5674
it('should fail to create server if schema databaseOptions does not exist', (done) => {
57-
const config = new Config('test');
58-
// Close the current DB before continueing
59-
config.database.adapter._pgp.end();
60-
reconfigureServer({
61-
databaseAdapter: new PostgresStorageAdapter({
62-
uri: postgresURI, collectionPrefix: 'test_',
63-
databaseOptions: databaseOptions2
64-
})
65-
}).then(() => {
66-
done.fail('Should not succeed');
67-
}, error => {
68-
// INVALID_SCHEMA error 3F000
69-
// https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
70-
expect(error.code).toEqual('3F000');
71-
done();
72-
});
75+
const adapter = new PostgresStorageAdapter({
76+
uri: postgresURI, collectionPrefix: 'test_',
77+
databaseOptions: databaseOptions2
78+
})
79+
80+
createParseServer({ databaseAdapter: adapter }).then(done.fail, done);
7381
});
7482
});

0 commit comments

Comments
 (0)