diff --git a/src/SynapseAdminApis.ts b/src/SynapseAdminApis.ts index 84bcdecd..ceba26f4 100644 --- a/src/SynapseAdminApis.ts +++ b/src/SynapseAdminApis.ts @@ -479,4 +479,14 @@ export class SynapseAdminApis { public async makeRoomAdmin(roomId: string, userId?: string): Promise { return this.client.doRequest("POST", `/_synapse/admin/v1/rooms/${encodeURIComponent(roomId)}/make_room_admin`, {}, { user_id: userId }); } + + /** + * Joins a local user account to a room. + * @param roomId The room to make the user join. + * @param UserId The user to join into the room. + * @returns Resolves when complete. + */ + public async joinUserToRoom(roomId: string, userId: string): Promise { + return this.client.doRequest("POST", `/_synapse/admin/v1/join/${encodeURIComponent(roomId)}`, {}, { user_id: userId }); + } } diff --git a/test/SynapseAdminApisTest.ts b/test/SynapseAdminApisTest.ts index b9d9f5f6..93ed7e18 100644 --- a/test/SynapseAdminApisTest.ts +++ b/test/SynapseAdminApisTest.ts @@ -531,5 +531,22 @@ describe('SynapseAdminApis', () => { await Promise.all([client.makeRoomAdmin(roomId, userId), http.flushAllExpected()]); }); }); + + describe('joinUserToRoom', () => { + it('should call the right endpoint', async () => { + const { client, http, hsUrl } = createTestSynapseAdminClient(); + + const roomId = "!room:example.org"; + const userId = "@alice:example.org"; + + http.when("POST", "/_synapse/admin/v1/join").respond(200, (path, content, req) => { + expect(content).toMatchObject({ user_id: userId }); + expect(path).toEqual(`${hsUrl}/_synapse/admin/v1/join/${encodeURIComponent(roomId)}`); + return {}; + }); + + await Promise.all([client.joinUserToRoom(roomId, userId), http.flushAllExpected()]); + }); + }); }); });