Move state enums to the model code

This commit is contained in:
Girish Ramakrishnan
2019-08-30 13:12:49 -07:00
parent b4cbf63519
commit dd0fb8292c
15 changed files with 118 additions and 156 deletions
+13 -12
View File
@@ -1,5 +1,6 @@
/* global it:false */
/* global describe:false */
/* global xdescribe:false */
/* global before:false */
/* global after:false */
@@ -366,9 +367,9 @@ describe('Apps', function () {
xdescribe('configureInstalledApps', function () {
before(function (done) {
async.series([
appdb.update.bind(null, APP_0.id, { installationState: appdb.ISTATE_INSTALLED }),
appdb.update.bind(null, APP_1.id, { installationState: appdb.ISTATE_ERROR }),
appdb.update.bind(null, APP_2.id, { installationState: appdb.ISTATE_INSTALLED })
appdb.update.bind(null, APP_0.id, { installationState: apps.ISTATE_INSTALLED }),
appdb.update.bind(null, APP_1.id, { installationState: apps.ISTATE_ERROR }),
appdb.update.bind(null, APP_2.id, { installationState: apps.ISTATE_INSTALLED })
], done);
});
@@ -377,9 +378,9 @@ describe('Apps', function () {
expect(error).to.be(null);
apps.getAll(function (error, apps) {
expect(apps[0].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE);
expect(apps[1].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE); // erorred app can be reconfigured after restore
expect(apps[2].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE);
expect(apps[0].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE);
expect(apps[1].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE); // erorred app can be reconfigured after restore
expect(apps[2].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE);
done();
});
@@ -390,9 +391,9 @@ describe('Apps', function () {
xdescribe('restoreInstalledApps', function () {
before(function (done) {
async.series([
appdb.update.bind(null, APP_0.id, { installationState: appdb.ISTATE_INSTALLED }),
appdb.update.bind(null, APP_1.id, { installationState: appdb.ISTATE_ERROR }),
appdb.update.bind(null, APP_2.id, { installationState: appdb.ISTATE_INSTALLED })
appdb.update.bind(null, APP_0.id, { installationState: apps.ISTATE_INSTALLED }),
appdb.update.bind(null, APP_1.id, { installationState: apps.ISTATE_ERROR }),
appdb.update.bind(null, APP_2.id, { installationState: apps.ISTATE_INSTALLED })
], done);
});
@@ -401,9 +402,9 @@ describe('Apps', function () {
expect(error).to.be(null);
apps.getAll(function (error, result) {
expect(result[0].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
expect(result[1].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
expect(result[2].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
expect(result[0].installationState).to.be(apps.ISTATE_PENDING_RESTORE);
expect(result[1].installationState).to.be(apps.ISTATE_PENDING_RESTORE);
expect(result[2].installationState).to.be(apps.ISTATE_PENDING_RESTORE);
done();
});
+2 -1
View File
@@ -7,6 +7,7 @@
var addons = require('../addons.js'),
appdb = require('../appdb.js'),
apps = require('../apps.js'),
apptask = require('../apptask.js'),
async = require('async'),
database = require('../database.js'),
@@ -81,7 +82,7 @@ var ADMIN = {
var APP = {
id: 'appid',
appStoreId: 'appStoreId',
installationState: appdb.ISTATE_PENDING_INSTALL,
installationState: apps.ISTATE_PENDING_INSTALL,
runState: null,
location: 'applocation',
domain: DOMAIN_0.domain,
+8 -44
View File
@@ -6,6 +6,7 @@
'use strict';
var appdb = require('../appdb.js'),
apps = require('../apps.js'),
async = require('async'),
authcodedb = require('../authcodedb.js'),
backupdb = require('../backupdb.js'),
@@ -391,7 +392,7 @@ describe('database', function () {
var APP_0 = {
id: 'appid-0',
appStoreId: 'appStoreId-0',
installationState: appdb.ISTATE_PENDING_INSTALL,
installationState: apps.ISTATE_PENDING_INSTALL,
error: null,
runState: null,
location: 'some-location-0',
@@ -969,7 +970,7 @@ describe('database', function () {
var APP_0 = {
id: 'appid-0',
appStoreId: 'appStoreId-0',
installationState: appdb.ISTATE_PENDING_INSTALL,
installationState: apps.ISTATE_PENDING_INSTALL,
error: null,
runState: null,
location: 'some-location-0',
@@ -1000,7 +1001,7 @@ describe('database', function () {
var APP_1 = {
id: 'appid-1',
appStoreId: 'appStoreId-1',
installationState: appdb.ISTATE_PENDING_INSTALL, // app health tests rely on this initial state
installationState: apps.ISTATE_PENDING_INSTALL, // app health tests rely on this initial state
error: null,
runState: null,
location: 'some-location-1',
@@ -1200,52 +1201,15 @@ describe('database', function () {
});
});
it('cannot set app as healthy because app is not installed', function (done) {
appdb.setHealth(APP_1.id, appdb.HEALTH_HEALTHY, new Date(), function (error) {
expect(error).to.be.ok();
it('can set app as healthy', function (done) {
appdb.setHealth(APP_1.id, apps.HEALTH_HEALTHY, new Date(), function (error) {
expect(error).to.be(null);
done();
});
});
it('cannot set app as healthy because app has pending run state', function (done) {
appdb.update(APP_1.id, { runState: appdb.RSTATE_PENDING_STOP, installationState: appdb.ISTATE_INSTALLED }, function (error) {
expect(error).to.be(null);
appdb.setHealth(APP_1.id, appdb.HEALTH_HEALTHY, new Date(), function (error) {
expect(error).to.be.ok();
done();
});
});
});
it('cannot set app as healthy because app has null run state', function (done) {
appdb.update(APP_1.id, { runState: null, installationState: appdb.ISTATE_INSTALLED }, function (error) {
expect(error).to.be(null);
appdb.setHealth(APP_1.id, appdb.HEALTH_HEALTHY, new Date(), function (error) {
expect(error).to.be.ok();
done();
});
});
});
it('can set app as healthy when installed and no pending runState', function (done) {
appdb.update(APP_1.id, { runState: appdb.RSTATE_RUNNING, installationState: appdb.ISTATE_INSTALLED }, function (error) {
expect(error).to.be(null);
appdb.setHealth(APP_1.id, appdb.HEALTH_HEALTHY, new Date(), function (error) {
expect(error).to.be(null);
appdb.get(APP_1.id, function (error, app) {
expect(error).to.be(null);
expect(app.health).to.be(appdb.HEALTH_HEALTHY);
done();
});
});
});
});
it('cannot set health of unknown app', function (done) {
appdb.setHealth('randomId', appdb.HEALTH_HEALTHY, new Date(), function (error) {
appdb.setHealth('randomId', apps.HEALTH_HEALTHY, new Date(), function (error) {
expect(error).to.be.ok();
done();
});
+2 -2
View File
@@ -63,9 +63,9 @@ var AUDIT_SOURCE = {
var APP_0 = {
id: 'appid-0',
appStoreId: 'appStoreId-0',
installationState: appdb.ISTATE_INSTALLED,
installationState: apps.ISTATE_INSTALLED,
error: null,
runState: appdb.RSTATE_RUNNING,
runState: apps.RSTATE_RUNNING,
location: 'some-location-0',
domain: DOMAIN_0.domain,
manifest: { version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0' },
+3 -3
View File
@@ -216,7 +216,7 @@ describe('updatechecker - app - manual (email)', function () {
var APP_0 = {
id: 'appid-0',
appStoreId: 'io.cloudron.app',
installationState: appdb.ISTATE_PENDING_INSTALL,
installationState: apps.ISTATE_PENDING_INSTALL,
error: null,
runState: null,
location: 'some-location-0',
@@ -323,7 +323,7 @@ describe('updatechecker - app - automatic (no email)', function () {
var APP_0 = {
id: 'appid-0',
appStoreId: 'io.cloudron.app',
installationState: appdb.ISTATE_PENDING_INSTALL,
installationState: apps.ISTATE_PENDING_INSTALL,
error: null,
runState: null,
location: 'some-location-0',
@@ -386,7 +386,7 @@ describe('updatechecker - app - automatic free (email)', function () {
var APP_0 = {
id: 'appid-0',
appStoreId: 'io.cloudron.app',
installationState: appdb.ISTATE_PENDING_INSTALL,
installationState: apps.ISTATE_PENDING_INSTALL,
error: null,
runState: null,
location: 'some-location-0',