You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
1 year ago
|
import TheApp from "../app";
|
||
|
import { mainRouter } from "../routes";
|
||
|
import _locreq from "locreq";
|
||
|
|
||
|
const locreq = _locreq(__dirname);
|
||
|
import Sealious, { SMTPMailer } from "sealious";
|
||
|
import { TestUtils } from "sealious";
|
||
|
|
||
|
export async function withProdApp(
|
||
|
callback: (args: {
|
||
|
app: TheApp;
|
||
|
base_url: string;
|
||
|
rest_api: TestUtils.MockRestApi;
|
||
|
mail_api: TestUtils.MailcatcherAPI;
|
||
|
}) => Promise<void>
|
||
|
) {
|
||
|
const app = new TheApp();
|
||
|
const port = 9999;
|
||
|
|
||
|
app.config["www-server"].port = port;
|
||
|
app.config.datastore_mongo = {
|
||
|
host: "db",
|
||
|
port: 27017,
|
||
|
db_name: "sealious-app-test",
|
||
|
};
|
||
|
app.config.logger.level = <const>"none";
|
||
|
app.mailer = new SMTPMailer({
|
||
|
host: "mailcatcher",
|
||
|
port: 1025,
|
||
|
user: "any",
|
||
|
password: "any",
|
||
|
});
|
||
|
|
||
|
await app.start();
|
||
|
mainRouter(app.HTTPServer.router);
|
||
|
|
||
|
app.HTTPServer.addStaticRoute("/", locreq.resolve("public"));
|
||
|
|
||
|
const base_url = `http://127.0.0.1:${port}`;
|
||
|
const mail_api = new TestUtils.MailcatcherAPI("http://mailcatcher:1080", app);
|
||
|
await mail_api.deleteAllInstanceEmails();
|
||
|
|
||
|
async function stop() {
|
||
|
await app.removeAllData();
|
||
|
await app.stop();
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
await callback({
|
||
|
app,
|
||
|
base_url,
|
||
|
rest_api: new TestUtils.MockRestApi(base_url),
|
||
|
mail_api,
|
||
|
});
|
||
|
await stop();
|
||
|
} catch (e) {
|
||
|
await stop();
|
||
|
console.error(e);
|
||
|
throw e;
|
||
|
}
|
||
|
}
|