1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

52 lines
1.9 KiB
TypeScript
Raw Normal View History

import * as path from 'path';
2021-01-04 10:32:19 +01:00
import * as fs from 'fs';
import {Config} from '../../../../../src/common/config/private/Config';
import {SQLConnection} from '../../../../../src/backend/model/database/sql/SQLConnection';
import {Server} from '../../../../../src/backend/server';
import {DatabaseType} from '../../../../../src/common/config/private/PrivateConfig';
2020-12-28 22:08:57 +01:00
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
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 () => {
await fs.promises.rm(tempDir, {recursive: true, force: true});
Config.Server.Threading.enabled = false;
Config.Server.Database.type = DatabaseType.sqlite;
Config.Server.Database.dbFolder = tempDir;
2020-12-28 22:08:57 +01:00
ProjectPath.reset();
});
afterEach(async () => {
await SQLConnection.close();
await fs.promises.rm(tempDir, {recursive: true, force: true});
});
describe('/GET settings', () => {
it('it should GET the settings', async () => {
2020-01-07 23:31:38 +01:00
Config.Client.authenticationRequired = false;
2020-01-28 18:36:52 +01:00
const originalSettings = await Config.original();
originalSettings.Server.sessionSecret = null;
originalSettings.Server.Database.enforcedUsers = 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-02-08 00:02:42 +01:00
result.body.result.Server.Environment.upTime = null;
originalSettings.Server.Environment.upTime = null;
2020-02-04 19:37:47 +01:00
result.body.result.should.deep.equal(JSON.parse(JSON.stringify(originalSettings.toJSON({attachState: true, attachVolatile: true}))));
});
});
});