mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-06-08 15:21:53 +03:00
* Update src with globalThis * Update spec with globalThis * Replace in more spec/ places * More changes to src/ * Add a linter rule for global * Prettify * lint
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
/*
|
|
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 { MatrixClient, PUSHER_ENABLED } 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",
|
|
fetchFn: httpBackend.fetchFn as typeof globalThis.fetch,
|
|
});
|
|
});
|
|
|
|
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({ [PUSHER_ENABLED.name]: true }),
|
|
mkPusher({ [PUSHER_ENABLED.name]: false }),
|
|
],
|
|
});
|
|
|
|
const promise = client.getPushers();
|
|
|
|
await httpBackend.flushAllExpected();
|
|
await flushPromises();
|
|
|
|
const response = await promise;
|
|
|
|
expect(response.pushers[0][PUSHER_ENABLED.name]).toBe(true);
|
|
expect(response.pushers[1][PUSHER_ENABLED.name]).toBe(true);
|
|
expect(response.pushers[2][PUSHER_ENABLED.name]).toBe(false);
|
|
});
|
|
});
|
|
});
|