]>
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 { Builder
, By
, until
} = require('selenium-webdriver'),
16 { Options
} = require('selenium-webdriver/chrome');
18 if (!process
.env
.USERNAME
|| !process
.env
.PASSWORD
) {
19 console
.log('USERNAME and PASSWORD env vars need to be set');
23 describe('Application life cycle test', function () {
26 const EXEC_ARGS
= { cwd: path
.resolve(__dirname
, '..'), stdio: 'inherit' };
27 const LOCATION
= 'test';
28 const TEST_TIMEOUT
= 10000;
29 const TEST_FILE_NAME_0
= 'index.html';
30 const TEST_FILE_NAME_1
= 'test.txt';
36 browser
= new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
43 function getAppInfo(location
, done
) {
49 var inspect
= JSON
.parse(execSync('cloudron inspect'));
50 app
= inspect
.apps
.filter(function (a
) { return a
.location
=== location
; })[0];
51 expect(app
).to
.be
.an('object');
56 function waitForElement(elem
) {
57 return browser
.wait(until
.elementLocated(elem
), TEST_TIMEOUT
).then(function () {
58 return browser
.wait(until
.elementIsVisible(browser
.findElement(elem
)), TEST_TIMEOUT
);
62 // tests which are used more than once
63 function login(done
) {
64 browser
.manage().deleteAllCookies();
65 browser
.get('https://' + app
.fqdn
+ '/_admin');
67 waitForElement(By
.id('loginUsernameInput')).then(function () {
68 browser
.findElement(By
.id('loginUsernameInput')).sendKeys(process
.env
.USERNAME
);
69 browser
.findElement(By
.id('loginPasswordInput')).sendKeys(process
.env
.PASSWORD
);
70 browser
.findElement(By
.id('loginSubmitButton')).click();
72 waitForElement(By
.id('burgerMenuButton')).then(function () {
78 function logout(done
) {
79 browser
.get('https://' + app
.fqdn
+ '/_admin');
81 waitForElement(By
.id('burgerMenuButton')).then(function () {
82 browser
.findElement(By
.id('burgerMenuButton')).click();
84 // wait for open animation
87 waitForElement(By
.id('logoutButton')).then(function () {
88 browser
.findElement(By
.id('logoutButton')).click();
90 waitForElement(By
.id('loginUsernameInput')).then(function () {
97 function checkFileIsListed(name
, done
) {
98 browser
.get('https://' + app
.fqdn
+ '/_admin');
100 waitForElement(By
.xpath('//*[text()="' + name
+ '"]')).then(function () {
105 function checkFileIsPresent(done
) {
106 browser
.get('https://' + app
.fqdn
+ '/' + TEST_FILE_NAME_0
);
108 waitForElement(By
.xpath('//*[text()="test"]')).then(function () {
113 function checkIndexFileIsServedUp(done
) {
114 browser
.get('https://' + app
.fqdn
);
116 waitForElement(By
.xpath('//*[text()="test"]')).then(function () {
121 function checkFileIsGone(name
, done
) {
122 superagent
.get('https://' + app
.fqdn
+ '/' + name
).end(function (error
, result
) {
123 expect(error
).to
.be
.an('object');
124 expect(error
.response
.status
).to
.equal(404);
125 expect(result
).to
.be
.an('object');
130 function cliLogin(done
) {
131 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' } );
135 function uploadFile(name
, done
) {
136 // File upload can't be tested with selenium, since the file input is not visible and thus can't be interacted with :-(
138 execSync(path
.join(__dirname
, '/../cli/surfer.js') + ' put ' + path
.join(__dirname
, name
) + ' /', { stdio: 'inherit' } );
142 xit('build app', function () { execSync('cloudron build', EXEC_ARGS
); });
144 it('install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_ARGS
); });
145 it('can get app information', getAppInfo
);
147 it('can login', login
);
148 it('can cli login', cliLogin
);
149 it('can upload file', uploadFile
.bind(null, TEST_FILE_NAME_0
));
150 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_0
));
151 it('file is served up', checkFileIsPresent
);
152 it('file is served up', checkIndexFileIsServedUp
);
153 it('can upload second file', uploadFile
.bind(null, TEST_FILE_NAME_1
));
154 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_1
));
155 it('can delete second file with cli', function () {
156 execSync(path
.join(__dirname
, '/../cli/surfer.js') + ' del ' + TEST_FILE_NAME_1
, { stdio: 'inherit' } );
158 it('second file is gone', checkFileIsGone
.bind(null, TEST_FILE_NAME_1
));
159 it('can logout', logout
);
161 it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS
); });
162 it('restore app', function () { execSync(`cloudron restore --app ${app.id}`, EXEC_ARGS
); });
164 it('can login', login
);
165 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_0
));
166 it('file is served up', checkFileIsPresent
);
167 it('file is served up', checkIndexFileIsServedUp
);
168 it('second file is still gone', checkFileIsGone
.bind(null, TEST_FILE_NAME_1
));
169 it('can logout', logout
);
171 it('move to different location', function (done
) {
172 browser
.manage().deleteAllCookies();
174 // ensure we don't hit NXDOMAIN in the mean time
175 browser
.get('about:blank').then(function () {
176 execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS
);
177 getAppInfo(`${LOCATION}2`, done
);
181 it('can login', login
);
182 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_0
));
183 it('file is served up', checkFileIsPresent
);
184 it('file is served up', checkIndexFileIsServedUp
);
185 it('can logout', logout
);
187 it('uninstall app', function (done
) {
188 // ensure we don't hit NXDOMAIN in the mean time
189 browser
.get('about:blank').then(function () {
190 execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS
);
196 it('can install app', function () {
197 execSync(`cloudron install --appstore-id io.cloudron.surfer --location ${LOCATION}`, EXEC_ARGS
);
200 it('can get app information', getAppInfo
);
201 it('can login', login
);
202 it('can cli login', cliLogin
);
203 it('can upload file', uploadFile
.bind(null, TEST_FILE_NAME_0
));
204 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_0
));
205 it('file is served up', checkFileIsPresent
);
206 it('file is served up', checkIndexFileIsServedUp
);
207 it('can logout', logout
);
209 it('can update', function () {
210 execSync(`cloudron update --app ${LOCATION}`, EXEC_ARGS
);
213 it('can login', login
);
214 it('file is listed', checkFileIsListed
.bind(null, TEST_FILE_NAME_0
));
215 it('file is served up', checkFileIsPresent
);
216 it('file is served up', checkIndexFileIsServedUp
);
217 it('can logout', logout
);
219 it('uninstall app', function (done
) {
220 // ensure we don't hit NXDOMAIN in the mean time
221 browser
.get('about:blank').then(function () {
222 execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS
);