mjolnir/test/integration/acceptInvitesFromSpaceTest.ts
Gnuxie 9bcb0b7a59
Replace acceptInvitesFromGroup with acceptInvitesFromSpace. (#338)
Replace acceptInvitesFromGroup with acceptInvitesFromSpace.

https://github.com/matrix-org/mjolnir/issues/125
https://github.com/matrix-org/mjolnir/issues/99

acceptInvitesFromGroup was implemented with an experimental api
that was a precursor to spaces which was refereed to
as either communities or groups.
Support for communities/groups ended in Synapse 1.61.0
https://github.com/matrix-org/synapse/releases/tag/v1.61.0.

To test we just edit the config dynamically which changes how the join room listener functions
though idk, shouldn't we have just made a new mjolnir instance
for this test, or changed the config before the test started somehow?


Co-authored-by: jesopo <github@lolnerd.net>
2022-08-17 10:05:23 +01:00

49 lines
1.7 KiB
TypeScript

import { MatrixClient } from "matrix-bot-sdk";
import { Mjolnir } from "../../src/Mjolnir"
import { newTestUser } from "./clientHelper";
describe("Test: Accept Invites From Space", function() {
let client: MatrixClient|undefined;
this.beforeEach(async function () {
client = await newTestUser(this.config.homeserverUrl, { name: { contains: "spacee" }});
await client.start();
})
this.afterEach(async function () {
await client.stop();
})
it("Mjolnir should accept an invite from a user in a nominated Space", async function() {
this.timeout(20000);
const mjolnir: Mjolnir = this.mjolnir!;
const mjolnirUserId = await mjolnir.client.getUserId();
const space = await client.createSpace({
name: "mjolnir space invite test",
invites: [mjolnirUserId],
isPublic: false
});
await this.mjolnir.client.joinRoom(space.roomId);
// we're mutating a static object, which may affect other tests :(
mjolnir.config.autojoinOnlyIfManager = false;
mjolnir.config.acceptInvitesFromSpace = space.roomId;
const promise = new Promise(async resolve => {
const newRoomId = await client.createRoom({ invite: [mjolnirUserId] });
client.on("room.event", (roomId, event) => {
if (
roomId === newRoomId
&& event.type === "m.room.member"
&& event.sender === mjolnirUserId
&& event.content?.membership === "join"
) {
resolve(null);
}
});
});
await promise;
});
});