diff --git a/src/cloudron.js b/src/cloudron.js index 787fa2dda..d8e1b8630 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -28,6 +28,7 @@ var apps = require('./apps.js'), async = require('async'), backups = require('./backups.js'), BackupsError = require('./backups.js').BackupsError, + bytes = require('bytes'), clientdb = require('./clientdb.js'), config = require('./config.js'), debug = require('debug')('box:cloudron'), @@ -221,7 +222,6 @@ function getCloudronDetails(callback) { function getConfig(callback) { assert.strictEqual(typeof callback, 'function'); - // TODO avoid pyramid of awesomeness with async getCloudronDetails(function (error, result) { if (error) { console.error('Failed to fetch cloudron details.', error); @@ -233,6 +233,10 @@ function getConfig(callback) { }; } + // We rely at the moment on the size being specified in 512mb,1gb,... + // TODO provide that number from the appstore + var memory = bytes(result.size) || 0; + settings.getCloudronName(function (error, cloudronName) { if (error) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, error)); @@ -252,6 +256,7 @@ function getConfig(callback) { developerMode: developerMode, region: result.region, size: result.size, + memory: memory, cloudronName: cloudronName }); }); diff --git a/src/routes/test/cloudron-test.js b/src/routes/test/cloudron-test.js index e055259af..c56126091 100644 --- a/src/routes/test/cloudron-test.js +++ b/src/routes/test/cloudron-test.js @@ -318,6 +318,7 @@ describe('Cloudron', function () { expect(result.body.developerMode).to.be.a('boolean'); expect(result.body.size).to.eql(null); expect(result.body.region).to.eql(null); + expect(result.body.memory).to.eql(0); expect(result.body.cloudronName).to.be.a('string'); done(); @@ -325,7 +326,7 @@ describe('Cloudron', function () { }); it('succeeds', function (done) { - var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/localhost?token=' + config.token()).reply(200, { box: { region: 'sfo', size: 'small' }}); + var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/localhost?token=' + config.token()).reply(200, { box: { region: 'sfo', size: '1gb' }}); request.get(SERVER_URL + '/api/v1/cloudron/config') .query({ access_token: token }) @@ -340,8 +341,9 @@ describe('Cloudron', function () { expect(result.body.update).to.be.an('object'); expect(result.body.version).to.eql('0.5.0'); expect(result.body.developerMode).to.be.a('boolean'); - expect(result.body.size).to.eql('small'); + expect(result.body.size).to.eql('1gb'); expect(result.body.region).to.eql('sfo'); + expect(result.body.memory).to.eql(1073741824); expect(result.body.cloudronName).to.be.a('string'); expect(scope.isDone()).to.be.ok(); @@ -455,7 +457,7 @@ describe('Cloudron', function () { .reply(201, { credentials: { AccessKeyId: 'accessKeyId', SecretAccessKey: 'secretAccessKey', SessionToken: 'sessionToken' } }); var scope3 = nock(config.apiServerOrigin()) - .post('/api/v1/boxes/' + config.fqdn() + '/backupDone?token=APPSTORE_TOKEN', function (body) { + .post('/api/v1/boxes/' + config.fqdn() + '/backupDone?token=APPSTORE_TOKEN', function (body) { return body.boxVersion && body.restoreKey && !body.appId && !body.appVersion && body.appBackupIds.length === 0; }) .reply(200, { id: 'someid' }); @@ -494,7 +496,7 @@ describe('Cloudron', function () { }).reply(202, {}); var scope2 = nock(config.apiServerOrigin()) - .post('/api/v1/boxes/' + config.fqdn() + '/backupDone?token=APPSTORE_TOKEN', function (body) { + .post('/api/v1/boxes/' + config.fqdn() + '/backupDone?token=APPSTORE_TOKEN', function (body) { return body.boxVersion && body.restoreKey && !body.appId && !body.appVersion && body.appBackupIds.length === 0; }) .reply(200, { id: 'someid' });