Skip to content

Commit

Permalink
Add empty bodies to /join, /leave (#249)
Browse files Browse the repository at this point in the history
* Add empty bodies to leave/join

* Add tests for empty bodies
  • Loading branch information
Half-Shot authored Jul 31, 2022
1 parent 13ce618 commit edde101
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/MatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ export class MatrixClient extends EventEmitter {
targetIdOrAlias = encodeURIComponent(targetIdOrAlias);
const qs = {};
if (viaServers.length > 0) qs['server_name'] = viaServers;
return this.doRequest("POST", "/_matrix/client/v3/join/" + targetIdOrAlias, qs).then(response => {
return this.doRequest("POST", "/_matrix/client/v3/join/" + targetIdOrAlias, qs, {}).then(response => {
return response['room_id'];
});
};
Expand Down Expand Up @@ -1101,7 +1101,7 @@ export class MatrixClient extends EventEmitter {
*/
@timedMatrixClientFunctionCall()
public leaveRoom(roomId: string): Promise<any> {
return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave");
return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave", null, {});
}

/**
Expand Down
16 changes: 11 additions & 5 deletions test/MatrixClientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2805,7 +2805,8 @@ describe('MatrixClient', () => {
(<any>client).userId = "@joins:example.org"; // avoid /whoami lookup

// noinspection TypeScriptValidateJSTypes
http.when("POST", "/_matrix/client/v3/join").respond(200, (path) => {
http.when("POST", "/_matrix/client/v3/join").respond(200, (path, content) => {
expect(content).toEqual({});
expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomId)}`);
return { room_id: roomId };
});
Expand All @@ -2824,6 +2825,7 @@ describe('MatrixClient', () => {

// noinspection TypeScriptValidateJSTypes
http.when("POST", "/_matrix/client/v3/join").respond(200, (path, content, req) => {
expect(content).toEqual({});
expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomId)}`);
expect(req.queryParams['server_name'].length).toEqual(serverNames.length);
for (let i = 0; i < serverNames.length; i++) {
Expand All @@ -2845,7 +2847,8 @@ describe('MatrixClient', () => {
(<any>client).userId = "@joins:example.org"; // avoid /whoami lookup

// noinspection TypeScriptValidateJSTypes
http.when("POST", "/_matrix/client/v3/join").respond(200, (path) => {
http.when("POST", "/_matrix/client/v3/join").respond(200, (path, content) => {
expect(content).toEqual({});
expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomAlias)}`);
return { room_id: roomId };
});
Expand Down Expand Up @@ -2873,7 +2876,8 @@ describe('MatrixClient', () => {
const strategySpy = simple.mock(strategy, "joinRoom").callOriginal();

// noinspection TypeScriptValidateJSTypes
http.when("POST", "/_matrix/client/v3/join").respond(200, (path) => {
http.when("POST", "/_matrix/client/v3/join").respond(200, (path, content) => {
expect(content).toEqual({});
expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomId)}`);
return { room_id: roomId };
});
Expand Down Expand Up @@ -2903,7 +2907,8 @@ describe('MatrixClient', () => {
const strategySpy = simple.mock(strategy, "joinRoom").callOriginal();

// noinspection TypeScriptValidateJSTypes
http.when("POST", "/_matrix/client/v3/join").respond(200, (path) => {
http.when("POST", "/_matrix/client/v3/join").respond(200, (path, content) => {
expect(content).toEqual({});
expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomId)}`);
return { room_id: roomId };
});
Expand Down Expand Up @@ -3103,7 +3108,8 @@ describe('MatrixClient', () => {
const roomId = "!testing:example.org";

// noinspection TypeScriptValidateJSTypes
http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path) => {
http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path, content) => {
expect(content).toEqual({});
expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/leave`);
return {};
});
Expand Down

0 comments on commit edde101

Please sign in to comment.