2015-07-20 00:09:47 -07:00
|
|
|
/* jslint node:true */
|
2026-02-14 09:53:14 +01:00
|
|
|
|
|
|
|
|
import constants from '../constants.js';
|
|
|
|
|
import expect from 'expect.js';
|
|
|
|
|
import safe from 'safetydance';
|
2026-02-14 15:43:24 +01:00
|
|
|
import server from '../server.js';
|
2026-02-14 09:53:14 +01:00
|
|
|
import superagent from '@cloudron/superagent';
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
const SERVER_URL = 'http://localhost:' + constants.PORT;
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
describe('Server', function () {
|
|
|
|
|
describe('startup', function () {
|
2021-09-07 09:57:49 -07:00
|
|
|
after(server.stop);
|
|
|
|
|
|
|
|
|
|
it('succeeds', async function () {
|
|
|
|
|
await server.start();
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
it('is reachable', async function () {
|
|
|
|
|
const response = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
|
|
|
|
|
expect(response.status).to.equal(200);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
it('should fail because already running', async function () {
|
|
|
|
|
const [error] = await safe(server.start());
|
|
|
|
|
expect(error).to.be.ok();
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('runtime', function () {
|
2021-09-07 09:57:49 -07:00
|
|
|
before(server.start);
|
|
|
|
|
after(server.stop);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
it('random bad superagents', async function () {
|
|
|
|
|
const response = await superagent.get(SERVER_URL + '/random').ok(() => true);
|
|
|
|
|
expect(response.status).to.equal(404);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
it('version', async function () {
|
|
|
|
|
const response = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
|
|
|
|
|
expect(response.status).to.equal(200);
|
|
|
|
|
expect(response.body.version).to.contain('-test');
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
it('status route is GET', async function () {
|
|
|
|
|
const response = await superagent.post(SERVER_URL + '/api/v1/cloudron/status').ok(() => true);
|
|
|
|
|
expect(response.status).to.equal(404);
|
2017-11-27 18:05:16 -08:00
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
const response2 = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
|
2025-02-14 17:26:54 +01:00
|
|
|
expect(response2.status).to.equal(200);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('config', function () {
|
2021-09-07 09:57:49 -07:00
|
|
|
before(server.start);
|
|
|
|
|
after(server.stop);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
it('config fails due missing token', async function () {
|
2023-08-12 21:47:24 +05:30
|
|
|
const response = await superagent.get(SERVER_URL + '/api/v1/dashboard/config').ok(() => true);
|
2025-02-14 17:26:54 +01:00
|
|
|
expect(response.status).to.equal(401);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
it('config fails due wrong token', async function () {
|
2023-08-12 21:47:24 +05:30
|
|
|
const response = await superagent.get(SERVER_URL + '/api/v1/dashboard/config').query({ access_token: 'somewrongtoken' }).ok(() => true);
|
2021-08-20 09:19:44 -07:00
|
|
|
expect(response.status).to.equal(401);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('shutdown', function () {
|
2021-09-07 09:57:49 -07:00
|
|
|
before(server.stop);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2021-08-20 09:19:44 -07:00
|
|
|
it('is not reachable anymore', async function () {
|
|
|
|
|
const [error] = await safe(superagent.get(SERVER_URL + '/api/v1/cloudron/status').ok(() => true));
|
|
|
|
|
expect(error).to.not.be(null);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|