-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add faulty test for the autoleave rooms mixin
* Unable to complete due to lack of knowledge Signed-off-by: Zac McKenzie <zachary.mckenzie@gmail.com>
- Loading branch information
Zac McKenzie
committed
Jan 16, 2024
1 parent
a6b2168
commit 0d09316
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as simple from "simple-mock"; | ||
|
||
import { AutoleaveRoomsMixin } from "../../src"; | ||
import { createTestClient } from "../TestUtils"; | ||
|
||
describe("AutoleaveRoomsMixin", () => { | ||
it("shouldn't leave rooms multiple members", async () => { | ||
const { client } = createTestClient(); | ||
AutoleaveRoomsMixin.setupOnClient(client); | ||
|
||
const roomId = "!test:example.org"; | ||
let members = [ | ||
"@this:example.org", | ||
"@alice:example.org", | ||
"@bob:example.org", | ||
]; | ||
|
||
const getJoinedRoomMembersSpy = simple | ||
.mock(client, "getJoinedRoomMembers") | ||
.callFn((rid) => { | ||
expect(rid).toEqual(roomId); | ||
return members; | ||
}); | ||
const leaveSpy = simple.mock(client, "leaveRoom"); | ||
const forgetSpy = simple.mock(client, "forgetRoom"); | ||
|
||
client.emit("room.event", roomId, { | ||
type: "m.room.member", | ||
content: { membership: "leave" }, | ||
}); | ||
expect(getJoinedRoomMembersSpy.callCount).toBe(1); | ||
// Since the AutoleaveRoomsMixin room.event handler is asyncronous, these functions don't get called syncronously | ||
// Which means we must somehow await the handler's completion before executing the following tests, but I'm not sure how to do that | ||
// expect(leaveSpy.callCount).toBe(0); | ||
// expect(forgetSpy.callCount).toBe(0); | ||
}); | ||
|
||
it("should leave rooms with one or no members", async () => { | ||
const { client } = createTestClient(); | ||
AutoleaveRoomsMixin.setupOnClient(client); | ||
|
||
const roomId = "!test:example.org"; | ||
let members = ["@this:example.org"]; | ||
|
||
const getJoinedRoomMembersSpy = simple | ||
.mock(client, "getJoinedRoomMembers") | ||
.callFn((rid) => { | ||
expect(rid).toEqual(roomId); | ||
return members; | ||
}); | ||
const leaveSpy = simple.mock(client, "leaveRoom"); | ||
const forgetSpy = simple.mock(client, "forgetRoom"); | ||
|
||
client.emit("room.event", roomId, { | ||
type: "m.room.member", | ||
content: { membership: "leave" }, | ||
}); | ||
expect(getJoinedRoomMembersSpy.callCount).toBe(1); | ||
// See comments above (lines 41-42) | ||
// expect(leaveSpy.callCount).toBe(1); | ||
// expect(forgetSpy.callCount).toBe(1); | ||
}); | ||
}); |