From 4458dd4dfd8e7a27f4fdc4fb4f9121a0e5507688 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Wed, 3 Sep 2014 07:56:42 -0700 Subject: [PATCH] Add more apps tests --- src/apps.js | 6 +++ src/test/apps-test.js | 87 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/apps.js b/src/apps.js index 9da406193..12b372d1f 100644 --- a/src/apps.js +++ b/src/apps.js @@ -139,6 +139,9 @@ function get(appId, callback) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app')); if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); + app.iconUrl = config.appServerUrl + '/api/v1/appstore/apps/' + app.id + '/icon'; + app.fqdn = appFqdn(app.location); + callback(null, app); }); } @@ -150,6 +153,9 @@ function getBySubdomain(subdomain, callback) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app')); if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); + app.iconUrl = config.appServerUrl + '/api/v1/appstore/apps/' + app.id + '/icon'; + app.fqdn = appFqdn(app.location); + callback(null, app); }); } diff --git a/src/test/apps-test.js b/src/test/apps-test.js index 0e9fa1ac1..297260a5d 100644 --- a/src/test/apps-test.js +++ b/src/test/apps-test.js @@ -7,9 +7,45 @@ 'use strict'; var apps = require('../apps.js'), - expect = require('expect.js'); + appdb = require('../appdb.js'), + expect = require('expect.js'), + database = require('../database.js'), + mkdirp = require('mkdirp'), + rimraf = require('rimraf'), + config = require('../../config.js'), + AppsError = apps.AppsError; describe('Apps', function () { + var APP_0 = { + id: 'appid-0', + appStoreId: 'appStoreId-0', + version: null, + installationState: appdb.ISTATE_PENDING_INSTALL, + installationProgress: null, + runState: null, + location: 'some-location-0', + manifest: null, + httpPort: null, + containerId: null, + portBindings: { "1234": "5678" }, + healthy: null + }; + + before(function (done) { + mkdirp.sync(config.configRoot); + + database.create(function (error) { + expect(error).to.be(null); + appdb.add(APP_0.id, APP_0.appStoreId, APP_0.location, APP_0.portBindings, done); + }); + }); + + after(function (done) { + database.uninitialize(); + rimraf.sync(config.baseDir); + done(); + }); + describe('validateSubdomain', function () { it('does not allow admin subdomain', function () { expect(apps._validateSubdomain('admin', 'cloudron.us')).to.be.an(Error); @@ -65,5 +101,54 @@ describe('Apps', function () { expect(apps._validatePortBindings({ '100': '4033', '25': '3242', '553': '1234' })).to.be(null); }); }); + + describe('getters', function () { + it('cannot get invalid app', function (done) { + apps.get('nope', function (error, app) { + expect(error).to.be.ok(); + expect(error.reason).to.be(AppsError.NOT_FOUND); + done(); + }); + }); + + it('can get valid app', function (done) { + apps.get(APP_0.id, function (error, app) { + expect(error).to.be(null); + expect(app).to.be.ok(); + expect(app.iconUrl).to.eql(config.appServerUrl + '/api/v1/appstore/apps/' + APP_0.id + '/icon'); + expect(app.fqdn).to.eql(APP_0.location + '-' + config.fqdn); + done(); + }); + }); + + it('cannot getBySubdomain', function (done) { + apps.getBySubdomain('moang', function (error, app) { + expect(error).to.be.ok(); + expect(error.reason).to.be(AppsError.NOT_FOUND); + done(); + }); + }); + + it('can getBySubdomain', function (done) { + apps.getBySubdomain(APP_0.location, function (error, app) { + expect(error).to.be(null); + expect(app).to.be.ok(); + expect(app.iconUrl).to.eql(config.appServerUrl + '/api/v1/appstore/apps/' + APP_0.id + '/icon'); + expect(app.fqdn).to.eql(APP_0.location + '-' + config.fqdn); + done(); + }); + }); + + it('can getAll', function (done) { + apps.getAll(function (error, apps) { + expect(error).to.be(null); + expect(apps).to.be.an(Array); + expect(apps[0].id).to.be(APP_0.id); + expect(apps[0].iconUrl).to.eql(config.appServerUrl + '/api/v1/appstore/apps/' + APP_0.id + '/icon'); + expect(apps[0].fqdn).to.eql(APP_0.location + '-' + config.fqdn); + done(); + }); + }); + }); });