cloudron-e2e-test/common.js
2016-01-27 09:21:41 -08:00

80 lines
2.5 KiB
JavaScript

'use strict';
var debug = require('debug')('e2e:common'),
path = require('path'),
safe = require('safetydance'),
util = require('util'),
_ = require('underscore');
exports = module.exports = {
TESTAPP_ID: 'io.cloudron.testapp',
PREV_TESTAPP_VERSION : '9.0.0',
TESTAPP_VERSION : '10.0.0',
cloudronDomain: cloudronDomain,
verifyResponse2xx: verifyResponse2xx,
verifyResponse: verifyResponse,
getOwner: getOwner,
getAdmin: getAdmin,
stripeSecret: stripeSecret,
stripUnreachable: stripUnreachable
};
var gEcosystem = safe.require(path.join(__dirname, '../secrets/e2e-test/ecosystem-staging.json'));
function cloudronDomain(filename) {
return 't' + path.basename(filename.replace(/-/g,''), 'test.js') + '.selfhost.io';
}
function stripUnreachable(releases) {
var reachableVersions = [ ];
var curVersion = '0.0.1';
while (true) {
reachableVersions.push(curVersion);
var nextVersion = releases[curVersion].next;
if (!nextVersion) break;
curVersion = nextVersion;
}
return _.pick(releases, reachableVersions);
}
function verifyResponse2xx(res, args) {
if (res.statusCode < 200 || res.statusCode > 299) {
debug('Response error statusCode:%s error:%s body:%j', res.statusCode, res.error, res.body);
var errorMessage = util.format.apply(util, Array.prototype.slice.call(arguments, 1));
debug(errorMessage.red);
throw new Error(errorMessage);
}
}
function verifyResponse(res, args) {
if (res.statusCode < 200 || res.statusCode > 399) {
debug('Response error statusCode:%s error:%s body:%j', res.statusCode, res.error, res.body);
var errorMessage = util.format.apply(util, Array.prototype.slice.call(arguments, 1));
debug(errorMessage.red);
throw new Error(errorMessage);
}
}
function getOwner() {
return {
username: process.env.APPSTORE_USERNAME || gEcosystem.env.APPSTORE_USERNAME,
password: process.env.APPSTORE_PASSWORD || gEcosystem.env.APPSTORE_PASSWORD,
email: process.env.APPSTORE_EMAIL || gEcosystem.env.APPSTORE_EMAIL
};
}
function getAdmin() {
return {
username: process.env.APPSTORE_ADMIN_USERNAME || gEcosystem.env.APPSTORE_ADMIN_USERNAME,
password: process.env.APPSTORE_ADMIN_PASSWORD || gEcosystem.env.APPSTORE_ADMIN_PASSWORD,
email: process.env.APPSTORE_ADMIN_EMAIL || gEcosystem.env.APPSTORE_ADMIN_EMAIL
};
}
function stripeSecret() {
return process.env.STRIPE_SECRET || gEcosystem.env.STRIPE_SECRET;
}