-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathParseServer.spec.js
116 lines (110 loc) · 3.46 KB
/
ParseServer.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'use strict';
/* Tests for ParseServer.js */
const express = require('express');
const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageAdapter').default;
const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter')
.default;
const ParseServer = require('../lib/ParseServer').default;
const path = require('path');
const { spawn } = require('child_process');
describe('Server Url Checks', () => {
let server;
beforeEach(done => {
if (!server) {
const app = express();
app.get('/health', function (req, res) {
res.json({
status: 'ok',
});
});
server = app.listen(13376, undefined, done);
} else {
done();
}
});
afterAll(done => {
Parse.serverURL = 'http://localhost:8378/1';
server.close(done);
});
it('validate good server url', done => {
Parse.serverURL = 'http://localhost:13376';
ParseServer.verifyServerUrl(async result => {
if (!result) {
done.fail('Did not pass valid url');
}
await reconfigureServer();
done();
});
});
it('mark bad server url', done => {
spyOn(console, 'warn').and.callFake(() => {});
Parse.serverURL = 'notavalidurl';
ParseServer.verifyServerUrl(async result => {
if (result) {
done.fail('Did not mark invalid url');
}
await reconfigureServer();
done();
});
});
xit('handleShutdown, close connection', done => {
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
let databaseAdapter;
if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
databaseAdapter = new PostgresStorageAdapter({
uri: process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI,
collectionPrefix: 'test_',
});
} else {
databaseAdapter = new MongoStorageAdapter({
uri: mongoURI,
collectionPrefix: 'test_',
});
}
let close = false;
const newConfiguration = Object.assign({}, defaultConfiguration, {
databaseAdapter,
serverStartComplete: () => {
let promise = Promise.resolve();
if (process.env.PARSE_SERVER_TEST_DB !== 'postgres') {
promise = parseServer.config.filesController.adapter._connect();
}
promise.then(() => {
parseServer.handleShutdown();
parseServer.server.close(err => {
if (err) {
done.fail('Close Server Error');
}
reconfigureServer({}).then(() => {
expect(close).toBe(true);
done();
});
});
});
},
serverCloseComplete: () => {
close = true;
},
});
const parseServer = ParseServer.start(newConfiguration);
});
it('does not have unhandled promise rejection in the case of load error', done => {
const parseServerProcess = spawn(path.resolve(__dirname, './support/FailingServer.js'));
let stdout;
let stderr;
parseServerProcess.stdout.on('data', data => {
stdout = data.toString();
});
parseServerProcess.stderr.on('data', data => {
stderr = data.toString();
});
parseServerProcess.on('close', async code => {
expect(code).toEqual(1);
expect(stdout).toBeUndefined();
expect(stderr).toContain('MongoServerSelectionError');
await reconfigureServer();
done();
});
});
});