peertube-app/test/test.js

224 lines
8.4 KiB
JavaScript
Raw Normal View History

2020-07-21 20:46:54 +00:00
#!/usr/bin/env node
2021-10-11 10:07:47 +00:00
/* jshint esversion: 8 */
/* global describe */
/* global before */
/* global after */
/* global it */
2020-07-21 20:46:54 +00:00
'use strict';
require('chromedriver');
2022-04-29 22:16:11 +00:00
const execSync = require('child_process').execSync,
2020-07-21 20:46:54 +00:00
expect = require('expect.js'),
2023-06-22 19:09:28 +00:00
readlinePromises = require('readline/promises'),
2020-07-21 20:46:54 +00:00
path = require('path'),
2021-01-07 16:21:38 +00:00
util = require('util'),
{ Builder, By, Key, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
2020-07-21 20:46:54 +00:00
2023-06-22 19:09:28 +00:00
const rl = readlinePromises.createInterface({ input: process.stdin, output: process.stdout });
2020-07-21 20:46:54 +00:00
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);
2021-10-11 10:07:47 +00:00
const LOCATION = 'test';
const TEST_TIMEOUT = parseInt(process.env.TEST_TIMEOUT, 10) || 30000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
2021-01-07 16:21:38 +00:00
var browser;
var app;
2020-10-15 04:45:44 +00:00
var username = process.env.USERNAME;
var password = process.env.PASSWORD;
2020-07-21 20:46:54 +00:00
var email = process.env.EMAIL;
2021-01-07 16:21:38 +00:00
before(function () {
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
2020-07-21 20:46:54 +00:00
});
2021-01-07 16:21:38 +00:00
after(function () {
2020-07-21 20:46:54 +00:00
browser.quit();
});
function getAppInfo() {
var inspect = JSON.parse(execSync('cloudron inspect'));
2021-10-11 10:07:47 +00:00
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
2020-07-21 20:46:54 +00:00
expect(app).to.be.an('object');
}
2021-12-16 15:56:07 +00:00
async function waitForElement(elem) {
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
2020-07-21 20:46:54 +00:00
}
2021-12-16 15:56:07 +00:00
function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
2021-09-13 20:27:30 +00:00
}
2021-12-16 15:56:07 +00:00
async function login(username, password) {
await browser.get('https://' + app.fqdn + '/login');
await waitForElement(By.id('username'));
await browser.findElement(By.id('username')).sendKeys(username);
await browser.findElement(By.id('password')).sendKeys(password);
await browser.findElement(By.xpath('//input[@value="Login"]')).click();
await waitForElement(By.xpath('//a[contains(@href, "/my-library")]'));
2020-10-15 04:45:44 +00:00
}
2021-12-16 15:56:07 +00:00
async function closeAccountSetupDialog() {
await browser.get('https://' + app.fqdn);
await browser.findElement(By.xpath('//span[contains(text(), "show me this anymore")]')).click();
await browser.findElement(By.xpath('//a[contains(text(), "Set up")]')).click();
await browser.sleep(3000);
}
async function logout() {
await browser.get('https://' + app.fqdn + '/my-account/videos');
await waitForElement(By.xpath('//div[@class="logged-in-display-name"]'));
await browser.sleep(2000);
await browser.findElement(By.xpath('//div[@class="logged-in-display-name"]')).click();
await browser.sleep(2000);
2023-06-21 16:03:32 +00:00
await browser.findElement(By.xpath('//button[contains(text(), "Log out")]')).click();
2021-12-16 15:56:07 +00:00
await browser.sleep(2000);
}
async function completeSetup() {
2020-07-21 22:30:01 +00:00
var button;
2022-09-21 14:55:48 +00:00
await browser.get(`https://${app.fqdn}`);
2021-12-16 15:56:07 +00:00
await waitForElement(By.xpath('//a[contains(text(), "Configure my instance")]'));
await browser.findElement(By.xpath('//a[contains(text(), "Configure my instance")]')).click(); // this opens a new window
2023-06-22 19:09:28 +00:00
execSync('spd-say "Close the newly opened configuration tab."');
await rl.question('Is tab closed? ');
2020-07-21 22:30:01 +00:00
}
2021-12-16 15:56:07 +00:00
async function uploadVideo() {
browser.get('https://' + app.fqdn + '/videos/upload');
2021-12-16 16:33:47 +00:00
await browser.sleep(2000);
2021-12-16 15:56:07 +00:00
await browser.findElement(By.xpath('//input[@id="videofile" and @type="file"]')).sendKeys(path.resolve(__dirname, './Cloudron Test Video.mp4'));
2021-12-16 16:33:47 +00:00
await browser.sleep(10000); // wait for upload
2022-11-17 12:38:43 +00:00
2021-12-16 16:33:47 +00:00
await waitForElement(By.xpath('//div[@class="submit-container"]//span[text()="Publish"]'));
2022-11-17 12:38:43 +00:00
let button = browser.findElement(By.xpath('//div[@class="submit-container"]//span[text()="Publish"]'));
await browser.executeScript('arguments[0].scrollIntoView(false)', button);
await browser.sleep(2000);
await button.click();
2021-12-16 15:56:07 +00:00
await browser.sleep(2000);
2020-07-21 22:30:01 +00:00
}
2021-12-16 15:56:07 +00:00
async function videoExists() {
await browser.get('https://' + app.fqdn + '/my-account/videos');
await waitForElement(By.xpath('//a[contains(@title, "Cloudron Test Video")]'));
2020-07-21 22:30:01 +00:00
}
2021-10-11 10:07:47 +00:00
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
2021-12-16 15:56:07 +00:00
it('install app', async function () {
2021-10-11 10:07:47 +00:00
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
2023-01-05 11:14:37 +00:00
await sleep(40000); // takes a bit to create root user in background
2020-07-21 20:46:54 +00:00
});
it('can get app information', getAppInfo);
2021-10-11 10:07:47 +00:00
it('can root login', login.bind(null, 'root', 'changeme'));
2021-01-07 19:50:44 +00:00
it('can complete setup', completeSetup);
2020-07-21 22:30:01 +00:00
it('can upload video', uploadVideo);
it('video exists', videoExists);
2020-10-15 04:45:44 +00:00
it('logout', logout);
it('can login', login.bind(null, username, password));
2021-09-13 20:27:30 +00:00
it('can close account setup dialog', closeAccountSetupDialog);
2020-10-15 04:45:44 +00:00
it('logout', logout);
2020-07-21 20:46:54 +00:00
2021-10-11 10:07:47 +00:00
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
2020-07-21 20:46:54 +00:00
it('restore app', function () {
const backups = JSON.parse(execSync('cloudron backup list --raw'));
2021-10-11 10:07:47 +00:00
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
2020-07-21 20:46:54 +00:00
getAppInfo();
2021-10-11 10:07:47 +00:00
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
2020-07-21 20:46:54 +00:00
});
2021-10-11 10:07:47 +00:00
it('can root login', login.bind(null, 'root', 'changeme'));
2020-07-21 22:30:01 +00:00
it('video exists', videoExists);
2020-10-15 04:45:44 +00:00
it('logout', logout);
it('can login', login.bind(null, username, password));
it('logout', logout);
2020-07-21 20:46:54 +00:00
it('can restart app', function () {
execSync('cloudron restart --app ' + app.id);
});
2021-10-11 10:07:47 +00:00
it('can root login', login.bind(null, 'root', 'changeme'));
2020-07-21 22:30:01 +00:00
it('video exists', videoExists);
2020-10-15 04:45:44 +00:00
it('logout', logout);
it('can login', login.bind(null, username, password));
it('logout', logout);
2020-07-21 20:46:54 +00:00
2020-07-21 22:30:01 +00:00
// this is not supported for federation
2021-10-11 10:07:47 +00:00
it('move to different location', function () { execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS); });
2020-07-21 20:46:54 +00:00
it('can get app information', getAppInfo);
2021-10-11 10:07:47 +00:00
it('can root login', login.bind(null, 'root', 'changeme'));
2020-07-21 22:30:01 +00:00
it('video exists', videoExists);
2020-10-15 04:45:44 +00:00
it('logout', logout);
it('can login', login.bind(null, username, password));
it('logout', logout);
2020-07-21 20:46:54 +00:00
2022-09-21 14:55:48 +00:00
it('uninstall app', async function () {
await browser.executeScript('localStorage.clear();');
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
});
2020-07-21 20:46:54 +00:00
2020-10-15 04:45:44 +00:00
// No SSO
2021-12-16 15:56:07 +00:00
it('install app (no sso)', async function () {
2021-10-11 10:07:47 +00:00
execSync('cloudron install --no-sso --location ' + LOCATION, EXEC_ARGS);
2021-12-16 15:56:07 +00:00
await sleep(10000); // takes a bit to create root user in background
2020-10-15 04:45:44 +00:00
});
2021-10-11 10:07:47 +00:00
it('can get app information', getAppInfo);
2020-10-15 04:45:44 +00:00
it('can login (no sso)', login.bind(null, 'root', 'changeme'));
it('can complete setup', completeSetup);
it('can logout', logout);
2022-09-21 14:55:48 +00:00
it('uninstall app (no sso)', async function () {
await browser.executeScript('localStorage.clear();');
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
});
2020-10-15 04:45:44 +00:00
2020-07-21 20:46:54 +00:00
// test update
2021-12-16 15:56:07 +00:00
it('can install app', async function () {
2021-10-11 10:07:47 +00:00
execSync('cloudron install --appstore-id org.joinpeertube.cloudronapp --location ' + LOCATION, EXEC_ARGS);
2021-12-16 15:56:07 +00:00
await sleep(10000); // takes a bit to create root user in background
2020-07-21 20:46:54 +00:00
});
it('can get app information', getAppInfo);
2021-01-07 16:21:38 +00:00
it('can root login', login.bind(null, 'root', 'changeme'));
2020-07-21 22:30:01 +00:00
it('can complete setup', completeSetup);
it('can upload video', uploadVideo);
it('video exists', videoExists);
2020-07-21 20:46:54 +00:00
2021-10-11 10:07:47 +00:00
it('can update', function () { execSync('cloudron update --app ' + app.id, EXEC_ARGS); });
2021-01-07 16:21:38 +00:00
it('can root login', login.bind(null, 'root', 'changeme'));
2020-07-21 22:30:01 +00:00
it('video exists', videoExists);
2020-10-15 04:45:44 +00:00
it('logout', logout);
it('can login', login.bind(null, username, password));
it('logout', logout);
2020-07-21 20:46:54 +00:00
2022-09-21 14:55:48 +00:00
it('uninstall app', async function () {
await browser.executeScript('localStorage.clear();');
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
});
2020-07-21 20:46:54 +00:00
});