From 71e763263e4a313e5138959c7b6de5eaaf466988 Mon Sep 17 00:00:00 2001 From: Kerry Date: Fri, 28 Apr 2023 09:49:35 +1200 Subject: [PATCH] add client method to remove pusher (#3324) * add client method to remove pusher * remove unused type --- spec/unit/matrix-client.spec.ts | 39 +++++++++++++++++++++++++++++++++ src/client.ts | 17 ++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index ddd95355ad7..635cd2ee5cd 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -2909,4 +2909,43 @@ describe("MatrixClient", function () { }); }); }); + + describe("pushers", () => { + const pusher = { + app_id: "test", + app_display_name: "Test App", + data: {}, + device_display_name: "test device", + kind: "http", + lang: "en-NZ", + pushkey: "1234", + }; + + beforeEach(() => { + makeClient(); + const response: HttpLookup = { + method: Method.Post, + path: "/pushers/set", + data: {}, + }; + httpLookups = [response]; + jest.spyOn(client.http, "authedRequest").mockClear(); + }); + + it("should make correct request to set pusher", async () => { + const result = await client.setPusher(pusher); + expect(client.http.authedRequest).toHaveBeenCalledWith(Method.Post, "/pushers/set", undefined, pusher); + expect(result).toEqual({}); + }); + + it("should make correct request to remove pusher", async () => { + const result = await client.removePusher(pusher.pushkey, pusher.app_id); + expect(client.http.authedRequest).toHaveBeenCalledWith(Method.Post, "/pushers/set", undefined, { + pushkey: pusher.pushkey, + app_id: pusher.app_id, + kind: null, + }); + expect(result).toEqual({}); + }); + }); }); diff --git a/src/client.ts b/src/client.ts index c545c2bbd49..d02fa74fdc6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8627,6 +8627,23 @@ export class MatrixClient extends TypedEventEmitter { + const path = "/pushers/set"; + const body = { + pushkey: pushKey, + app_id: appId, + kind: null, // marks pusher for removal + }; + return this.http.authedRequest(Method.Post, path, undefined, body); + } + /** * Persists local notification settings * @returns Promise which resolves: an empty object