]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blobdiff - test/test.js
Add update tests
[perso/Immae/Projets/Nodejs/Surfer.git] / test / test.js
index 3610c05bf74e9aed4c6fd5d31367109d2e0a1aaf..8145f179486d7340821ec8ee1a60e9e9a9d4b9aa 100644 (file)
@@ -12,42 +12,39 @@ var execSync = require('child_process').execSync,
     path = require('path'),
     util = require('util'),
     superagent = require('superagent'),
-    webdriver = require('selenium-webdriver');
-
-var by = webdriver.By,
-    until = webdriver.until;
+    { Builder, By, until } = require('selenium-webdriver'),
+    { Options } = require('selenium-webdriver/chrome');
 
 if (!process.env.USERNAME || !process.env.PASSWORD) {
     console.log('USERNAME and PASSWORD env vars need to be set');
     process.exit(1);
 }
 
-const EXEC_OPTIONS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
-
 describe('Application life cycle test', function () {
     this.timeout(0);
 
-    var browser;
+    const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
+    const LOCATION = 'test';
+    const TEST_TIMEOUT = 10000;
+    const TEST_FILE_NAME_0 = 'index.html';
+    const TEST_FILE_NAME_1 = 'test.txt';
 
-    before(function (done) {
-        browser = new webdriver.Builder()
-          .forBrowser('chrome')
-        //   .setChromeOptions(new chrome.Options().addArguments(['no-sandbox', 'headless']))
-          .build();
+    var app;
+    var browser;
 
-        done();
+    before(function () {
+        browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
     });
 
-    after(function (done) {
+    after(function () {
         browser.quit();
-        done();
     });
 
-    var LOCATION = 'test';
-    var TEST_TIMEOUT = 10000;
-    var TEST_FILE_NAME_0 = 'index.html';
-    var TEST_FILE_NAME_1 = 'test.txt';
-    var app;
+    function getAppInfo() {
+        var inspect = JSON.parse(execSync('cloudron inspect'));
+        app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
+        expect(app).to.be.an('object');
+    }
 
     function waitForElement(elem) {
         return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
@@ -60,12 +57,12 @@ describe('Application life cycle test', function () {
         browser.manage().deleteAllCookies();
         browser.get('https://' + app.fqdn + '/_admin');
 
-        waitForElement(by.id('loginUsernameInput')).then(function () {
-            browser.findElement(by.id('loginUsernameInput')).sendKeys(process.env.USERNAME);
-            browser.findElement(by.id('loginPasswordInput')).sendKeys(process.env.PASSWORD);
-            browser.findElement(by.id('loginSubmitButton')).click();
+        waitForElement(By.id('loginUsernameInput')).then(function () {
+            browser.findElement(By.id('loginUsernameInput')).sendKeys(process.env.USERNAME);
+            browser.findElement(By.id('loginPasswordInput')).sendKeys(process.env.PASSWORD);
+            browser.findElement(By.id('loginSubmitButton')).click();
 
-            waitForElement(by.id('burgerMenuButton')).then(function () {
+            waitForElement(By.id('burgerMenuButton')).then(function () {
                 done();
             });
         });
@@ -74,16 +71,16 @@ describe('Application life cycle test', function () {
     function logout(done) {
         browser.get('https://' + app.fqdn + '/_admin');
 
-        waitForElement(by.id('burgerMenuButton')).then(function () {
-            browser.findElement(by.id('burgerMenuButton')).click();
+        waitForElement(By.id('burgerMenuButton')).then(function () {
+            browser.findElement(By.id('burgerMenuButton')).click();
 
             // wait for open animation
             browser.sleep(5000);
 
-            waitForElement(by.id('logoutButton')).then(function () {
-                browser.findElement(by.id('logoutButton')).click();
+            waitForElement(By.id('logoutButton')).then(function () {
+                browser.findElement(By.id('logoutButton')).click();
 
-                waitForElement(by.id('loginUsernameInput')).then(function () {
+                waitForElement(By.id('loginUsernameInput')).then(function () {
                     done();
                 });
             });
@@ -93,7 +90,7 @@ describe('Application life cycle test', function () {
     function checkFileIsListed(name, done) {
         browser.get('https://' + app.fqdn + '/_admin');
 
-        waitForElement(by.xpath('//*[text()="' + name + '"]')).then(function () {
+        waitForElement(By.xpath('//*[text()="' + name + '"]')).then(function () {
             done();
         });
     }
@@ -101,7 +98,7 @@ describe('Application life cycle test', function () {
     function checkFileIsPresent(done) {
         browser.get('https://' + app.fqdn + '/' + TEST_FILE_NAME_0);
 
-        waitForElement(by.xpath('//*[text()="test"]')).then(function () {
+        waitForElement(By.xpath('//*[text()="test"]')).then(function () {
             done();
         });
     }
@@ -109,7 +106,7 @@ describe('Application life cycle test', function () {
     function checkIndexFileIsServedUp(done) {
         browser.get('https://' + app.fqdn);
 
-        waitForElement(by.xpath('//*[text()="test"]')).then(function () {
+        waitForElement(By.xpath('//*[text()="test"]')).then(function () {
             done();
         });
     }
@@ -131,25 +128,15 @@ describe('Application life cycle test', function () {
     function uploadFile(name, done) {
         // File upload can't be tested with selenium, since the file input is not visible and thus can't be interacted with :-(
 
-        execSync(path.join(__dirname, '/../cli/surfer.js') + ' put ' + path.join(__dirname, name) + '/',  { stdio: 'inherit' } );
+        execSync(path.join(__dirname, '/../cli/surfer.js') + ' put ' + path.join(__dirname, name) + ' /',  { stdio: 'inherit' } );
         done();
     }
 
-    xit('build app', function () {
-        execSync('cloudron build', EXEC_OPTIONS);
-    });
-
-    it('install app', function () {
-        execSync('cloudron install --new --wait --location ' + LOCATION, EXEC_OPTIONS);
-    });
+    xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
 
-    it('can get app information', function () {
-        var inspect = JSON.parse(execSync('cloudron inspect'));
+    it('install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_ARGS); });
 
-        app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
-
-        expect(app).to.be.an('object');
-    });
+    it('can get app information', getAppInfo);
 
     it('can login', login);
     it('can cli login', cliLogin);
@@ -159,20 +146,14 @@ describe('Application life cycle test', function () {
     it('file is served up', checkIndexFileIsServedUp);
     it('can upload second file', uploadFile.bind(null, TEST_FILE_NAME_1));
     it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_1));
-    it('can delete second file with cli', function (done) {
+    it('can delete second file with cli', function () {
         execSync(path.join(__dirname, '/../cli/surfer.js') + ' del ' + TEST_FILE_NAME_1,  { stdio: 'inherit' } );
-        done();
     });
     it('second file is gone', checkFileIsGone.bind(null, TEST_FILE_NAME_1));
     it('can logout', logout);
 
-    it('backup app', function () {
-        execSync('cloudron backup create --app ' + app.id, EXEC_OPTIONS);
-    });
-
-    it('restore app', function () {
-        execSync('cloudron restore --app ' + app.id, EXEC_OPTIONS);
-    });
+    it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS); });
+    it('restore app', function () { execSync(`cloudron restore --app ${app.id}`, EXEC_ARGS); });
 
     it('can login', login);
     it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_0));
@@ -186,10 +167,10 @@ describe('Application life cycle test', function () {
 
         // ensure we don't hit NXDOMAIN in the mean time
         browser.get('about:blank').then(function () {
-            execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_OPTIONS);
-            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');
+            execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS);
+
+            getAppInfo();
+
             done();
         });
     });
@@ -203,7 +184,39 @@ describe('Application life cycle test', function () {
     it('uninstall app', function (done) {
         // ensure we don't hit NXDOMAIN in the mean time
         browser.get('about:blank').then(function () {
-            execSync('cloudron uninstall --app ' + app.id, EXEC_OPTIONS);
+            execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS);
+            done();
+        });
+    });
+
+    // test update
+    it('can install app', function () {
+        execSync(`cloudron install --appstore-id io.cloudron.surfer --location ${LOCATION}`, EXEC_ARGS);
+    });
+
+    it('can get app information', getAppInfo);
+    it('can login', login);
+    it('can cli login', cliLogin);
+    it('can upload file', uploadFile.bind(null, TEST_FILE_NAME_0));
+    it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_0));
+    it('file is served up', checkFileIsPresent);
+    it('file is served up', checkIndexFileIsServedUp);
+    it('can logout', logout);
+
+    it('can update', function () {
+        execSync(`cloudron update --app ${LOCATION}`, EXEC_ARGS);
+    });
+
+    it('can login', login);
+    it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_0));
+    it('file is served up', checkFileIsPresent);
+    it('file is served up', checkIndexFileIsServedUp);
+    it('can logout', logout);
+
+    it('uninstall app', function (done) {
+        // ensure we don't hit NXDOMAIN in the mean time
+        browser.get('about:blank').then(function () {
+            execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS);
             done();
         });
     });