55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
const async = require('async'),
|
||
|
|
constants = require('../../constants.js'),
|
||
|
|
database = require('../../database.js'),
|
||
|
|
expect = require('expect.js'),
|
||
|
|
server = require('../../server.js'),
|
||
|
|
superagent = require('superagent');
|
||
|
|
|
||
|
|
exports = module.exports = {
|
||
|
|
setup,
|
||
|
|
cleanup,
|
||
|
|
|
||
|
|
owner: {
|
||
|
|
username: 'superadmin',
|
||
|
|
password: 'Foobar?1337',
|
||
|
|
email: 'silly@me.com',
|
||
|
|
token: null
|
||
|
|
},
|
||
|
|
|
||
|
|
serverUrl: `http://localhost:${constants.PORT}`
|
||
|
|
};
|
||
|
|
|
||
|
|
function setup(done) {
|
||
|
|
const owner = exports.owner, serverUrl = exports.serverUrl;
|
||
|
|
|
||
|
|
async.series([
|
||
|
|
server.start.bind(null),
|
||
|
|
database._clear.bind(null),
|
||
|
|
|
||
|
|
function createAdmin(callback) {
|
||
|
|
superagent.post(`${serverUrl}/api/v1/cloudron/activate`)
|
||
|
|
.query({ setupToken: 'somesetuptoken' })
|
||
|
|
.send({ username: owner.username, password: owner.password, email: owner.email })
|
||
|
|
.end(function (error, result) {
|
||
|
|
expect(result).to.be.ok();
|
||
|
|
expect(result.statusCode).to.eql(201);
|
||
|
|
|
||
|
|
// stash token for further use
|
||
|
|
owner.token = result.body.token;
|
||
|
|
|
||
|
|
callback();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
], done);
|
||
|
|
}
|
||
|
|
|
||
|
|
function cleanup(done) {
|
||
|
|
database._clear(function (error) {
|
||
|
|
expect(!error).to.be.ok();
|
||
|
|
|
||
|
|
server.stop(done);
|
||
|
|
});
|
||
|
|
}
|