mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 19:22:51 +00:00
refactor: parameterize configureApp function (inject db list)
Reason: easier testing (mocking) and better readability Note: did additional refactoring
This commit is contained in:
committed by
Rainer Killinger
parent
f3b86f0f0d
commit
fe7dd09d7e
@@ -13,14 +13,17 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SCSearchQuery, SCSearchResponse, SCThings, SCUuid} from '@openstapps/core';
|
||||
import {SCConfigFile, SCSearchQuery, SCSearchResponse, SCThings, SCThingType, SCUuid} from '@openstapps/core';
|
||||
import {Express} from 'express';
|
||||
import moment from 'moment';
|
||||
import {configureApp} from '../src/app';
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import {configFile} from '../src/common';
|
||||
import {MailQueue} from '../src/notification/mail-queue';
|
||||
import {Bulk, BulkStorage} from '../src/storage/bulk-storage';
|
||||
import {Database} from '../src/storage/database';
|
||||
import getPort from 'get-port';
|
||||
import {Database} from '../src/storage/database';
|
||||
|
||||
/**
|
||||
* Adds routers and configures an (express) app
|
||||
@@ -29,7 +32,7 @@ import getPort from 'get-port';
|
||||
export async function startApp(): Promise<Express> {
|
||||
const app = express();
|
||||
|
||||
await configureApp(app);
|
||||
await configureApp(app, {elasticsearch: ElasticsearchMock});
|
||||
|
||||
const server = http.createServer(app);
|
||||
|
||||
@@ -42,9 +45,9 @@ export async function startApp(): Promise<Express> {
|
||||
});
|
||||
|
||||
return new Promise(resolve => server.on('listening', () => {
|
||||
app.set(
|
||||
'bulk',
|
||||
bulkStorage,
|
||||
app.set(
|
||||
'bulk',
|
||||
bulkStorageMock,
|
||||
);
|
||||
resolve(app);
|
||||
}));
|
||||
@@ -58,7 +61,7 @@ export class ElasticsearchMock implements Database {
|
||||
private bulk: Bulk | undefined;
|
||||
private storageMock = new Map<string, SCThings>();
|
||||
|
||||
constructor() {
|
||||
constructor(_configFile: SCConfigFile, _mailQueue?: MailQueue) {
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
@@ -98,9 +101,44 @@ export class ElasticsearchMock implements Database {
|
||||
}
|
||||
}
|
||||
|
||||
export const bulkStorage = new BulkStorage(new ElasticsearchMock());
|
||||
export const bulkStorageMock = new BulkStorage(new ElasticsearchMock(configFile));
|
||||
|
||||
export const bulk: Bulk = {
|
||||
expiration: moment().add(3600, 'seconds')
|
||||
.format(),
|
||||
source: 'some_source',
|
||||
state: 'in progress',
|
||||
type: SCThingType.Book,
|
||||
uid: ''
|
||||
};
|
||||
|
||||
export class FooError extends Error {
|
||||
}
|
||||
|
||||
export const DEFAULT_TEST_TIMEOUT = 10000;
|
||||
|
||||
export const TRANSPORT_SEND_RESPONSE = 'Send Response';
|
||||
|
||||
export const getTransport = (verified: boolean) => {
|
||||
return {
|
||||
cc: undefined,
|
||||
from: undefined,
|
||||
recipients: undefined,
|
||||
transportAgent: undefined,
|
||||
verified: undefined,
|
||||
isVerified(): boolean {
|
||||
return verified;
|
||||
},
|
||||
send(_subject: string, _message: string): Promise<string> {
|
||||
return Promise.resolve('');
|
||||
},
|
||||
sendMail(_mail: any): Promise<string> {
|
||||
return Promise.resolve(TRANSPORT_SEND_RESPONSE);
|
||||
},
|
||||
verify(): Promise<boolean> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const index = 'stapps_footype_foosource_foobar';
|
||||
|
||||
Reference in New Issue
Block a user