Skip to content

Commit

Permalink
Update tests to support single port depolyment and custom server
Browse files Browse the repository at this point in the history
  • Loading branch information
enykeev committed Jan 28, 2016
1 parent 07def3a commit 53b71ed
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ var gulp = require('gulp')
, header = require('gulp-header')
, git = require('git-rev-sync')
, pkg = require('./package.json')
, yargs = require('yargs')
;

var express = require('express')
, server
, argv = yargs.argv
, app = express();

app.use(express.static(__dirname));
Expand Down Expand Up @@ -149,7 +151,7 @@ gulp.task('serve', ['build'], function () {
});

gulp.task('test', ['build', 'serve'], function () {
return gulp.src('tests/**/test-*.js', {read: false})
return gulp.src(argv['test-files'] || 'tests/**/test-*.js', {read: false})
.pipe(mocha({
reporter: 'dot'
}))
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"repository": "stackstorm/st2web",
"dependencies": {
"st2client": "^0.4.3"
"st2client": "^0.4.3",
"urijs": "^1.17.0"
},
"devDependencies": {
"chai": "^3.3.0",
Expand Down Expand Up @@ -37,6 +38,7 @@
"main-bower-files": "^2.4.0",
"request": "^2.49.0",
"yamljs": "^0.2.4",
"yargs": "^3.32.0",
"zombie": "https://github.com/enykeev/zombie/releases/download/enykeev-1/zombie-4.1.0.tgz"
}
}
4 changes: 2 additions & 2 deletions tests/test-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('User visits actions page', function () {

before(function () {
resource = browser.resources.filter(function (e) {
return new RegExp('^http://172.168.60.10:9101/v1/actions$').test(e.url);
return new RegExp('^https://example.com/api/v1/actions$').test(e.url);
});
});

Expand All @@ -58,7 +58,7 @@ describe('User visits actions page', function () {

before(function () {
resource = browser.resources.filter(function (e) {
return new RegExp('^http://172.168.60.10:9101/v1/actions/views/overview/[\\w.-]+$').test(e.url);
return new RegExp('^https://example.com/api/v1/actions/views/overview/[\\w.-]+$').test(e.url);
});
});

Expand Down
8 changes: 4 additions & 4 deletions tests/test-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('User visits history page', function () {

before(function () {
resource = browser.resources.filter(function (e) {
return ~e.url.indexOf('http://172.168.60.10:9101/v1/executions?'); //jshint ignore:line
return ~e.url.indexOf('https://example.com/api/v1/executions?'); //jshint ignore:line
});
});

Expand Down Expand Up @@ -59,7 +59,7 @@ describe('User visits history page', function () {

before(function () {
resource = browser.resources.filter(function (e) {
return new RegExp('^http://172.168.60.10:9101/v1/executions/\\w+$').test(e.url);
return new RegExp('^https://example.com/api/v1/executions/\\w+$').test(e.url);
});
});

Expand All @@ -85,7 +85,7 @@ describe('User visits history page', function () {
browser.assert.text(util.name('header_description'), execution.action.description, 'Wrong description in header');

browser.assert.text(util.name('status'), util.capitalize(execution.status), 'Wrong status');
browser.assert.attribute(util.name('execution_id'), 'value', execution.id, 'Wrong execution id');
browser.assert.text(util.name('execution_id'), execution.id, 'Wrong execution id');
browser.assert.text(util.name('start_timestamp'), util.formatUTC(execution.start_timestamp), 'Wrong start time');
browser.assert.text(util.name('end_timestamp'), util.formatUTC(execution.end_timestamp), 'Wrong end time');

Expand Down Expand Up @@ -122,7 +122,7 @@ describe('User visits history page', function () {
browser.assert.elements(util.name('rerun_popup'), 0, 'Rerun popup is in DOM when it should not be');

var resource = browser.resources.filter(function (e) {
return e.request.method === 'POST' && new RegExp('^http://172.168.60.10:9101/v1/executions/\\w+/re_run$').test(e.url);
return e.request.method === 'POST' && new RegExp('^https://example.com/api/v1/executions/\\w+/re_run$').test(e.url);
});

expect(resource).to.have.length(1, 'Rerun should make a single request');
Expand Down
6 changes: 3 additions & 3 deletions tests/test-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('User visits rules page', function () {

before(function () {
resource = browser.resources.filter(function (e) {
return new RegExp('^http://172.168.60.10:9101/v1/rules/views$').test(e.url);
return new RegExp('^https://example.com/api/v1/rules/views$').test(e.url);
});
});

Expand All @@ -58,7 +58,7 @@ describe('User visits rules page', function () {

before(function () {
resource = browser.resources.filter(function (e) {
var match = e.url.match(new RegExp('^http://172.168.60.10:9101/v1/rules/([\\w.-]+)$'));
var match = e.url.match(new RegExp('^https://example.com/api/v1/rules/([\\w.-]+)$'));
return match && match[1] && match[1] !== 'views';
});
});
Expand All @@ -83,7 +83,7 @@ describe('User visits rules page', function () {
browser.assert.element(util.name('delete_button'), 'Delete button is missing');

browser.assert.text(util.name('status'), rule.enabled ? 'Enabled' : 'Disabled', 'Wrong status');
browser.assert.text(util.name('header_name'), rule.name, 'Wrong name in header');
browser.assert.text(util.name('header_name'), rule.ref, 'Wrong ref in header');
browser.assert.text(util.name('header_description'), rule.description, 'Wrong description in header');
browser.assert.text(util.name('header_if'), 'If ' + rule.trigger.ref, 'Wrong if in header');
browser.assert.text(util.name('header_then'), 'Then ' + rule.action.ref, 'Wrong then in header');
Expand Down
28 changes: 26 additions & 2 deletions tests/util.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
/* jshint node:true */
'use strict';
var URI = require('urijs');

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

module.exports = function (browser) {
browser.pipeline.addHandler(function(browser, request) {
var url = new URI(request.url);

if (url.directory().match(/^\/auth/) || url.directory().match(/^\/api/)) {
request.url = url.host(process.env.ST2_HOST).toString();
}

return null;
});

browser.pipeline.addHandler(function(browser, request, response) {
var url = new URI(response.url);

if (url.host() === process.env.ST2_HOST) {
response._url = url.host('example.com').toString();
request.url = response.url;
}

return response;
});

return {
login: function () {
return browser
.fill('username', 'testu')
.fill('password', 'testp')
.fill('username', process.env.ST2_USERNAME)
.fill('password', process.env.ST2_PASSWORD)
.pressButton('Connect');
},
capitalize: function (str) {
Expand Down

0 comments on commit 53b71ed

Please sign in to comment.