UNPKG

@sync-in/server

Version:

The secure, open-source platform for file storage, sharing, collaboration, and sync

94 lines (93 loc) 4.36 kB
/* * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com> * This file is part of Sync-in | The open source file sync and share solution * See the LICENSE file for licensing details */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _common = require("@nestjs/common"); const _nodecluster = /*#__PURE__*/ _interop_require_default(require("node:cluster")); const _nodefs = /*#__PURE__*/ _interop_require_default(require("node:fs")); const _nodeos = /*#__PURE__*/ _interop_require_default(require("node:os")); const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path")); const _nodeprocess = /*#__PURE__*/ _interop_require_default(require("node:process")); const _appservice = require("./app.service"); const _configconstants = require("./configuration/config.constants"); const _configenvironment = require("./configuration/config.environment"); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } describe(_appservice.AppService.name, ()=>{ let appService; beforeAll(async ()=>{ appService = new _appservice.AppService(); _common.Logger.overrideLogger([ 'fatal' ]); }); it('should be defined', ()=>{ expect(appService).toBeDefined(); }); it('should clusterize', ()=>{ _configenvironment.configuration.server.restartOnFailure = true; const callBack = jest.fn().mockReturnValue({ process: { pid: 1 } }); _nodecluster.default.fork = jest.fn(()=>callBack()); const spyExit = jest.spyOn(_nodecluster.default, 'on'); expect(()=>_appservice.AppService.clusterize(callBack)).not.toThrow(); expect(callBack).toHaveBeenCalledTimes(_configenvironment.configuration.server.workers); expect(_nodecluster.default.fork).toHaveBeenCalledTimes(_configenvironment.configuration.server.workers); callBack.mockClear(); _appservice.AppService.schedulerPID = 1; _nodecluster.default.emit('exit', { process: { pid: 1 } }, 1, 1); _appservice.AppService.schedulerPID = 0; _nodecluster.default.emit('exit', { process: { pid: 1 } }, 1, 1); expect(spyExit).toHaveBeenCalled(); expect(callBack).toHaveBeenCalledTimes(2); jest.replaceProperty(_nodecluster.default, 'isPrimary', false); callBack.mockClear(); expect(()=>_appservice.AppService.clusterize(callBack)).not.toThrow(); expect(callBack).toHaveBeenCalledTimes(1); spyExit.mockClear(); }); it(`should use ${_configconstants.ENVIRONMENT_PREFIX} environment variables to override the configuration`, ()=>{ let conf = (0, _configenvironment.exportConfiguration)(); expect(conf.logger.stdout).toBe(true); expect(conf.logger.colorize).toBe(true); const tmpSecretFile = _nodepath.default.join(_nodeos.default.tmpdir(), 'secret'); _nodefs.default.writeFileSync(tmpSecretFile, 'fooBAR8888'); _nodeprocess.default.env[`${_configconstants.ENVIRONMENT_PREFIX}APPLICATIONS_FILES_ONLYOFFICE_SECRET`] = 'fooBAR'; _nodeprocess.default.env[`${_configconstants.ENVIRONMENT_PREFIX}LOGGER_STDOUT`] = 'false'; _nodeprocess.default.env[`${_configconstants.ENVIRONMENT_PREFIX}LOGGER_COLORIZE`] = '"false"'; _nodeprocess.default.env[`${_configconstants.ENVIRONMENT_PREFIX}APPLICATIONS_FILES_MAXUPLOADSIZE`] = '8888'; // docker compose secret file _nodeprocess.default.env[`${_configconstants.ENVIRONMENT_PREFIX}AUTH_TOKEN_ACCESS_SECRET_FILE`] = tmpSecretFile; conf = (0, _configenvironment.exportConfiguration)(true); expect(conf.applications.files.onlyoffice.secret).toBe('fooBAR'); expect(conf.logger.stdout).toBe(false); expect(conf.logger.colorize).toBe(false); expect(conf.applications.files.maxUploadSize).toBe(8888); expect(conf.auth.token.access.secret).toBe('fooBAR8888'); // cleanup secret file _nodefs.default.promises.rm(tmpSecretFile, { force: true }).catch((e)=>{ console.error(e); }); }); }); //# sourceMappingURL=app.service.spec.js.map