2020-01-04 03:28:03 +08:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as util from 'util';
|
|
|
|
import * as rimraf from 'rimraf';
|
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
|
|
|
import {SQLConnection} from '../../../../../src/backend/model/database/sql/SQLConnection';
|
|
|
|
import {Server} from '../../../../../src/backend/server';
|
2020-01-29 01:36:52 +08:00
|
|
|
import {ServerConfig} from '../../../../../src/common/config/private/PrivateConfig';
|
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);
|
|
|
|
|
|
|
|
const rimrafPR = util.promisify(rimraf);
|
|
|
|
describe('SettingsRouter', () => {
|
|
|
|
|
|
|
|
const tempDir = path.join(__dirname, '../../tmp');
|
|
|
|
beforeEach(async () => {
|
|
|
|
await rimrafPR(tempDir);
|
|
|
|
Config.Server.Threading.enabled = false;
|
|
|
|
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
|
|
|
|
Config.Server.Database.dbFolder = tempDir;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await SQLConnection.close();
|
|
|
|
await rimrafPR(tempDir);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('/GET settings', () => {
|
|
|
|
it('it should GET all the books', async () => {
|
2020-01-08 06:31:38 +08:00
|
|
|
Config.Client.authenticationRequired = false;
|
2020-01-29 01:36:52 +08:00
|
|
|
const originalSettings = await Config.original();
|
2020-01-04 03:28:03 +08:00
|
|
|
originalSettings.Server.sessionSecret = null;
|
|
|
|
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-01-29 05:41:17 +08:00
|
|
|
result.body.result.should.deep.equal(JSON.parse(JSON.stringify(originalSettings.toJSON({attachDefaults: true}))));
|
2020-01-04 03:28:03 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|