Files
cloudron-box/src/test/settings-test.js
2021-08-19 17:45:40 -07:00

96 lines
2.9 KiB
JavaScript

/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
var async = require('async'),
database = require('../database.js'),
expect = require('expect.js'),
MockS3 = require('mock-aws-s3'),
nock = require('nock'),
os = require('os'),
path = require('path'),
rimraf = require('rimraf'),
s3 = require('../storage/s3.js'),
settings = require('../settings.js');
function setup(done) {
nock.cleanAll();
async.series([
database.initialize,
function (callback) {
MockS3.config.basePath = path.join(os.tmpdir(), 's3-settings-test-buckets/');
s3._mockInject(MockS3);
callback();
}
], done);
}
function cleanup(done) {
s3._mockRestore();
rimraf.sync(MockS3.config.basePath);
async.series([
database._clear,
database.uninitialize
], done);
}
describe('Settings', function () {
describe('values', function () {
before(setup);
after(cleanup);
it('can get default timezone', async function () {
const tz = await settings.getTimeZone();
expect(tz.length).to.not.be(0);
});
it('can get default autoupdate_pattern', async function () {
const pattern = await settings.getAutoupdatePattern();
expect(pattern).to.be('00 00 1,3,5,23 * * *');
});
it ('can get default cloudron name', async function () {
const name = await settings.getCloudronName();
expect(name).to.be('Cloudron');
});
it('can get default cloudron avatar', async function () {
const avatar = await settings.getCloudronAvatar();
expect(avatar).to.be.a(Buffer);
});
it('can get backup config', async function () {
const backupConfig = await settings.getBackupConfig();
expect(backupConfig.provider).to.be('filesystem');
expect(backupConfig.backupFolder).to.be('/var/backups');
});
it('can get default unstable apps setting', async function () {
const enabled = await settings.getUnstableAppsConfig();
expect(enabled).to.be(true);
});
it('can set unstable apps setting', async function () {
await settings.setUnstableAppsConfig(false);
const enabled = await settings.getUnstableAppsConfig();
expect(enabled).to.be(false);
});
it('can get all values', async function () {
const allSettings = await settings.list();
expect(allSettings[settings.TIME_ZONE_KEY]).to.be.a('string');
expect(allSettings[settings.AUTOUPDATE_PATTERN_KEY]).to.be.a('string');
expect(allSettings[settings.CLOUDRON_NAME_KEY]).to.be.a('string');
expect(allSettings[settings.UNSTABLE_APPS_KEY]).to.be.a('boolean');
});
});
});