/* 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', function (done) { settings.getTimeZone(function (error, tz) { expect(error).to.be(null); expect(tz.length).to.not.be(0); done(); }); }); it('can get default autoupdate_pattern', function (done) { settings.getAutoupdatePattern(function (error, pattern) { expect(error).to.be(null); expect(pattern).to.be('00 00 1,3,5,23 * * *'); done(); }); }); 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', function (done) { settings.getBackupConfig(function (error, backupConfig) { expect(error).to.be(null); expect(backupConfig.provider).to.be('filesystem'); expect(backupConfig.backupFolder).to.be('/var/backups'); done(); }); }); 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'); }); }); });