You've already forked pigallery2
mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-07-17 01:32:29 +02:00
Improving integration tests.
This commit is contained in:
@ -36,7 +36,7 @@ export class ExtensionManager implements IObjectManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.router = express.Router();
|
this.router = express.Router();
|
||||||
Server.getInstance().app.use(ExtensionManager.EXTENSION_API_PATH, this.router);
|
Server.instance?.app.use(ExtensionManager.EXTENSION_API_PATH, this.router);
|
||||||
this.loadExtensionsList();
|
this.loadExtensionsList();
|
||||||
await this.initExtensions();
|
await this.initExtensions();
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ export class ExtensionManager implements IObjectManager {
|
|||||||
}
|
}
|
||||||
this.initEvents(); // reset events
|
this.initEvents(); // reset events
|
||||||
await this.cleanUpExtensions();
|
await this.cleanUpExtensions();
|
||||||
Server.getInstance().app.use(ExtensionManager.EXTENSION_API_PATH, express.Router());
|
Server.instance?.app.use(ExtensionManager.EXTENSION_API_PATH, this.router);
|
||||||
this.extObjects = {};
|
this.extObjects = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ export class Server {
|
|||||||
public app: express.Express;
|
public app: express.Express;
|
||||||
private server: HttpServer;
|
private server: HttpServer;
|
||||||
|
|
||||||
static instance: Server = null;
|
public static instance: Server = null;
|
||||||
|
|
||||||
public static getInstance(): Server {
|
public static getInstance(): Server {
|
||||||
if (!this.instance) {
|
if (!this.instance) {
|
||||||
@ -148,18 +148,21 @@ export class Server {
|
|||||||
this.server.on('close', this.onClose);
|
this.server.on('close', this.onClose);
|
||||||
|
|
||||||
// Sigterm handler
|
// Sigterm handler
|
||||||
process.on('SIGTERM', () => {
|
process.removeAllListeners('SIGTERM');
|
||||||
Logger.info(LOG_TAG, 'SIGTERM signal received');
|
process.on('SIGTERM', this.SIGTERM);
|
||||||
this.server.close(() => {
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!listen) {
|
if (!listen) {
|
||||||
this.onStarted.trigger();
|
this.onStarted.trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SIGTERM = () =>{
|
||||||
|
Logger.info(LOG_TAG, 'SIGTERM signal received');
|
||||||
|
this.server.close(() => {
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event listener for HTTP server "error" event.
|
* Event listener for HTTP server "error" event.
|
||||||
*/
|
*/
|
||||||
|
@ -2,11 +2,10 @@
|
|||||||
import {ServerConfig} from './PrivateConfig';
|
import {ServerConfig} from './PrivateConfig';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {ConfigClass, ConfigClassBuilder} from 'typeconfig/node';
|
import {ConfigClass} from 'typeconfig/node';
|
||||||
import {IConfigClass} from 'typeconfig/common';
|
import {IConfigClass} from 'typeconfig/common';
|
||||||
import {PasswordHelper} from '../../../backend/model/PasswordHelper';
|
import {PasswordHelper} from '../../../backend/model/PasswordHelper';
|
||||||
import {TAGS} from '../public/ClientConfig';
|
import {TAGS} from '../public/ClientConfig';
|
||||||
import {NotificationManager} from '../../../backend/model/NotifocationManager';
|
|
||||||
|
|
||||||
declare const process: any;
|
declare const process: any;
|
||||||
const upTime = new Date().toISOString();
|
const upTime = new Date().toISOString();
|
||||||
|
@ -50,7 +50,6 @@ describe('PublicRouter', () => {
|
|||||||
await SQLConnection.close();
|
await SQLConnection.close();
|
||||||
};
|
};
|
||||||
const tearDown = async () => {
|
const tearDown = async () => {
|
||||||
await server.Stop();
|
|
||||||
await ObjectManagers.reset();
|
await ObjectManagers.reset();
|
||||||
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
|
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,7 @@ import {RouteTestingHelper} from './RouteTestingHelper';
|
|||||||
import {QueryParams} from '../../../../src/common/QueryParams';
|
import {QueryParams} from '../../../../src/common/QueryParams';
|
||||||
import {ErrorCodes} from '../../../../src/common/entities/Error';
|
import {ErrorCodes} from '../../../../src/common/entities/Error';
|
||||||
import {DatabaseType} from '../../../../src/common/config/private/PrivateConfig';
|
import {DatabaseType} from '../../../../src/common/config/private/PrivateConfig';
|
||||||
|
import {ProjectPath} from '../../../../src/backend/ProjectPath';
|
||||||
|
|
||||||
|
|
||||||
process.env.NODE_ENV = 'test';
|
process.env.NODE_ENV = 'test';
|
||||||
@ -38,6 +39,7 @@ describe('SharingRouter', () => {
|
|||||||
Config.Sharing.enabled = true;
|
Config.Sharing.enabled = true;
|
||||||
Config.Database.type = DatabaseType.sqlite;
|
Config.Database.type = DatabaseType.sqlite;
|
||||||
Config.Database.dbFolder = tempDir;
|
Config.Database.dbFolder = tempDir;
|
||||||
|
ProjectPath.reset();
|
||||||
|
|
||||||
server = new Server(false);
|
server = new Server(false);
|
||||||
await server.onStarted.wait();
|
await server.onStarted.wait();
|
||||||
@ -47,7 +49,6 @@ describe('SharingRouter', () => {
|
|||||||
await SQLConnection.close();
|
await SQLConnection.close();
|
||||||
};
|
};
|
||||||
const tearDown = async () => {
|
const tearDown = async () => {
|
||||||
await server.Stop();
|
|
||||||
await ObjectManagers.reset();
|
await ObjectManagers.reset();
|
||||||
await fs.promises.rm(tempDir, {recursive: true, force: true});
|
await fs.promises.rm(tempDir, {recursive: true, force: true});
|
||||||
};
|
};
|
||||||
|
@ -39,7 +39,6 @@ describe('UserRouter', () => {
|
|||||||
Config.Database.dbFolder = tempDir;
|
Config.Database.dbFolder = tempDir;
|
||||||
ProjectPath.reset();
|
ProjectPath.reset();
|
||||||
|
|
||||||
|
|
||||||
server = new Server(false);
|
server = new Server(false);
|
||||||
await server.onStarted.wait();
|
await server.onStarted.wait();
|
||||||
await ObjectManagers.getInstance().init();
|
await ObjectManagers.getInstance().init();
|
||||||
@ -47,7 +46,6 @@ describe('UserRouter', () => {
|
|||||||
await SQLConnection.close();
|
await SQLConnection.close();
|
||||||
};
|
};
|
||||||
const tearDown = async () => {
|
const tearDown = async () => {
|
||||||
await server.Stop();
|
|
||||||
await ObjectManagers.reset();
|
await ObjectManagers.reset();
|
||||||
await fs.promises.rm(tempDir, {recursive: true, force: true});
|
await fs.promises.rm(tempDir, {recursive: true, force: true});
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import * as path from 'path';
|
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import {Config} from '../../../../../src/common/config/private/Config';
|
import {Config} from '../../../../../src/common/config/private/Config';
|
||||||
import {Server} from '../../../../../src/backend/server';
|
import {Server} from '../../../../../src/backend/server';
|
||||||
@ -9,8 +8,6 @@ import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
|||||||
import {UserRoles} from '../../../../../src/common/entities/UserDTO';
|
import {UserRoles} from '../../../../../src/common/entities/UserDTO';
|
||||||
import {ExtensionConfigWrapper} from '../../../../../src/backend/model/extension/ExtensionConfigWrapper';
|
import {ExtensionConfigWrapper} from '../../../../../src/backend/model/extension/ExtensionConfigWrapper';
|
||||||
import {TestHelper} from '../../../../TestHelper';
|
import {TestHelper} from '../../../../TestHelper';
|
||||||
import {Utils} from '../../../../../src/common/Utils';
|
|
||||||
import {SQLConnection} from '../../../../../src/backend/model/database/SQLConnection';
|
|
||||||
|
|
||||||
process.env.NODE_ENV = 'test';
|
process.env.NODE_ENV = 'test';
|
||||||
const chai: any = require('chai');
|
const chai: any = require('chai');
|
||||||
@ -29,13 +26,11 @@ describe('SettingsRouter', () => {
|
|||||||
|
|
||||||
server = new Server(false);
|
server = new Server(false);
|
||||||
await server.onStarted.wait();
|
await server.onStarted.wait();
|
||||||
console.log('done');
|
|
||||||
await ObjectManagers.getInstance().init();
|
await ObjectManagers.getInstance().init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await server.Stop();
|
|
||||||
await ObjectManagers.reset();
|
await ObjectManagers.reset();
|
||||||
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
|
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
|
||||||
});
|
});
|
||||||
@ -44,9 +39,8 @@ describe('SettingsRouter', () => {
|
|||||||
it('it should GET the settings', async () => {
|
it('it should GET the settings', async () => {
|
||||||
Config.Users.authenticationRequired = false;
|
Config.Users.authenticationRequired = false;
|
||||||
Config.Users.unAuthenticatedUserRole = UserRoles.Admin;
|
Config.Users.unAuthenticatedUserRole = UserRoles.Admin;
|
||||||
const originalSettings = await ExtensionConfigWrapper.original();
|
const originalSettings = await ExtensionConfigWrapper.original();
|
||||||
|
|
||||||
console.log('testing');
|
|
||||||
const result = await chai.request(server.Server)
|
const result = await chai.request(server.Server)
|
||||||
.get(Config.Server.apiPath + '/settings');
|
.get(Config.Server.apiPath + '/settings');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user