Files
cloudron-box/src/test/server-test.js
T
Girish Ramakrishnan 113aba0897 remove the cors test
2026-02-17 17:15:30 +01:00

83 lines
2.8 KiB
JavaScript

/* jslint node:true */
import constants from '../constants.js';
import expect from 'expect.js';
import safe from 'safetydance';
import server from '../server.js';
import superagent from '@cloudron/superagent';
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
const SERVER_URL = 'http://localhost:' + constants.PORT;
describe('Server', function () {
describe('startup', function () {
after(server.stop);
it('succeeds', async function () {
await server.start();
});
it('is reachable', async function () {
const response = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
expect(response.status).to.equal(200);
});
it('should fail because already running', async function () {
const [error] = await safe(server.start());
expect(error).to.be.ok();
});
});
describe('runtime', function () {
before(server.start);
after(server.stop);
it('random bad superagents', async function () {
const response = await superagent.get(SERVER_URL + '/random').ok(() => true);
expect(response.status).to.equal(404);
});
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');
});
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);
const response2 = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
expect(response2.status).to.equal(200);
});
});
describe('config', function () {
before(server.start);
after(server.stop);
it('config fails due missing token', async function () {
const response = await superagent.get(SERVER_URL + '/api/v1/dashboard/config').ok(() => true);
expect(response.status).to.equal(401);
});
it('config fails due wrong token', async function () {
const response = await superagent.get(SERVER_URL + '/api/v1/dashboard/config').query({ access_token: 'somewrongtoken' }).ok(() => true);
expect(response.status).to.equal(401);
});
});
describe('shutdown', function () {
before(server.stop);
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);
});
});
});