2020-01-03 21:28:03 +02:00
|
|
|
import * as path from 'path';
|
2021-01-04 11:32:19 +02:00
|
|
|
import * as fs from 'fs';
|
2020-01-03 21:28:03 +02:00
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
|
|
|
import {SQLConnection} from '../../../../../src/backend/model/database/sql/SQLConnection';
|
|
|
|
import {Server} from '../../../../../src/backend/server';
|
2021-04-18 15:48:35 +02:00
|
|
|
import {DatabaseType, ServerConfig} from '../../../../../src/common/config/private/PrivateConfig';
|
2020-12-28 23:08:57 +02:00
|
|
|
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
|
2020-01-03 21:28:03 +02: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 () => {
|
2022-01-14 17:27:08 +02:00
|
|
|
await fs.promises.rm(tempDir, {recursive: true});
|
2020-01-03 21:28:03 +02:00
|
|
|
Config.Server.Threading.enabled = false;
|
2021-04-18 15:48:35 +02:00
|
|
|
Config.Server.Database.type = DatabaseType.sqlite;
|
2020-01-03 21:28:03 +02:00
|
|
|
Config.Server.Database.dbFolder = tempDir;
|
2020-12-28 23:08:57 +02:00
|
|
|
ProjectPath.reset();
|
2020-01-03 21:28:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await SQLConnection.close();
|
2022-01-14 17:27:08 +02:00
|
|
|
await fs.promises.rm(tempDir, {recursive: true});
|
2020-01-03 21:28:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('/GET settings', () => {
|
2021-05-11 15:57:36 +02:00
|
|
|
it('it should GET the settings', async () => {
|
2020-01-08 00:31:38 +02:00
|
|
|
Config.Client.authenticationRequired = false;
|
2020-01-28 19:36:52 +02:00
|
|
|
const originalSettings = await Config.original();
|
2020-01-03 21:28:03 +02:00
|
|
|
originalSettings.Server.sessionSecret = null;
|
2022-01-14 12:02:17 +02:00
|
|
|
originalSettings.Server.Database.enforcedUsers = null;
|
2020-01-03 21:28:03 +02:00
|
|
|
const srv = new Server();
|
|
|
|
await srv.onStarted.wait();
|
|
|
|
const result = await chai.request(srv.App)
|
|
|
|
.get('/api/settings');
|
|
|
|
|
|
|
|
result.res.should.have.status(200);
|
|
|
|
result.body.should.be.a('object');
|
|
|
|
should.equal(result.body.error, null);
|
2020-02-08 01:02:42 +02:00
|
|
|
result.body.result.Server.Environment.upTime = null;
|
|
|
|
originalSettings.Server.Environment.upTime = null;
|
2020-02-04 20:37:47 +02:00
|
|
|
result.body.result.should.deep.equal(JSON.parse(JSON.stringify(originalSettings.toJSON({attachState: true, attachVolatile: true}))));
|
2020-01-03 21:28:03 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|