diff --git a/test/integration/standardConsequenceTest.ts b/test/integration/standardConsequenceTest.ts index eea8d636..2309a9e9 100644 --- a/test/integration/standardConsequenceTest.ts +++ b/test/integration/standardConsequenceTest.ts @@ -1,14 +1,12 @@ -import { strict as assert } from "assert"; - import { Mjolnir } from "../../src/Mjolnir"; import { Protection } from "../../src/protections/IProtection"; -import { newTestUser, noticeListener } from "./clientHelper"; -import { matrixClient, mjolnir } from "./mjolnirSetupUtils"; +import { newTestUser } from "./clientHelper"; import { ConsequenceBan, ConsequenceRedact } from "../../src/protections/consequence"; +import { MatrixClient } from "@vector-im/matrix-bot-sdk"; describe("Test: standard consequences", function () { - let badUser; - let goodUser; + let badUser: MatrixClient; + let goodUser: MatrixClient; this.beforeEach(async function () { badUser = await newTestUser(this.config.homeserverUrl, { name: { contains: "standard-consequences" } }); goodUser = await newTestUser(this.config.homeserverUrl, { name: { contains: "standard-consequences" } }); @@ -32,6 +30,7 @@ describe("Test: standard consequences", function () { name = "JY2TPN"; description = "A test protection"; settings = {}; + // @ts-ignore handleEvent = async (mjolnir: Mjolnir, roomId: string, event: any) => { if (event.content.body === "ngmWkF") { return [new ConsequenceRedact("asd")]; @@ -43,7 +42,7 @@ describe("Test: standard consequences", function () { let reply: Promise = new Promise(async (resolve, reject) => { const messageId = await badUser.sendMessage(protectedRoomId, { msgtype: "m.text", body: "ngmWkF" }); - let redaction; + let redaction: any; badUser.on("room.event", (roomId, event) => { if (roomId === protectedRoomId && event?.type === "m.room.redaction" && event.redacts === messageId) { redaction = event; @@ -59,13 +58,12 @@ describe("Test: standard consequences", function () { }); }); - const [eventRedact, eventMessage] = await reply; + await reply; }); it("Mjolnir applies a standard consequence ban", async function () { this.timeout(20000); let protectedRoomId = await this.mjolnir.client.createRoom({ invite: [await badUser.getUserId()] }); - await badUser.joinRoom(this.mjolnir.managementRoomId); await badUser.joinRoom(protectedRoomId); await this.mjolnir.addProtectedRoom(protectedRoomId); @@ -74,6 +72,7 @@ describe("Test: standard consequences", function () { name = "0LxMTy"; description = "A test protection"; settings = {}; + // @ts-ignore handleEvent = async (mjolnir: Mjolnir, roomId: string, event: any) => { if (event.content.body === "7Uga3d") { return [new ConsequenceBan("asd")]; @@ -84,19 +83,20 @@ describe("Test: standard consequences", function () { await this.mjolnir.protectionManager.enableProtection("0LxMTy"); let reply: Promise = new Promise(async (resolve, reject) => { - const messageId = await badUser.sendMessage(protectedRoomId, { msgtype: "m.text", body: "7Uga3d" }); - let ban; + await badUser.sendMessage(protectedRoomId, { msgtype: "m.text", body: "7Uga3d" }); + let ban: any; + const badId = await badUser.getUserId(); badUser.on("room.leave", (roomId, event) => { if ( roomId === protectedRoomId && event?.type === "m.room.member" && event.content?.membership === "ban" && - event.state_key === badUser.userId + event.state_key === badId ) { ban = event; } }); - badUser.on("room.event", (roomId, event) => { + this.mjolnir.client.on("room.event", (roomId: any, event: any) => { if ( roomId === this.mjolnir.managementRoomId && event?.type === "m.room.message" && @@ -108,13 +108,15 @@ describe("Test: standard consequences", function () { }); }); - const [eventBan, eventMessage] = await reply; + await reply; }); it("Mjolnir doesn't ban a good user", async function () { this.timeout(20000); + const badId = await badUser.getUserId(); + const goodId = await goodUser.getUserId(); let protectedRoomId = await this.mjolnir.client.createRoom({ - invite: [await goodUser.getUserId(), await badUser.getUserId()], + invite: [goodId, badId], }); await badUser.joinRoom(protectedRoomId); await goodUser.joinRoom(protectedRoomId); @@ -125,6 +127,7 @@ describe("Test: standard consequences", function () { name = "95B1Cr"; description = "A test protection"; settings = {}; + // @ts-ignore handleEvent = async (mjolnir: Mjolnir, roomId: string, event: any) => { if (event.content.body === "8HUnwb") { return [new ConsequenceBan("asd")]; @@ -135,21 +138,21 @@ describe("Test: standard consequences", function () { await this.mjolnir.protectionManager.enableProtection("95B1Cr"); let reply = new Promise(async (resolve, reject) => { - this.mjolnir.client.on("room.message", async (roomId, event) => { + this.mjolnir.client.on("room.message", async (roomId: string, event: any) => { if (event?.content?.body === "SUwvFT") { await badUser.sendMessage(protectedRoomId, { msgtype: "m.text", body: "8HUnwb" }); } }); - this.mjolnir.client.on("room.event", (roomId, event) => { + this.mjolnir.client.on("room.event", (roomId: string, event: any) => { if ( roomId === protectedRoomId && event?.type === "m.room.member" && event.content?.membership === "ban" ) { - if (event.state_key === goodUser.userId) { + if (event.state_key === goodId) { reject("good user has been banned"); - } else if (event.state_key === badUser.userId) { + } else if (event.state_key === badId) { resolve(null); } }