Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Jul 25, 2024
1 parent 4828237 commit 6f27735
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/integration/protectionSettingsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { ProtectionSettingValidationError } from "../../src/protections/Protecti
import { NumberProtectionSetting, StringProtectionSetting, StringListProtectionSetting } from "../../src/protections/ProtectionSettings";
import { newTestUser, noticeListener } from "./clientHelper";
import { matrixClient, mjolnir } from "./mjolnirSetupUtils";
import {MessageIsMedia} from "../../src/protections/MessageIsMedia";

describe("Test: Protection settings", function() {
let client;
let room;
this.beforeEach(async function () {
client = await newTestUser(this.config.homeserverUrl, { name: { contains: "protection-settings" }});
await client.start();
room = await client.createRoom();
await client.joinRoom(room)
})
this.afterEach(async function () {
await client.stop();
Expand Down Expand Up @@ -158,5 +162,31 @@ describe("Test: Protection settings", function() {
"Changed d0sNrt.test to asd2 (was asd1)"
)
});
});
it("Events are checked for new content under media protections", async function() {
this.timeout(20000);
await client.joinRoom(this.config.managementRoom);

await this.mjolnir.protectionManager.registerProtection(new MessageIsMedia());

// send a regular media message to make sure protections are running
await client.sendMessage(room, {msgtype: "m.image", body: ""})
let reply = () => new Promise((resolve, reject) => {
client.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => {
if (event.content.body.includes("Redacting event")) {
resolve(event);
}
}))
});
await reply;

await client.sendMessage(room, {"m.new_content": {msgtype: "m.image", body: ""}, body: "", msgtype: "m.text"})
let reply2 = () => new Promise((resolve, reject) => {
client.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => {
if (event.content.body.includes("Redacting event")) {
resolve(event);
}
}))
});
await reply2;
});
});

0 comments on commit 6f27735

Please sign in to comment.