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

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();
});