2017-02-17 10:28:42 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2018-05-21 19:36:04 +00:00
|
|
|
require('chromedriver');
|
|
|
|
|
2017-02-17 10:28:42 +00:00
|
|
|
var execSync = require('child_process').execSync,
|
|
|
|
expect = require('expect.js'),
|
|
|
|
path = require('path'),
|
|
|
|
webdriver = require('selenium-webdriver');
|
|
|
|
|
|
|
|
var by = webdriver.By,
|
|
|
|
until = webdriver.until;
|
|
|
|
|
|
|
|
var username = 'admin',
|
|
|
|
password = 'password';
|
|
|
|
|
|
|
|
|
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
|
|
|
|
|
|
|
|
|
|
describe('Application life cycle test', function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
var chrome = require('selenium-webdriver/chrome');
|
|
|
|
var server, browser = new chrome.Driver();
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
var seleniumJar= require('selenium-server-standalone-jar');
|
|
|
|
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
|
|
|
|
server = new SeleniumServer(seleniumJar.path, { port: 4444 });
|
|
|
|
server.start();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
browser.quit();
|
|
|
|
server.stop();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2017-06-01 08:43:14 +00:00
|
|
|
var LOCATION = 'test';
|
2017-02-17 10:28:42 +00:00
|
|
|
var TEST_TIMEOUT = 10000;
|
|
|
|
var app;
|
|
|
|
|
|
|
|
function exists(selector, callback) {
|
|
|
|
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT).then(function () {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function visible(selector, callback) {
|
|
|
|
exists(selector, function () {
|
|
|
|
browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT).then(function () {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function login(callback) {
|
|
|
|
browser.manage().deleteAllCookies();
|
|
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
|
|
|
|
visible(by.id('loginButton'), function () {
|
|
|
|
browser.findElement(by.id('username')).sendKeys(username);
|
|
|
|
browser.findElement(by.id('passwordPlain')).sendKeys(password);
|
|
|
|
browser.findElement(by.id('loginButton')).click();
|
|
|
|
browser.wait(until.elementLocated(by.id('dropdown-configure')), TEST_TIMEOUT).then(function () { callback(); });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout(callback) {
|
|
|
|
var logout_btn = by.xpath('//ul[@class="dropdown-menu"]/li/a[@class="signout"]');
|
|
|
|
|
|
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
|
|
|
|
visible(by.id('stream'), function () {
|
|
|
|
browser.findElement(by.className('dropdown-toggle')).click();
|
|
|
|
visible(logout_btn, function () {
|
|
|
|
browser.findElement(logout_btn).click();
|
|
|
|
|
|
|
|
browser.wait(until.elementLocated(by.id('loginButton')), TEST_TIMEOUT).then(function () { callback(); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSubscription(callback) {
|
|
|
|
var url = "https://cloudron.io/blog/rss.xml";
|
|
|
|
|
|
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
|
|
|
|
visible(by.id('stream'), function () {
|
|
|
|
browser.findElement(by.xpath('//a[@href=".?c=subscription"]')).click();
|
|
|
|
visible(by.id('add_rss'), function () {
|
|
|
|
browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url);
|
|
|
|
browser.findElement(by.xpath('//form[@id="add_rss"]/div/button[@type="submit"]')).click();
|
|
|
|
visible(by.xpath('//div[@id="notification" and @class="notification good"]'), function() { callback(); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addUser(callback) {
|
|
|
|
var test_username = 'test';
|
|
|
|
var manage_users_btn = by.xpath('//a[@href=".?c=user&a=manage"]');
|
|
|
|
|
|
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
|
|
|
|
visible(by.id('stream'), function () {
|
|
|
|
browser.findElement(by.className('dropdown-toggle')).click();
|
|
|
|
visible(manage_users_btn, function () {
|
|
|
|
browser.findElement(manage_users_btn).click();
|
|
|
|
visible(by.id('new_user_name'), function () {
|
|
|
|
browser.findElement(by.id('new_user_name')).sendKeys(test_username);
|
|
|
|
browser.findElement(by.id('new_user_passwordPlain')).sendKeys(password);
|
|
|
|
browser.findElement(by.xpath('//form[@action=".?c=user&a=create"]/div/div/button[@type="submit"]')).click();
|
|
|
|
visible(by.xpath('//div[@id="notification" and @class="notification good"]'), function() { callback(); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-24 18:19:26 +00:00
|
|
|
function enableApi(callback) {
|
|
|
|
browser.get('https://' + app.fqdn + '/p/i/?c=auth').then(function () {
|
|
|
|
return browser.findElement(by.id('api_enabled')).click();
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.xpath('//form[@action=".?c=auth"]')).submit();
|
|
|
|
}).then(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkApiConfiguration(callback) {
|
|
|
|
browser.get('https://' + app.fqdn + '/p/api/greader.php/check%2Fcompatibility').then(function () {
|
|
|
|
exists(by.xpath('//pre[text()="PASS"]'), callback);
|
|
|
|
});
|
|
|
|
}
|
2017-02-17 10:28:42 +00:00
|
|
|
|
2018-03-19 11:01:48 +00:00
|
|
|
function getAppInfo() {
|
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
}
|
|
|
|
|
|
|
|
function subscriptionExists(callback) {
|
|
|
|
browser.get('https://' + app.fqdn + '/p/i/?get=c_1');
|
|
|
|
|
|
|
|
visible(by.xpath('//a[text()="Cloudron.io"]'), callback);
|
|
|
|
}
|
|
|
|
|
2017-02-17 10:28:42 +00:00
|
|
|
xit('build app', function () {
|
|
|
|
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('install app', function () {
|
|
|
|
execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
2018-03-19 11:01:48 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2017-02-17 10:28:42 +00:00
|
|
|
|
|
|
|
it('can login', login);
|
|
|
|
it('can subscribe', addSubscription);
|
|
|
|
it('can add users', addUser);
|
2017-05-24 18:19:26 +00:00
|
|
|
it('can enable API', enableApi);
|
|
|
|
it('can check configuration', checkApiConfiguration);
|
2018-03-19 11:01:48 +00:00
|
|
|
it('subscription exists', subscriptionExists);
|
2017-02-17 10:28:42 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('backup app', function () {
|
|
|
|
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('restore app', function () {
|
|
|
|
execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can login', login);
|
2017-05-24 18:19:26 +00:00
|
|
|
it('can check configuration', checkApiConfiguration);
|
2018-03-19 11:01:48 +00:00
|
|
|
it('subscription exists', subscriptionExists);
|
2017-02-17 10:28:42 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('move to different location', function () {
|
|
|
|
browser.manage().deleteAllCookies();
|
2018-03-19 11:01:48 +00:00
|
|
|
execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
2017-02-17 10:28:42 +00:00
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can login', login);
|
2017-05-24 18:19:26 +00:00
|
|
|
it('can check configuration', checkApiConfiguration);
|
2018-03-19 11:01:48 +00:00
|
|
|
it('subscription exists', subscriptionExists);
|
2017-02-17 10:28:42 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('uninstall app', function () {
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
2018-03-19 11:01:48 +00:00
|
|
|
// test update
|
|
|
|
it('can install app', function () {
|
|
|
|
execSync('cloudron install --new --wait --appstore-id org.freshrss.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can get app information', getAppInfo);
|
|
|
|
it('can login', login);
|
|
|
|
it('can subscribe', addSubscription);
|
|
|
|
it('can add users', addUser);
|
|
|
|
|
|
|
|
it('can update', function () {
|
|
|
|
execSync('cloudron install --wait --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can login', login);
|
|
|
|
it('subscription exists', subscriptionExists);
|
|
|
|
|
|
|
|
it('uninstall app', function () {
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
2017-02-17 10:28:42 +00:00
|
|
|
});
|