2021-01-04 17:32:19 +08:00
|
|
|
import * as fs from 'fs';
|
2020-01-04 03:28:03 +08:00
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
|
|
|
import {Server} from '../../../../../src/backend/server';
|
2024-03-26 07:09:32 +08:00
|
|
|
import {DatabaseType, LogLevel, ServerConfig} from '../../../../../src/common/config/private/PrivateConfig';
|
2020-12-29 05:08:57 +08:00
|
|
|
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
|
2023-01-02 05:47:39 +08:00
|
|
|
import {TAGS} from '../../../../../src/common/config/public/ClientConfig';
|
2023-01-13 18:22:49 +08:00
|
|
|
import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
2023-07-30 20:06:25 +08:00
|
|
|
import {UserRoles} from '../../../../../src/common/entities/UserDTO';
|
2023-11-13 23:51:25 +08:00
|
|
|
import {ExtensionConfigWrapper} from '../../../../../src/backend/model/extension/ExtensionConfigWrapper';
|
2024-03-26 05:21:18 +08:00
|
|
|
import {TestHelper} from '../../../../TestHelper';
|
2020-01-04 03:28:03 +08:00
|
|
|
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
const chai: any = require('chai');
|
|
|
|
const chaiHttp = require('chai-http');
|
|
|
|
const should = chai.should();
|
|
|
|
chai.use(chaiHttp);
|
|
|
|
|
|
|
|
describe('SettingsRouter', () => {
|
|
|
|
|
2024-03-26 05:21:18 +08:00
|
|
|
let server: Server;
|
2020-01-04 03:28:03 +08:00
|
|
|
beforeEach(async () => {
|
2024-03-26 05:21:18 +08:00
|
|
|
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Database.type = DatabaseType.sqlite;
|
2024-03-26 05:21:18 +08:00
|
|
|
Config.Database.dbFolder = TestHelper.TMP_DIR;
|
2024-03-26 07:15:58 +08:00
|
|
|
Config.Extensions.folder = 'notexisting';
|
2020-12-29 05:08:57 +08:00
|
|
|
ProjectPath.reset();
|
2024-03-26 05:21:18 +08:00
|
|
|
|
|
|
|
server = new Server(false);
|
|
|
|
await server.onStarted.wait();
|
|
|
|
await ObjectManagers.getInstance().init();
|
2020-01-04 03:28:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
2023-01-13 18:22:49 +08:00
|
|
|
await ObjectManagers.reset();
|
2024-03-26 05:21:18 +08:00
|
|
|
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
|
2020-01-04 03:28:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('/GET settings', () => {
|
2021-05-11 21:57:36 +08:00
|
|
|
it('it should GET the settings', async () => {
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Users.authenticationRequired = false;
|
2023-07-30 20:06:25 +08:00
|
|
|
Config.Users.unAuthenticatedUserRole = UserRoles.Admin;
|
2024-03-26 05:51:27 +08:00
|
|
|
const originalSettings = await ExtensionConfigWrapper.original();
|
2024-03-26 05:21:18 +08:00
|
|
|
|
2024-03-26 06:10:10 +08:00
|
|
|
originalSettings.Environment.upTime = null;
|
|
|
|
const originalJSON = JSON.parse(JSON.stringify(originalSettings.toJSON({
|
|
|
|
attachState: true,
|
|
|
|
attachVolatile: true,
|
|
|
|
skipTags: {secret: true} as TAGS
|
|
|
|
})));
|
2024-03-26 07:15:58 +08:00
|
|
|
console.log(originalJSON);
|
2024-03-26 06:10:10 +08:00
|
|
|
|
2024-03-26 05:21:18 +08:00
|
|
|
const result = await chai.request(server.Server)
|
2022-12-29 02:12:18 +08:00
|
|
|
.get(Config.Server.apiPath + '/settings');
|
2020-01-04 03:28:03 +08:00
|
|
|
|
|
|
|
result.res.should.have.status(200);
|
|
|
|
result.body.should.be.a('object');
|
|
|
|
should.equal(result.body.error, null);
|
2023-01-02 05:47:39 +08:00
|
|
|
(result.body.result as ServerConfig).Environment.upTime = null;
|
2024-03-26 06:10:10 +08:00
|
|
|
result.body.result.should.deep.equal(originalJSON);
|
2020-01-04 03:28:03 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|