1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/test/backend/integration/routers/admin/SettingsRouter.ts

66 lines
2.5 KiB
TypeScript
Raw Normal View History

import * as path from 'path';
2021-01-04 17:32:19 +08:00
import * as fs from 'fs';
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';
import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
import {UserRoles} from '../../../../../src/common/entities/UserDTO';
2023-11-13 23:51:25 +08:00
import {ExtensionConfigWrapper} from '../../../../../src/backend/model/extension/ExtensionConfigWrapper';
import {TestHelper} from '../../../../TestHelper';
import {Utils} from '../../../../../src/common/Utils';
import {SQLConnection} from '../../../../../src/backend/model/database/SQLConnection';
process.env.NODE_ENV = 'test';
const chai: any = require('chai');
const chaiHttp = require('chai-http');
const should = chai.should();
chai.use(chaiHttp);
describe('SettingsRouter', () => {
let server: Server;
beforeEach(async () => {
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
2022-12-29 02:12:18 +08:00
Config.Database.type = DatabaseType.sqlite;
Config.Database.dbFolder = TestHelper.TMP_DIR;
2020-12-29 05:08:57 +08:00
ProjectPath.reset();
server = new Server(false);
await server.onStarted.wait();
console.log('done');
await ObjectManagers.getInstance().init();
});
afterEach(async () => {
await server.Stop();
await ObjectManagers.reset();
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
});
describe('/GET settings', () => {
it('it should GET the settings', async () => {
2022-12-29 02:12:18 +08:00
Config.Users.authenticationRequired = false;
Config.Users.unAuthenticatedUserRole = UserRoles.Admin;
const originalSettings = await ExtensionConfigWrapper.original();
console.log('testing');
const result = await chai.request(server.Server)
2022-12-29 02:12:18 +08:00
.get(Config.Server.apiPath + '/settings');
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
}))));
});
});
});