diff --git a/appstore.js b/appstore.js index 017bd93..004a0c9 100644 --- a/appstore.js +++ b/appstore.js @@ -1,8 +1,7 @@ 'use strict'; -var debug = require('debug')('e2e:appstore'), - fs = require('fs'), - path = require('path'), +var common = require('./common.js'), + debug = require('debug')('e2e:appstore'), request = require('superagent-sync'), sleep = require('sleep').sleep, stripe = require('stripe'); @@ -17,12 +16,6 @@ function AppStore(origin) { password: null, accessToken: null }; - - if (fs.existsSync(path.join(__dirname, '../ecosystem.json'))) { - this._ecosystem = require(path.join(__dirname, '../ecosystem.json')); // staging appstore - } else { - this._ecosystem = require(path.join(__dirname, '../keys/appstore/ecosystem-staging.json')); - } } function verifyResponse(res, errorMessage) { @@ -106,7 +99,7 @@ AppStore.prototype.restore = function (boxId, backupId) { }; AppStore.prototype.setupBilling = function (callback) { - var stripeApi = stripe(this._ecosystem.env['STRIPE_SECRET']); + var stripeApi = stripe(common.stripeSecret()); var that = this; diff --git a/common.js b/common.js index 92dae1f..4f210cc 100644 --- a/common.js +++ b/common.js @@ -9,9 +9,15 @@ exports = module.exports = { cloudronDomain: cloudronDomain, verifyResponse: verifyResponse, getOwner: getOwner, + stripeSecret: stripeSecret }; var gNow = ((new Date()).getTime() / 1000).toFixed(); +var gEcosystem = null; +try { + gEcosystem = require(path.join(__dirname, '../keys/appstore/ecosystem-staging.json')); +} catch (e) { +} function cloudronDomain(filename) { return 't-' + path.basename(filename, '-test.js') + '-' + gNow + '.smartserver.io'; @@ -27,9 +33,12 @@ function verifyResponse(res, errorMessage) { function getOwner() { return { - username: process.env.APPSTORE_USERNAME || 'test', - password: process.env.APPSTORE_PASSWORD || 'test1234', - email: process.env.APPSTORE_EMAIL || 'test@cloudron.io' + username: process.env.APPSTORE_USERNAME || gEcosystem.APPSTORE_USERNAME, + password: process.env.APPSTORE_PASSWORD || gEcosystem.APPSTORE_PASSWORD, + email: process.env.APPSTORE_EMAIL || gEcosystem.APPSTORE_EMAIL }; } +function stripeSecret() { + return process.env.STRIPE_SECRET; +}