From edde1017e62d07ab0ec06ea8701aecc516e03ef4 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Sun, 31 Jul 2022 01:34:53 +0100 Subject: [PATCH] Add empty bodies to /join, /leave (#249) * Add empty bodies to leave/join * Add tests for empty bodies --- src/MatrixClient.ts | 4 ++-- test/MatrixClientTest.ts | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/MatrixClient.ts b/src/MatrixClient.ts index 2053f0e2..6a04dd8e 100644 --- a/src/MatrixClient.ts +++ b/src/MatrixClient.ts @@ -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']; }); }; @@ -1101,7 +1101,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public leaveRoom(roomId: string): Promise { - return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave"); + return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave", null, {}); } /** diff --git a/test/MatrixClientTest.ts b/test/MatrixClientTest.ts index 8cb4dd4f..c3e7a003 100644 --- a/test/MatrixClientTest.ts +++ b/test/MatrixClientTest.ts @@ -2805,7 +2805,8 @@ describe('MatrixClient', () => { (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 }; }); @@ -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++) { @@ -2845,7 +2847,8 @@ describe('MatrixClient', () => { (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 }; }); @@ -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 }; }); @@ -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 }; }); @@ -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 {}; });