]>
git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blob - test/test.js
10 var execSync
= require('child_process').execSync
,
11 expect
= require('expect.js'),
12 path
= require('path'),
13 util
= require('util'),
14 superagent
= require('superagent'),
15 webdriver
= require('selenium-webdriver');
17 var by
= webdriver
.By
,
18 until
= webdriver
.until
;
20 if (!process
.env
.USERNAME
|| !process
.env
.PASSWORD
) {
21 console
.log('USERNAME and PASSWORD env vars need to be set');
25 const EXEC_OPTIONS
= { cwd: path
.resolve(__dirname
, '..'), stdio: 'inherit' };
27 describe('Application life cycle test', function () {
32 before(function (done
) {
33 browser
= new webdriver
.Builder()
35 // .setChromeOptions(new chrome.Options().addArguments(['no-sandbox', 'headless']))
41 after(function (done
) {
46 var LOCATION
= 'test';
47 var TEST_TIMEOUT
= 10000;
48 var TEST_FILE_NAME_0
= 'index.html';
49 var TEST_FILE_NAME_1
= 'test.txt';
52 function waitForElement(elem
) {
53 return browser
.wait(until
.elementLocated(elem
), TEST_TIMEOUT
).then(function () {
54 return browser
.wait(until
.elementIsVisible(browser
.findElement(elem
)), TEST_TIMEOUT
);
58 // tests which are used more than once
59 function login(done
) {
60 browser
.manage().deleteAllCookies();
61 browser
.get('https://' + app
.fqdn
+ '/_admin');
63 waitForElement(by
.id('loginUsernameInput')).then(function () {
64 browser
.findElement(by
.id('loginUsernameInput')).sendKeys(process
.env
.USERNAME
);
65 browser
.findElement(by
.id('loginPasswordInput')).sendKeys(process
.env
.PASSWORD
);
66 browser
.findElement(by
.id('loginSubmitButton')).click();
68 waitForElement(by
.id('burgerMenuButton')).then(function () {
74 function logout(done
) {
75 browser
.get('https://' + app
.fqdn
+ '/_admin');
77 waitForElement(by
.id('burgerMenuButton')).then(function () {
78 browser
.findElement(by
.id('burgerMenuButton')).click();
80 // wait for open animation
83 waitForElement(by
.id('logoutButton')).then(function () {
84 browser
.findElement(by
.id('logoutButton')).click();
86 waitForElement(by
.id('loginUsernameInput')).then(function () {
93 function checkFileIsListed(name
, done
) {
94 browser
.get('https://' + app
.fqdn
+ '/_admin');
96 waitForElement(by
.xpath('//*[text()="' + name
+ '"]')).then(function () {
101 function checkFileIsPresent(done
) {
102 browser
.get('https://' + app
.fqdn
+ '/' + TEST_FILE_NAME_0
);
104 waitForElement(by
.xpath('//*[text()="test"]')).then(function () {
109 function checkIndexFileIsServedUp(done
) {
110 browser
.get('https://' + app
.fqdn
);
112 waitForElement(by
.xpath('//*[text()="test"]')).then(function () {
117 function checkFileIsGone(name
, done
) {
118 superagent
.get('https://' + app
.fqdn
+ '/' + name
).end(function (error
, result
) {
119 expect(error
).to
.be
.an('object');
120 expect(error
.response
.status
).to
.equal(404);
121 expect(result
).to
.be
.an('object');
126 function cliLogin(done
) {
127 execSync(util
.format('%s login %s --username %s --password %s', path
.join(__dirname
, '/../cli/surfer.js'), app
.fqdn
, process
.env
.USERNAME
, process
.env
.PASSWORD
), { stdio: 'inherit' } );
131 function uploadFile(name
, done
) {
132 // File upload can't be tested with selenium, since the file input is not visible and thus can't be interacted with :-(
134 execSync(path
.join(__dirname
, '/../cli/surfer.js') + ' put ' + path
.join(__dirname
, name
) + ' /', { stdio: 'inherit' } );
138 xit('build app', function () {
139 execSync('cloudron build', EXEC_OPTIONS
);
142 it('install app', function () {
143 execSync('cloudron install --new --wait --location ' + LOCATION
, EXEC_OPTIONS
);
146 it('can get app information', function () {
147 var inspect
= JSON
.parse(execSync('cloudron inspect'));
149 app
= inspect
.apps
.filter(function (a
) { return a
.location
=== LOCATION
; })[0];
151 expect(app
).to
.be
.an('object');
154 it('can login', login
);
155 it('can cli login', cliLogin
);
156 it('can upload file', uploadFile
.bind(null, TEST_FILE_NAME_0
));
157 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_0
));
158 it('file is served up', checkFileIsPresent
);
159 it('file is served up', checkIndexFileIsServedUp
);
160 it('can upload second file', uploadFile
.bind(null, TEST_FILE_NAME_1
));
161 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_1
));
162 it('can delete second file with cli', function (done
) {
163 execSync(path
.join(__dirname
, '/../cli/surfer.js') + ' del ' + TEST_FILE_NAME_1
, { stdio: 'inherit' } );
166 it('second file is gone', checkFileIsGone
.bind(null, TEST_FILE_NAME_1
));
167 it('can logout', logout
);
169 it('backup app', function () {
170 execSync('cloudron backup create --app ' + app
.id
, EXEC_OPTIONS
);
173 it('restore app', function () {
174 execSync('cloudron restore --app ' + app
.id
, EXEC_OPTIONS
);
177 it('can login', login
);
178 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_0
));
179 it('file is served up', checkFileIsPresent
);
180 it('file is served up', checkIndexFileIsServedUp
);
181 it('second file is still gone', checkFileIsGone
.bind(null, TEST_FILE_NAME_1
));
182 it('can logout', logout
);
184 it('move to different location', function (done
) {
185 browser
.manage().deleteAllCookies();
187 // ensure we don't hit NXDOMAIN in the mean time
188 browser
.get('about:blank').then(function () {
189 execSync('cloudron configure --location ' + LOCATION
+ '2 --app ' + app
.id
, EXEC_OPTIONS
);
190 var inspect
= JSON
.parse(execSync('cloudron inspect'));
191 app
= inspect
.apps
.filter(function (a
) { return a
.location
=== LOCATION
+ '2'; })[0];
192 expect(app
).to
.be
.an('object');
197 it('can login', login
);
198 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_0
));
199 it('file is served up', checkFileIsPresent
);
200 it('file is served up', checkIndexFileIsServedUp
);
201 it('can logout', logout
);
203 it('uninstall app', function (done
) {
204 // ensure we don't hit NXDOMAIN in the mean time
205 browser
.get('about:blank').then(function () {
206 execSync('cloudron uninstall --app ' + app
.id
, EXEC_OPTIONS
);