merge appdb.js into apps.js
This commit is contained in:
@@ -6,24 +6,18 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var constants = require('../constants.js'),
|
||||
const constants = require('../constants.js'),
|
||||
database = require('../database.js'),
|
||||
expect = require('expect.js'),
|
||||
safe = require('safetydance'),
|
||||
server = require('../server.js'),
|
||||
superagent = require('superagent'),
|
||||
server = require('../server.js');
|
||||
util = require('util');
|
||||
|
||||
var SERVER_URL = 'http://localhost:' + constants.PORT;
|
||||
const SERVER_URL = 'http://localhost:' + constants.PORT;
|
||||
|
||||
describe('Server', function () {
|
||||
describe('startup', function () {
|
||||
it('start fails due to wrong arguments', function (done) {
|
||||
expect(function () { server.start(); }).to.throwException();
|
||||
expect(function () { server.start('foobar', function () {}); }).to.throwException();
|
||||
expect(function () { server.start(1337, function () {}); }).to.throwException();
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('succeeds', function (done) {
|
||||
server.start(function (error) {
|
||||
expect(error).to.not.be.ok();
|
||||
@@ -31,11 +25,9 @@ describe('Server', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('is reachable', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/cloudron/status', function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
done(err);
|
||||
});
|
||||
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', function (done) {
|
||||
@@ -56,43 +48,28 @@ describe('Server', function () {
|
||||
server.start(done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
database._clear(function (error) {
|
||||
expect(!error).to.be.ok();
|
||||
server.stop(function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
after(async function () {
|
||||
await database._clear();
|
||||
await util.promisify(server.stop)();
|
||||
});
|
||||
|
||||
it('random bad superagents', function (done) {
|
||||
superagent.get(SERVER_URL + '/random', function (err, res) {
|
||||
expect(err).to.be.ok();
|
||||
expect(res.statusCode).to.equal(404);
|
||||
done();
|
||||
});
|
||||
it('random bad superagents', async function () {
|
||||
const response = await superagent.get(SERVER_URL + '/random').ok(() => true);
|
||||
expect(response.status).to.equal(404);
|
||||
});
|
||||
|
||||
it('version', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/cloudron/status', function (err, res) {
|
||||
expect(err).to.not.be.ok();
|
||||
expect(res.statusCode).to.equal(200);
|
||||
expect(res.body.version).to.contain('-test');
|
||||
done();
|
||||
});
|
||||
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', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/cloudron/status')
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(404);
|
||||
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);
|
||||
|
||||
superagent.get(SERVER_URL + '/api/v1/cloudron/status')
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
const response2 = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -107,18 +84,14 @@ describe('Server', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('config fails due missing token', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/config', function (err, res) {
|
||||
expect(res.statusCode).to.equal(401);
|
||||
done();
|
||||
});
|
||||
it('config fails due missing token', async function () {
|
||||
const response = await superagent.get(SERVER_URL + '/api/v1/config').ok(() => true);
|
||||
expect(response.statusCode).to.equal(401);
|
||||
});
|
||||
|
||||
it('config fails due wrong token', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/config').query({ access_token: 'somewrongtoken' }).end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(401);
|
||||
done();
|
||||
});
|
||||
it('config fails due wrong token', async function () {
|
||||
const response = await superagent.get(SERVER_URL + '/api/v1/config').query({ access_token: 'somewrongtoken' }).ok(() => true);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -127,28 +100,15 @@ describe('Server', function () {
|
||||
server.start(done);
|
||||
});
|
||||
|
||||
it('fails due to wrong arguments', function (done) {
|
||||
expect(function () { server.stop(); }).to.throwException();
|
||||
expect(function () { server.stop('foobar'); }).to.throwException();
|
||||
expect(function () { server.stop(1337); }).to.throwException();
|
||||
expect(function () { server.stop({}); }).to.throwException();
|
||||
expect(function () { server.stop({ httpServer: {} }); }).to.throwException();
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('succeeds', function (done) {
|
||||
server.stop(function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('is not reachable anymore', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/cloudron/status', function (error) {
|
||||
expect(error).to.not.be(null);
|
||||
expect(!error.response).to.be.ok();
|
||||
done();
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -159,27 +119,23 @@ describe('Server', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('responds to OPTIONS', function (done) {
|
||||
superagent('OPTIONS', SERVER_URL + '/api/v1/cloudron/status')
|
||||
it('responds to OPTIONS', async function () {
|
||||
const response = await superagent('OPTIONS', SERVER_URL + '/api/v1/cloudron/status')
|
||||
.set('Access-Control-Request-Method', 'GET')
|
||||
.set('Access-Control-Request-Headers', 'accept, origin, x-superagented-with')
|
||||
.set('Origin', 'http://localhost')
|
||||
.end(function (error, res) {
|
||||
expect(res.headers['access-control-allow-methods']).to.be('GET, PUT, DELETE, POST, OPTIONS');
|
||||
expect(res.headers['access-control-allow-credentials']).to.be('false');
|
||||
expect(res.headers['access-control-allow-headers']).to.be('accept, origin, x-superagented-with'); // mirrored from superagent
|
||||
expect(res.headers['access-control-allow-origin']).to.be('http://localhost'); // mirrors from superagent
|
||||
done();
|
||||
});
|
||||
.set('Origin', 'http://localhost');
|
||||
|
||||
expect(response.headers['access-control-allow-methods']).to.be('GET, PUT, DELETE, POST, OPTIONS');
|
||||
expect(response.headers['access-control-allow-credentials']).to.be('false');
|
||||
expect(response.headers['access-control-allow-headers']).to.be('accept, origin, x-superagented-with'); // mirrored from superagent
|
||||
expect(response.headers['access-control-allow-origin']).to.be('http://localhost'); // mirrors from superagent
|
||||
});
|
||||
|
||||
it('does not crash for malformed origin', function (done) {
|
||||
superagent('OPTIONS', SERVER_URL + '/api/v1/cloudron/status')
|
||||
it('does not crash for malformed origin', async function () {
|
||||
const response = await superagent('OPTIONS', SERVER_URL + '/api/v1/cloudron/status')
|
||||
.set('Origin', 'foobar')
|
||||
.end(function (error, res) {
|
||||
expect(res.statusCode).to.be(405);
|
||||
done();
|
||||
});
|
||||
.ok(() => true);
|
||||
expect(response.status).to.be(405);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
|
||||
Reference in New Issue
Block a user