diff --git a/src/appservice/AppService.ts b/src/appservice/AppService.ts index c51b536..90f8415 100644 --- a/src/appservice/AppService.ts +++ b/src/appservice/AppService.ts @@ -88,12 +88,13 @@ export class MjolnirAppService { * @param config The parsed configuration file. * @param registrationFilePath A path to their homeserver registration file. */ - public static async run(port: number, config: IConfig, registrationFilePath: string) { + public static async run(port: number, config: IConfig, registrationFilePath: string): Promise { const dataStore = new PgDataStore(config.db.connectionString); await dataStore.init(); const service = await MjolnirAppService.makeMjolnirAppService(config, dataStore, registrationFilePath); // The call to `start` MUST happen last. As it needs the datastore, and the mjolnir manager to be initialized before it can process events from the homeserver. await service.start(port); + return service; } public onUserQuery (queriedUser: MatrixUser) { diff --git a/test/appservice/integration/provisionTest.ts b/test/appservice/integration/provisionTest.ts index 94507a6..8e2765a 100644 --- a/test/appservice/integration/provisionTest.ts +++ b/test/appservice/integration/provisionTest.ts @@ -16,6 +16,7 @@ describe("Test that the app service can provision a mjolnir on invite of the app return this.appservice.close(); } else { console.warn("Missing Appservice in this context, so cannot stop it.") + return Promise.resolve(); // TS7030: Not all code paths return a value. } }); it("A moderator that requests a mjolnir via a matrix invitation will be invited to a new policy and management room", async function (this: Context) { diff --git a/test/appservice/integration/webAPITest.ts b/test/appservice/integration/webAPITest.ts index 2236fe8..2875e69 100644 --- a/test/appservice/integration/webAPITest.ts +++ b/test/appservice/integration/webAPITest.ts @@ -20,6 +20,7 @@ describe("Test that the app service can provision a mjolnir when requested from return this.appservice.close(); } else { console.warn("Missing Appservice in this context, so cannot stop it.") + return Promise.resolve(); // TS7030: Not all code paths return a value. } }); it("A moderator that requests a mjolnir via a matrix invitation will be invited to a new policy and management room", async function (this: Context) { diff --git a/test/appservice/utils/harness.ts b/test/appservice/utils/harness.ts index 03d7950..00ad2ba 100644 --- a/test/appservice/utils/harness.ts +++ b/test/appservice/utils/harness.ts @@ -2,7 +2,6 @@ import path from "path"; import { MjolnirAppService } from "../../../src/appservice/AppService"; import { ensureAliasedRoomExists } from "../../integration/mjolnirSetupUtils"; import { read as configRead, IConfig } from "../../../src/appservice/config/config"; -import { PgDataStore } from "../../../src/appservice/datastore"; import { newTestUser } from "../../integration/clientHelper"; import PolicyList from "../../../src/models/PolicyList"; import { CreateEvent, MatrixClient } from "matrix-bot-sdk"; @@ -15,11 +14,7 @@ export async function setupHarness(): Promise { const config = readTestConfig(); const utilityUser = await newTestUser(config.homeserver.url, { name: { contains: "utility" }}); await ensureAliasedRoomExists(utilityUser, config.accessControlList); - const dataStore = new PgDataStore(config.db.connectionString); - await dataStore.init(); - const appservice = await MjolnirAppService.makeMjolnirAppService(config, dataStore, "mjolnir-registration.yaml"); - await appservice.start(9000); - return appservice; + return await MjolnirAppService.run(9000, config, "mjolnir-registration.yaml"); } export async function isPolicyRoom(user: MatrixClient, roomId: string): Promise { diff --git a/test/appservice/utils/webAPIClient.ts b/test/appservice/utils/webAPIClient.ts index 235a1b8..ef7269b 100644 --- a/test/appservice/utils/webAPIClient.ts +++ b/test/appservice/utils/webAPIClient.ts @@ -21,7 +21,6 @@ export interface CreateMjolnirResponse { export class MjolnirWebAPIClient { private constructor( - private readonly matrixClient: MatrixClient, private readonly openIDToken: string, private readonly baseURL: string, ) { @@ -30,7 +29,7 @@ export class MjolnirWebAPIClient { public static async makeClient(client: MatrixClient, baseUrl: string): Promise { const token = await getOpenIDToken(client); - return new MjolnirWebAPIClient(client, token, baseUrl); + return new MjolnirWebAPIClient(token, baseUrl); } public async createMjolnir(roomToProtectId: string): Promise { diff --git a/tsconfig.json b/tsconfig.json index 2910699..f048822 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,7 +21,7 @@ }, "include": [ "./src/**/*", - "./test/appservice/*", + "./test/appservice/**/*", "./test/integration/manualLaunchScript.ts", "./test/integration/roomMembersTest.ts", "./test/integration/banListTest.ts",