2020-01-04 03:28:03 +08:00
|
|
|
import * as path from 'path';
|
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';
|
2023-01-02 05:47:39 +08:00
|
|
|
import {DatabaseType, 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';
|
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', () => {
|
|
|
|
|
|
|
|
const tempDir = path.join(__dirname, '../../tmp');
|
|
|
|
beforeEach(async () => {
|
2024-03-26 04:38:09 +08:00
|
|
|
await ObjectManagers.reset();
|
2022-01-15 18:32:46 +08:00
|
|
|
await fs.promises.rm(tempDir, {recursive: true, force: true});
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Database.type = DatabaseType.sqlite;
|
|
|
|
Config.Database.dbFolder = tempDir;
|
2020-12-29 05:08:57 +08:00
|
|
|
ProjectPath.reset();
|
2020-01-04 03:28:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
2023-01-13 18:22:49 +08:00
|
|
|
await ObjectManagers.reset();
|
2022-01-15 18:32:46 +08:00
|
|
|
await fs.promises.rm(tempDir, {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;
|
2023-11-13 23:51:25 +08:00
|
|
|
const originalSettings = await ExtensionConfigWrapper.original();
|
2020-01-04 03:28:03 +08:00
|
|
|
const srv = new Server();
|
|
|
|
await srv.onStarted.wait();
|
2023-11-17 06:41:05 +08:00
|
|
|
const result = await chai.request(srv.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;
|
2022-12-29 02:12:18 +08:00
|
|
|
originalSettings.Environment.upTime = null;
|
2023-01-02 05:47:39 +08:00
|
|
|
result.body.result.should.deep.equal(JSON.parse(JSON.stringify(originalSettings.toJSON({
|
|
|
|
attachState: true,
|
|
|
|
attachVolatile: true,
|
|
|
|
skipTags: {secret: true} as TAGS
|
|
|
|
}))));
|
2020-01-04 03:28:03 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|