-
-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support to remotely toggle push notifications
Implements MSC3881, matrix-org/matrix-spec-proposals#3881 Epic https://element-io.atlassian.net/browse/PSG-595 Fixes partially https://element-io.atlassian.net/browse/PSG-707
- Loading branch information
Germain Souquet
committed
Sep 21, 2022
1 parent
7e24cb6
commit 37971d4
Showing
4 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import MockHttpBackend from 'matrix-mock-request'; | ||
|
||
import { IHttpOpts, MatrixClient } from "../../src/matrix"; | ||
import { mkPusher } from '../test-utils/test-utils'; | ||
|
||
const realSetTimeout = setTimeout; | ||
function flushPromises() { | ||
return new Promise(r => { | ||
realSetTimeout(r, 1); | ||
}); | ||
} | ||
|
||
let client: MatrixClient; | ||
let httpBackend: MockHttpBackend; | ||
|
||
describe("Pushers", () => { | ||
beforeEach(() => { | ||
httpBackend = new MockHttpBackend(); | ||
client = new MatrixClient({ | ||
baseUrl: "https://my.home.server", | ||
accessToken: "my.access.token", | ||
request: httpBackend.requestFn as unknown as IHttpOpts["request"], | ||
}); | ||
}); | ||
|
||
describe("supports remotely toggling push notifications", () => { | ||
it("migration support when connecting to a legacy homeserver", async () => { | ||
httpBackend.when("GET", "/_matrix/client/versions").respond(200, { | ||
unstable_features: { | ||
"org.matrix.msc3881": false, | ||
}, | ||
}); | ||
httpBackend.when("GET", "/pushers").respond(200, { | ||
pushers: [ | ||
mkPusher(), | ||
mkPusher({ enabled: true }), | ||
mkPusher({ enabled: false }), | ||
], | ||
}); | ||
|
||
const promise = client.getPushers(); | ||
|
||
await httpBackend.flushAllExpected(); | ||
await flushPromises(); | ||
|
||
const response = await promise; | ||
|
||
expect(response.pushers[0].enabled).toBe(true); | ||
expect(response.pushers[1].enabled).toBe(true); | ||
expect(response.pushers[2].enabled).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters