sorry i ever left you dear mocha node:test has two major issues: * --bail does not work and requires strange modules and incantations. I was able to work around this with a custom module. * the test reporter reports _after_ the suite is run. this makes debugging really hard. the debugs that we print all happen before the test suite summary. poor design overall.
78 lines
2.7 KiB
JavaScript
78 lines
2.7 KiB
JavaScript
import { describe, it, before, after } from 'mocha';
|
|
import constants from '../constants.js';
|
|
import assert from 'node:assert/strict';
|
|
import safe from 'safetydance';
|
|
import server from '../server.js';
|
|
import superagent from '@cloudron/superagent';
|
|
|
|
|
|
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');
|
|
assert.equal(response.status, 200);
|
|
});
|
|
|
|
it('should fail because already running', async function () {
|
|
const [error] = await safe(server.start());
|
|
assert.ok(error);
|
|
});
|
|
});
|
|
|
|
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);
|
|
assert.equal(response.status, 404);
|
|
});
|
|
|
|
it('version', async function () {
|
|
const response = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
|
|
assert.equal(response.status, 200);
|
|
assert.ok(response.body.version.includes('-test'));
|
|
});
|
|
|
|
it('status route is GET', async function () {
|
|
const response = await superagent.post(SERVER_URL + '/api/v1/cloudron/status').ok(() => true);
|
|
assert.equal(response.status, 404);
|
|
|
|
const response2 = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
|
|
assert.equal(response2.status, 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);
|
|
assert.equal(response.status, 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);
|
|
assert.equal(response.status, 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));
|
|
assert.notEqual(error, null);
|
|
});
|
|
});
|
|
});
|