From 3a578473b415b929501023624b1c3bc815a66b70 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Sun, 3 Mar 2024 01:06:34 -0500 Subject: [PATCH 1/2] Support admin join API Signed-off-by: Gary Kim --- src/SynapseAdminApis.ts | 10 ++++++++++ test/SynapseAdminApisTest.ts | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) 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..9f2ed258 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('addUserToRoom', () => { + 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()]); + }); + }); }); }); From 1c9f30e6131180c78d6c433a190ccf7c3f3ed050 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Sun, 3 Mar 2024 05:50:29 -0500 Subject: [PATCH 2/2] Match test name to function name Signed-off-by: Gary Kim --- test/SynapseAdminApisTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/SynapseAdminApisTest.ts b/test/SynapseAdminApisTest.ts index 9f2ed258..93ed7e18 100644 --- a/test/SynapseAdminApisTest.ts +++ b/test/SynapseAdminApisTest.ts @@ -532,7 +532,7 @@ describe('SynapseAdminApis', () => { }); }); - describe('addUserToRoom', () => { + describe('joinUserToRoom', () => { it('should call the right endpoint', async () => { const { client, http, hsUrl } = createTestSynapseAdminClient();