Fixup some app tests using test/common.js
This commit is contained in:
@@ -8,9 +8,10 @@
|
||||
const appdb = require('../appdb.js'),
|
||||
apps = require('../apps.js'),
|
||||
async = require('async'),
|
||||
blobs = require('../blobs.js'),
|
||||
constants = require('../constants.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
database = require('../database.js'),
|
||||
common = require('./common.js'),
|
||||
domains = require('../domains.js'),
|
||||
expect = require('expect.js'),
|
||||
hat = require('../hat.js'),
|
||||
@@ -20,35 +21,9 @@ const appdb = require('../appdb.js'),
|
||||
let AUDIT_SOURCE = { ip: '1.2.3.4' };
|
||||
|
||||
describe('Apps', function () {
|
||||
var ADMIN_0 = {
|
||||
id: 'admin123',
|
||||
username: 'admin123',
|
||||
password: 'secret',
|
||||
email: 'admin@me.com',
|
||||
fallbackEmail: 'admin@me.com',
|
||||
salt: 'morton',
|
||||
createdAt: 'sometime back',
|
||||
resetToken: hat(256),
|
||||
displayName: '',
|
||||
groupIds: [],
|
||||
role: 'owner',
|
||||
source: ''
|
||||
};
|
||||
var ADMIN_0 = common.ADMIN;
|
||||
|
||||
var USER_0 = {
|
||||
id: 'uuid213',
|
||||
username: 'uuid213',
|
||||
password: 'secret',
|
||||
email: 'safe@me.com',
|
||||
fallbackEmail: 'safe@me.com',
|
||||
salt: 'morton',
|
||||
createdAt: 'sometime back',
|
||||
resetToken: hat(256),
|
||||
displayName: '',
|
||||
groupIds: [],
|
||||
role: 'user',
|
||||
source: ''
|
||||
};
|
||||
var USER_0 = common.USER;
|
||||
|
||||
var USER_1 = {
|
||||
id: 'uuid2134',
|
||||
@@ -62,7 +37,8 @@ describe('Apps', function () {
|
||||
displayName: '',
|
||||
groupIds: [ 'somegroup' ],
|
||||
role: 'user',
|
||||
source: ''
|
||||
source: '',
|
||||
avatar: constants.AVATAR_NONE
|
||||
};
|
||||
|
||||
var GROUP_0 = {
|
||||
@@ -76,15 +52,7 @@ describe('Apps', function () {
|
||||
source: 'ldap'
|
||||
};
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
provider: 'noop',
|
||||
config: { },
|
||||
fallbackCertificate: null,
|
||||
tlsConfig: { provider: 'fallback' },
|
||||
wellKnown: null
|
||||
};
|
||||
const DOMAIN_0 = common.DOMAIN;
|
||||
|
||||
const DOMAIN_1 = {
|
||||
domain: 'example2.com',
|
||||
@@ -171,27 +139,20 @@ describe('Apps', function () {
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear,
|
||||
blobs.initSecrets,
|
||||
provision.setup.bind(null, DOMAIN_0, { provider: 'generic' }, AUDIT_SOURCE),
|
||||
domains.add.bind(null, DOMAIN_1.domain, DOMAIN_1, AUDIT_SOURCE),
|
||||
userdb.add.bind(null, ADMIN_0.id, ADMIN_0),
|
||||
userdb.add.bind(null, USER_0.id, USER_0),
|
||||
userdb.add.bind(null, USER_1.id, USER_1),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, apps._translatePortBindings(APP_0.portBindings, APP_0.manifest), APP_0),
|
||||
appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, apps._translatePortBindings(APP_1.portBindings, APP_1.manifest), APP_1),
|
||||
appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.domain, apps._translatePortBindings(APP_2.portBindings, APP_2.manifest), APP_2),
|
||||
], done);
|
||||
common.setup(function (error) {
|
||||
if (error) return done(error);
|
||||
|
||||
async.series([
|
||||
userdb.add.bind(null, USER_1.id, USER_1),
|
||||
domains.add.bind(null, DOMAIN_1.domain, DOMAIN_1, AUDIT_SOURCE),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, apps._translatePortBindings(APP_0.portBindings, APP_0.manifest), APP_0),
|
||||
appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, apps._translatePortBindings(APP_1.portBindings, APP_1.manifest), APP_1),
|
||||
appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.domain, apps._translatePortBindings(APP_2.portBindings, APP_2.manifest), APP_2),
|
||||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
});
|
||||
after(common.cleanup);
|
||||
|
||||
describe('validatePortBindings', function () {
|
||||
it('does not allow invalid host port', function () {
|
||||
@@ -250,9 +211,9 @@ describe('Apps', function () {
|
||||
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.be(null);
|
||||
expect(apps[0].fqdn).to.eql(APP_0.location + '.' + DOMAIN_0.domain);
|
||||
expect(apps[1].id).to.be(APP_0.id);
|
||||
expect(apps[1].iconUrl).to.be(null);
|
||||
expect(apps[1].fqdn).to.eql(APP_0.location + '.' + DOMAIN_0.domain);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -353,9 +314,10 @@ describe('Apps', function () {
|
||||
it('succeeds for USER_0', function (done) {
|
||||
apps.getAllByUser(USER_0, function (error, result) {
|
||||
expect(error).to.equal(null);
|
||||
expect(result.length).to.equal(2);
|
||||
expect(result[0].id).to.equal(APP_0.id);
|
||||
expect(result[1].id).to.equal(APP_2.id);
|
||||
expect(result.length).to.equal(3);
|
||||
expect(result[0].id).to.equal(common.APP.id);
|
||||
expect(result[1].id).to.equal(APP_0.id);
|
||||
expect(result[2].id).to.equal(APP_2.id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -363,9 +325,10 @@ describe('Apps', function () {
|
||||
it('succeeds for USER_1', function (done) {
|
||||
apps.getAllByUser(USER_1, function (error, result) {
|
||||
expect(error).to.equal(null);
|
||||
expect(result.length).to.equal(2);
|
||||
expect(result[0].id).to.equal(APP_0.id);
|
||||
expect(result[1].id).to.equal(APP_1.id);
|
||||
expect(result.length).to.equal(3);
|
||||
expect(result[0].id).to.equal(common.APP.id);
|
||||
expect(result[1].id).to.equal(APP_0.id);
|
||||
expect(result[2].id).to.equal(APP_1.id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -373,10 +336,11 @@ describe('Apps', function () {
|
||||
it('returns all apps for admin', function (done) {
|
||||
apps.getAllByUser(ADMIN_0, function (error, result) {
|
||||
expect(error).to.equal(null);
|
||||
expect(result.length).to.equal(3);
|
||||
expect(result[0].id).to.equal(APP_0.id);
|
||||
expect(result[1].id).to.equal(APP_1.id);
|
||||
expect(result[2].id).to.equal(APP_2.id);
|
||||
expect(result.length).to.equal(4);
|
||||
expect(result[0].id).to.equal(common.APP.id);
|
||||
expect(result[1].id).to.equal(APP_0.id);
|
||||
expect(result[2].id).to.equal(APP_1.id);
|
||||
expect(result[3].id).to.equal(APP_2.id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -397,8 +361,9 @@ describe('Apps', function () {
|
||||
|
||||
apps.getAll(function (error, result) {
|
||||
expect(result[0].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE);
|
||||
expect(result[1].installationState).to.be(apps.ISTATE_ERROR);
|
||||
expect(result[2].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE);
|
||||
expect(result[1].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE);
|
||||
expect(result[2].installationState).to.be(apps.ISTATE_ERROR);
|
||||
expect(result[3].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE);
|
||||
|
||||
done();
|
||||
});
|
||||
@@ -421,8 +386,9 @@ describe('Apps', function () {
|
||||
|
||||
apps.getAll(function (error, result) {
|
||||
expect(result[0].installationState).to.be(apps.ISTATE_PENDING_INSTALL);
|
||||
expect(result[1].installationState).to.be(apps.ISTATE_ERROR);
|
||||
expect(result[2].installationState).to.be(apps.ISTATE_PENDING_INSTALL);
|
||||
expect(result[1].installationState).to.be(apps.ISTATE_PENDING_INSTALL);
|
||||
expect(result[2].installationState).to.be(apps.ISTATE_ERROR);
|
||||
expect(result[3].installationState).to.be(apps.ISTATE_PENDING_INSTALL);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user