2017-10-17 11:49:28 -07:00
|
|
|
'use strict';
|
|
|
|
|
/* Tests for ParseServer.js */
|
|
|
|
|
const express = require('express');
|
2018-07-02 23:30:14 -04:00
|
|
|
const ParseServer = require('../lib/ParseServer').default;
|
2019-05-14 11:34:51 -07:00
|
|
|
const path = require('path');
|
|
|
|
|
const { spawn } = require('child_process');
|
2017-10-17 11:49:28 -07:00
|
|
|
|
|
|
|
|
describe('Server Url Checks', () => {
|
2018-06-29 17:09:51 -04:00
|
|
|
let server;
|
2021-03-13 09:05:22 -06:00
|
|
|
beforeEach(done => {
|
|
|
|
|
if (!server) {
|
|
|
|
|
const app = express();
|
|
|
|
|
app.get('/health', function (req, res) {
|
|
|
|
|
res.json({
|
|
|
|
|
status: 'ok',
|
|
|
|
|
});
|
2018-06-29 17:09:51 -04:00
|
|
|
});
|
2021-03-13 09:05:22 -06:00
|
|
|
server = app.listen(13376, undefined, done);
|
|
|
|
|
} else {
|
|
|
|
|
done();
|
|
|
|
|
}
|
2018-06-29 17:09:51 -04:00
|
|
|
});
|
|
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
afterAll(done => {
|
2021-03-13 09:05:22 -06:00
|
|
|
Parse.serverURL = 'http://localhost:8378/1';
|
2018-06-29 17:09:51 -04:00
|
|
|
server.close(done);
|
2017-10-17 11:49:28 -07:00
|
|
|
});
|
|
|
|
|
|
2023-01-09 04:23:01 +11:00
|
|
|
it('validate good server url', async () => {
|
2017-10-17 11:49:28 -07:00
|
|
|
Parse.serverURL = 'http://localhost:13376';
|
2023-01-09 04:23:01 +11:00
|
|
|
const response = await ParseServer.verifyServerUrl();
|
|
|
|
|
expect(response).toBeTrue();
|
2017-10-17 11:49:28 -07:00
|
|
|
});
|
|
|
|
|
|
2023-01-09 04:23:01 +11:00
|
|
|
it('mark bad server url', async () => {
|
2019-12-03 18:21:12 -06:00
|
|
|
spyOn(console, 'warn').and.callFake(() => {});
|
2017-10-17 11:49:28 -07:00
|
|
|
Parse.serverURL = 'notavalidurl';
|
2023-01-09 04:23:01 +11:00
|
|
|
const response = await ParseServer.verifyServerUrl();
|
|
|
|
|
expect(response).not.toBeTrue();
|
|
|
|
|
expect(console.warn).toHaveBeenCalledWith(
|
|
|
|
|
`\nWARNING, Unable to connect to 'notavalidurl' as the URL is invalid. Cloud code and push notifications may be unavailable!\n`
|
|
|
|
|
);
|
2017-10-17 11:49:28 -07:00
|
|
|
});
|
2017-11-19 04:20:19 +08:00
|
|
|
|
2019-05-14 11:34:51 -07:00
|
|
|
it('does not have unhandled promise rejection in the case of load error', done => {
|
2020-10-25 15:06:58 -05:00
|
|
|
const parseServerProcess = spawn(path.resolve(__dirname, './support/FailingServer.js'));
|
2019-05-14 11:34:51 -07:00
|
|
|
let stdout;
|
|
|
|
|
let stderr;
|
|
|
|
|
parseServerProcess.stdout.on('data', data => {
|
|
|
|
|
stdout = data.toString();
|
|
|
|
|
});
|
|
|
|
|
parseServerProcess.stderr.on('data', data => {
|
|
|
|
|
stderr = data.toString();
|
|
|
|
|
});
|
2021-03-13 09:05:22 -06:00
|
|
|
parseServerProcess.on('close', async code => {
|
2019-05-14 11:34:51 -07:00
|
|
|
expect(code).toEqual(1);
|
2021-04-05 02:28:28 +02:00
|
|
|
expect(stdout).not.toContain('UnhandledPromiseRejectionWarning');
|
2026-01-25 00:15:01 +01:00
|
|
|
expect(stderr).toContain('Database error');
|
2021-03-13 09:05:22 -06:00
|
|
|
await reconfigureServer();
|
2019-05-14 11:34:51 -07:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-10-17 11:49:28 -07:00
|
|
|
});
|