From 575f3fa9668d15cbdbcf69c554d9d4095f73109f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 24 Jun 2021 14:28:10 +0200 Subject: [PATCH] fix tests --- src/matrix/room/timeline/PowerLevels.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/matrix/room/timeline/PowerLevels.js b/src/matrix/room/timeline/PowerLevels.js index 26e5db1d..d2fb026d 100644 --- a/src/matrix/room/timeline/PowerLevels.js +++ b/src/matrix/room/timeline/PowerLevels.js @@ -114,39 +114,45 @@ export function tests() { return { "redact somebody else event with power level event": assert => { - const pl1 = new PowerLevels({powerLevelEvent: redactPowerLevelEvent, ownUserId: alice}); + const pl1 = new PowerLevels({powerLevelEvent: redactPowerLevelEvent, ownUserId: alice, membership: "join"}); assert.equal(pl1.canRedact, true); - const pl2 = new PowerLevels({powerLevelEvent: redactPowerLevelEvent, ownUserId: bob}); + const pl2 = new PowerLevels({powerLevelEvent: redactPowerLevelEvent, ownUserId: bob, membership: "join"}); assert.equal(pl2.canRedact, false); }, "redact somebody else event with create event": assert => { - const pl1 = new PowerLevels({createEvent, ownUserId: alice}); + const pl1 = new PowerLevels({createEvent, ownUserId: alice, membership: "join"}); assert.equal(pl1.canRedact, true); - const pl2 = new PowerLevels({createEvent, ownUserId: bob}); + const pl2 = new PowerLevels({createEvent, ownUserId: bob, membership: "join"}); assert.equal(pl2.canRedact, false); }, "redact own event": assert => { - const pl = new PowerLevels({ownUserId: alice}); + const pl = new PowerLevels({ownUserId: alice, membership: "join"}); assert.equal(pl.canRedactFromSender(alice), true); assert.equal(pl.canRedactFromSender(bob), false); }, "can send event without power levels": assert => { - const pl = new PowerLevels({createEvent, ownUserId: charly}); + const pl = new PowerLevels({createEvent, ownUserId: charly, membership: "join"}); assert.equal(pl.canSendType("m.room.message"), true); }, "can't send any event below events_default": assert => { - const pl = new PowerLevels({powerLevelEvent: eventsPowerLevelEvent, ownUserId: charly}); + const pl = new PowerLevels({powerLevelEvent: eventsPowerLevelEvent, ownUserId: charly, membership: "join"}); assert.equal(pl.canSendType("m.foo"), false); }, "can't send event below events[type]": assert => { - const pl = new PowerLevels({powerLevelEvent: eventsPowerLevelEvent, ownUserId: bob}); + const pl = new PowerLevels({powerLevelEvent: eventsPowerLevelEvent, ownUserId: bob, membership: "join"}); assert.equal(pl.canSendType("m.foo"), true); assert.equal(pl.canSendType("m.room.message"), false); }, "can send event above or at events[type]": assert => { - const pl = new PowerLevels({powerLevelEvent: eventsPowerLevelEvent, ownUserId: alice}); + const pl = new PowerLevels({powerLevelEvent: eventsPowerLevelEvent, ownUserId: alice, membership: "join"}); assert.equal(pl.canSendType("m.room.message"), true); assert.equal(pl.canSendType("m.room.topic"), true); }, + "can't redact or send in non-joined room'": assert => { + const pl = new PowerLevels({createEvent, ownUserId: alice, membership: "leave"}); + assert.equal(pl.canRedact, false); + assert.equal(pl.canRedactFromSender(alice), false); + assert.equal(pl.canSendType("m.room.message"), false); + }, } }