Skip to content

Commit 7b6c277

Browse files
committed
test: add tests for LocalRoom.isEncrypted
1 parent 94bb6f0 commit 7b6c277

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/unit-tests/models/LocalRoom-test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
9+
import { Direction, EventType, type MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
1010

1111
import { LocalRoom, LocalRoomState, LOCAL_ROOM_ID_PREFIX } from "../../../src/models/LocalRoom";
1212
import { createTestClient } from "../../test-utils";
@@ -79,4 +79,26 @@ describe("LocalRoom", () => {
7979
});
8080
});
8181
});
82+
83+
it("should return false for isEncryptionEnabled with no state", () => {
84+
expect(room.isEncryptionEnabled()).toBe(false);
85+
});
86+
87+
it("should return true for isEncryptionEnabled with an encryption state event", () => {
88+
const encryptionEvent = new MatrixEvent({
89+
type: EventType.RoomEncryption,
90+
state_key: "",
91+
content: {
92+
algorithm: "m.megolm.v1.aes-sha2",
93+
},
94+
sender: "@test:localhost",
95+
room_id: room.roomId,
96+
event_id: "$test:localhost",
97+
});
98+
99+
const roomState = room.getLiveTimeline().getState(Direction.Forward);
100+
roomState?.setStateEvents([encryptionEvent]);
101+
102+
expect(room.isEncryptionEnabled()).toBe(true);
103+
});
82104
});

0 commit comments

Comments
 (0)