Finish tests
This commit is contained in:
@@ -13,7 +13,6 @@ require('chromedriver');
|
|||||||
|
|
||||||
var execSync = require('child_process').execSync,
|
var execSync = require('child_process').execSync,
|
||||||
expect = require('expect.js'),
|
expect = require('expect.js'),
|
||||||
fs = require('fs'),
|
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
superagent = require('superagent'),
|
superagent = require('superagent'),
|
||||||
webdriver = require('selenium-webdriver');
|
webdriver = require('selenium-webdriver');
|
||||||
@@ -22,8 +21,6 @@ var by = require('selenium-webdriver').By,
|
|||||||
until = require('selenium-webdriver').until,
|
until = require('selenium-webdriver').until,
|
||||||
Key = require('selenium-webdriver').Key;
|
Key = require('selenium-webdriver').Key;
|
||||||
|
|
||||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
||||||
|
|
||||||
describe('Application life cycle test', function () {
|
describe('Application life cycle test', function () {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
var server, browser = new webdriver.Builder().forBrowser('chrome').build();
|
var server, browser = new webdriver.Builder().forBrowser('chrome').build();
|
||||||
@@ -32,8 +29,8 @@ describe('Application life cycle test', function () {
|
|||||||
var app;
|
var app;
|
||||||
var username = process.env.USERNAME;
|
var username = process.env.USERNAME;
|
||||||
var password = process.env.PASSWORD;
|
var password = process.env.PASSWORD;
|
||||||
var email = process.env.EMAIL;
|
var TIMEOUT = process.env.TIMEOUT | 30000;
|
||||||
var token;
|
var token, roomId;
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
|
if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
|
||||||
@@ -53,6 +50,56 @@ describe('Application life cycle test', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function checkLandingPage(done) {
|
||||||
|
browser.get('https://' + app.fqdn).then(function () {
|
||||||
|
return browser.wait(until.elementLocated(by.xpath('//h1[contains(text(),"Synapse is running")]')), TIMEOUT);
|
||||||
|
}).then(function () {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://matrix.org/docs/spec/client_server/latest
|
||||||
|
function checkLogin(done) {
|
||||||
|
superagent.post('https://' + app.fqdn + '/_matrix/client/r0/login').send({
|
||||||
|
type: 'm.login.password',
|
||||||
|
user: username,
|
||||||
|
password: password
|
||||||
|
}).end(function (error, result) {
|
||||||
|
if (error) return done(error);
|
||||||
|
if (result.statusCode !== 200) return done(new Error('Login failed with status ' + result.statusCode));
|
||||||
|
|
||||||
|
token = result.body.access_token;
|
||||||
|
if (!token) return done(new Error('No token'));
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createRoom(done) {
|
||||||
|
superagent.post('https://' + app.fqdn + '/_matrix/client/r0/createRoom?access_token=' + token).send({
|
||||||
|
room_alias_name: 'discuss'
|
||||||
|
}).end(function (error, result) {
|
||||||
|
if (error) return done(error);
|
||||||
|
if (result.statusCode !== 200) return done(new Error('Room creation failed with status ' + result.statusCode));
|
||||||
|
|
||||||
|
roomId = result.body.room_id;
|
||||||
|
if (!roomId) return done(new Error('No room id'));
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkRoom(done) {
|
||||||
|
superagent.get('https://' + app.fqdn + '/_matrix/client/r0/joined_rooms?access_token=' + token).end(function (error, result) {
|
||||||
|
if (error) return done(error);
|
||||||
|
if (result.statusCode !== 200) return done(new Error('Room listing failed with status ' + result.statusCode));
|
||||||
|
|
||||||
|
if (!result.body.joined_rooms.includes(roomId)) return done(new Error('No room in list: ' + JSON.stringify(result.body)));
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
xit('build app', function () {
|
xit('build app', function () {
|
||||||
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
||||||
});
|
});
|
||||||
@@ -69,28 +116,33 @@ describe('Application life cycle test', function () {
|
|||||||
expect(app).to.be.an('object');
|
expect(app).to.be.an('object');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can get the main page', function (done) {
|
it('check landing page', checkLandingPage);
|
||||||
superagent.get('https://' + app.fqdn).end(function (error, result) {
|
it('can login', checkLogin);
|
||||||
expect(error).to.be(null);
|
it('create room', createRoom);
|
||||||
expect(result.status).to.eql(200);
|
it('check room', checkRoom);
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can restart app', function (done) {
|
it('can restart app', function (done) {
|
||||||
execSync('cloudron restart');
|
execSync('cloudron restart');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('check landing page', checkLandingPage);
|
||||||
|
it('check room', checkRoom);
|
||||||
|
|
||||||
it('backup app', function () {
|
it('backup app', function () {
|
||||||
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('check landing page', checkLandingPage);
|
||||||
|
it('check room', checkRoom);
|
||||||
|
|
||||||
it('restore app', function () {
|
it('restore app', function () {
|
||||||
execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('check landing page', checkLandingPage);
|
||||||
|
it('check room', checkRoom);
|
||||||
|
|
||||||
it('move to different location', function () {
|
it('move to different location', function () {
|
||||||
browser.manage().deleteAllCookies();
|
browser.manage().deleteAllCookies();
|
||||||
execSync('cloudron configure --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron configure --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
||||||
@@ -99,6 +151,9 @@ describe('Application life cycle test', function () {
|
|||||||
expect(app).to.be.an('object');
|
expect(app).to.be.an('object');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('check landing page', checkLandingPage);
|
||||||
|
it('check room', checkRoom);
|
||||||
|
|
||||||
it('uninstall app', function () {
|
it('uninstall app', function () {
|
||||||
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
||||||
});
|
});
|
||||||
@@ -110,9 +165,18 @@ describe('Application life cycle test', function () {
|
|||||||
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
||||||
expect(app).to.be.an('object');
|
expect(app).to.be.an('object');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('check landing page', checkLandingPage);
|
||||||
|
it('can login', checkLogin);
|
||||||
|
it('create room', createRoom);
|
||||||
|
it('check room', checkRoom);
|
||||||
|
|
||||||
it('can update', function () {
|
it('can update', function () {
|
||||||
execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron update --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('check landing page', checkLandingPage);
|
||||||
|
it('check room', checkRoom);
|
||||||
it('uninstall app', function () {
|
it('uninstall app', function () {
|
||||||
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user