mirror of
https://git.cloudron.io/cloudron/peertube-app.git
synced 2024-11-22 09:31:10 +00:00
266 lines
10 KiB
JavaScript
266 lines
10 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/* jslint node:true */
|
|
/* global it:false */
|
|
/* global xit:false */
|
|
/* global describe:false */
|
|
/* global before:false */
|
|
/* global after:false */
|
|
|
|
'use strict';
|
|
|
|
require('chromedriver');
|
|
|
|
var execSync = require('child_process').execSync,
|
|
expect = require('expect.js'),
|
|
path = require('path'),
|
|
util = require('util'),
|
|
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
|
{ Options } = require('selenium-webdriver/chrome');
|
|
|
|
if (!process.env.USERNAME || !process.env.PASSWORD || !process.env.EMAIL) {
|
|
console.log('USERNAME, EMAIL and PASSWORD env vars need to be set');
|
|
process.exit(1);
|
|
}
|
|
|
|
describe('Application life cycle test', function () {
|
|
this.timeout(0);
|
|
|
|
var LOCATION = 'test';
|
|
var TEST_TIMEOUT = parseInt(process.env.TEST_TIMEOUT, 10) || 30000;
|
|
|
|
var browser;
|
|
var app;
|
|
var username = process.env.USERNAME;
|
|
var password = process.env.PASSWORD;
|
|
var email = process.env.EMAIL;
|
|
|
|
before(function () {
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
|
|
});
|
|
|
|
after(function () {
|
|
browser.quit();
|
|
});
|
|
|
|
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 login(username, password, done) {
|
|
browser.get('https://' + app.fqdn + '/login').then(function () {
|
|
return browser.wait(until.elementLocated(By.id('username')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
return browser.findElement(By.id('username')).sendKeys(username);
|
|
}).then(function () {
|
|
return browser.findElement(By.id('password')).sendKeys(password);
|
|
}).then(function () {
|
|
return browser.findElement(By.xpath('//input[@value="Login"]')).click();
|
|
}).then(function () {
|
|
if (app.manifest.version === '2.4.0') {
|
|
return browser.wait(until.elementLocated(By.xpath('//a[contains(@href, "/my-library")]')), TEST_TIMEOUT);
|
|
} else {
|
|
return browser.wait(until.elementLocated(By.xpath('//div[contains(text(), "MY LIBRARY")]')), TEST_TIMEOUT);
|
|
}
|
|
}).then(function () {
|
|
done();
|
|
});
|
|
}
|
|
|
|
function closeAccountSetupDialog(done) {
|
|
browser.get('https://' + app.fqdn).then(function () {
|
|
return browser.wait(until.elementLocated(By.id('stopDisplayModal')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
return browser.findElement(By.xpath('//span[contains(text(), "show me this anymore")]')).click();
|
|
}).then(function () {
|
|
return browser.findElement(By.xpath('//a[contains(text(), "Set up")]')).click();
|
|
}).then(function () {
|
|
return browser.sleep(3000);
|
|
}).then(function () {
|
|
done();
|
|
});
|
|
}
|
|
|
|
function logout(done) {
|
|
browser.get('https://' + app.fqdn + '/my-account/videos').then(function () {
|
|
return browser.wait(until.elementLocated(By.xpath('//div[@class="logged-in-display-name"]')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
return browser.sleep(2000);
|
|
}).then(function () {
|
|
return browser.findElement(By.xpath('//div[@class="logged-in-display-name"]')).click();
|
|
}).then(function () {
|
|
return browser.sleep(2000);
|
|
}).then(function () {
|
|
return browser.findElement(By.xpath('//a[contains(text(), "Log out")]')).click();
|
|
}).then(function () {
|
|
return browser.sleep(2000);
|
|
}).then(function () {
|
|
done();
|
|
});
|
|
}
|
|
|
|
function completeSetup(done) {
|
|
var button;
|
|
|
|
browser.get('https://' + app.fqdn + '/admin/config/edit-custom').then(function () {
|
|
return browser.wait(until.elementLocated(By.xpath('//a[contains(text(), "Configure my instance")]')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
return browser.findElement(By.xpath('//a[contains(text(), "Configure my instance")]')).click(); // this opens a new window
|
|
}).then(function () {
|
|
return browser.get('https://' + app.fqdn + '/admin/config/edit-custom');
|
|
}).then(function () {
|
|
return browser.wait(until.elementLocated(By.xpath('//input[contains(@value, "Update configuration")]')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
button = browser.findElement(By.xpath('//input[contains(@value, "Update configuration")]'));
|
|
return browser.executeScript('arguments[0].scrollIntoView(true)', button);
|
|
}).then(function () {
|
|
return button.click();
|
|
}).then(function () {
|
|
return browser.wait(until.elementLocated(By.xpath('//h3[contains(text(), "Success")]')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
console.log('Close the newly opened tab. Will wait for 20 seconds');
|
|
return browser.sleep(20000);
|
|
}).then(function () {
|
|
done();
|
|
});
|
|
}
|
|
|
|
function uploadVideo(done) {
|
|
browser.get('https://' + app.fqdn + '/videos/upload').then(function () {
|
|
return browser.findElement(By.xpath('//input[@id="videofile" and @type="file"]')).sendKeys(path.resolve(__dirname, './Cloudron Test Video.mp4'));
|
|
}).then(function () {
|
|
return browser.sleep(20000); // wait for upload
|
|
}).then(function () {
|
|
return browser.findElement(By.xpath('//span[text()="Publish"]')).click();
|
|
}).then(function () {
|
|
return browser.sleep(2000);
|
|
}).then(function () {
|
|
done();
|
|
});
|
|
}
|
|
|
|
function videoExists(done) {
|
|
browser.get('https://' + app.fqdn + '/my-account/videos').then(function () {
|
|
return browser.wait(until.elementLocated(By.xpath('//a[contains(@title, "Cloudron Test Video")]')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
return done();
|
|
});
|
|
}
|
|
|
|
xit('build app', function () {
|
|
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
|
|
it('install app', function (done) {
|
|
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
setTimeout(done, 20000); // takes a bit to create root user in background
|
|
});
|
|
|
|
it('can get app information', getAppInfo);
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
|
it('can complete setup', completeSetup);
|
|
it('can upload video', uploadVideo);
|
|
it('video exists', videoExists);
|
|
it('logout', logout);
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
it('can close account setup dialog', closeAccountSetupDialog);
|
|
it('logout', logout);
|
|
|
|
it('backup app', function () {
|
|
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
|
|
it('restore app', function () {
|
|
const backups = JSON.parse(execSync('cloudron backup list --raw'));
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
getAppInfo();
|
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
|
it('video exists', videoExists);
|
|
it('logout', logout);
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
it('logout', logout);
|
|
|
|
it('can restart app', function () {
|
|
execSync('cloudron restart --app ' + app.id);
|
|
});
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
|
it('video exists', videoExists);
|
|
it('logout', logout);
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
it('logout', logout);
|
|
|
|
// this is not supported for federation
|
|
it('move to different location', function (done) {
|
|
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
done();
|
|
});
|
|
|
|
it('can get app information', getAppInfo);
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
|
it('video exists', videoExists);
|
|
it('logout', logout);
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
it('logout', logout);
|
|
|
|
it('uninstall app', function () {
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
|
|
// No SSO
|
|
it('install app (no sso)', function (done) {
|
|
execSync('cloudron install --no-sso --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
setTimeout(done, 20000); // takes a bit to create root user in background
|
|
});
|
|
|
|
it('can get app information', function () {
|
|
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 (no sso)', login.bind(null, 'root', 'changeme'));
|
|
it('can complete setup', completeSetup);
|
|
it('can logout', logout);
|
|
|
|
it('uninstall app (no sso)', function () {
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
|
|
// test update
|
|
it('can install app', function (done) {
|
|
execSync('cloudron install --appstore-id org.joinpeertube.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
setTimeout(done, 20000); // takes a bit to create root user in background
|
|
});
|
|
|
|
it('can get app information', getAppInfo);
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
|
it('can complete setup', completeSetup);
|
|
it('can upload video', uploadVideo);
|
|
it('video exists', videoExists);
|
|
|
|
it('can update', function () {
|
|
execSync('cloudron update --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
|
it('video exists', videoExists);
|
|
it('logout', logout);
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
it('logout', logout);
|
|
|
|
it('uninstall app', function () {
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
});
|