Skip to content

Commit

Permalink
Support admin join API
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Kim <gary@garykim.dev>
  • Loading branch information
gary-kim committed Mar 3, 2024
1 parent 6174c38 commit 3a57847
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/SynapseAdminApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,14 @@ export class SynapseAdminApis {
public async makeRoomAdmin(roomId: string, userId?: string): Promise<void> {
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<void> {
return this.client.doRequest("POST", `/_synapse/admin/v1/join/${encodeURIComponent(roomId)}`, {}, { user_id: userId });
}
}
17 changes: 17 additions & 0 deletions test/SynapseAdminApisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
});
});
});
});

0 comments on commit 3a57847

Please sign in to comment.