From 2ee1d46abc2ac1054a085ef1f2284d481fdceb97 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Thu, 9 Apr 2020 18:28:07 -0700 Subject: [PATCH] Finish tests --- tests/test.js | 92 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 14 deletions(-) diff --git a/tests/test.js b/tests/test.js index 5e3e283..52e1b72 100644 --- a/tests/test.js +++ b/tests/test.js @@ -13,7 +13,6 @@ require('chromedriver'); var execSync = require('child_process').execSync, expect = require('expect.js'), - fs = require('fs'), path = require('path'), superagent = require('superagent'), webdriver = require('selenium-webdriver'); @@ -22,8 +21,6 @@ var by = require('selenium-webdriver').By, until = require('selenium-webdriver').until, Key = require('selenium-webdriver').Key; -process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; - describe('Application life cycle test', function () { this.timeout(0); var server, browser = new webdriver.Builder().forBrowser('chrome').build(); @@ -32,8 +29,8 @@ describe('Application life cycle test', function () { var app; var username = process.env.USERNAME; var password = process.env.PASSWORD; - var email = process.env.EMAIL; - var token; + var TIMEOUT = process.env.TIMEOUT | 30000; + var token, roomId; before(function (done) { if (!process.env.USERNAME) return done(new Error('USERNAME env var not set')); @@ -53,6 +50,56 @@ describe('Application life cycle test', function () { 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 () { 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'); }); - it('can get the main page', function (done) { - superagent.get('https://' + app.fqdn).end(function (error, result) { - expect(error).to.be(null); - expect(result.status).to.eql(200); - - done(); - }); - }); + it('check landing page', checkLandingPage); + it('can login', checkLogin); + it('create room', createRoom); + it('check room', checkRoom); it('can restart app', function (done) { execSync('cloudron restart'); done(); }); + it('check landing page', checkLandingPage); + it('check room', checkRoom); + it('backup app', function () { 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 () { 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 () { browser.manage().deleteAllCookies(); 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'); }); + it('check landing page', checkLandingPage); + it('check room', checkRoom); + it('uninstall app', function () { 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]; 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 () { - 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 () { execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); });