Update tests not to mock out an ancient server (#12081)

Some of our tests, which mock a `/versions` response, currently mock the
response of a 2-year-old server. This will soon be incompatible with the
JS-SDK. Update the tests in preparation.
pull/28217/head
Richard van der Hoff 2024-01-05 13:24:00 +00:00 committed by GitHub
parent 86017639c2
commit db7f0ba69a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -62,6 +62,9 @@ jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
completeAuthorizationCodeGrant: jest.fn(),
}));
/** The matrix versions our mock server claims to support */
const SERVER_SUPPORTED_MATRIX_VERSIONS = ["v1.1", "v1.5", "v1.6", "v1.8", "v1.9"];
describe("<MatrixChat />", () => {
const userId = "@alice:server.org";
const deviceId = "qwertyui";
@ -69,7 +72,7 @@ describe("<MatrixChat />", () => {
// reused in createClient mock below
const getMockClientMethods = () => ({
...mockClientMethodsUser(userId),
getVersions: jest.fn().mockResolvedValue({ versions: ["v1.1"] }),
getVersions: jest.fn().mockResolvedValue({ versions: SERVER_SUPPORTED_MATRIX_VERSIONS }),
startClient: jest.fn(),
stopClient: jest.fn(),
setCanResetTimelineCallback: jest.fn(),
@ -202,7 +205,7 @@ describe("<MatrixChat />", () => {
mockClient = getMockClientWithEventEmitter(getMockClientMethods());
fetchMock.get("https://test.com/_matrix/client/versions", {
unstable_features: {},
versions: ["v1.1"],
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
});
jest.spyOn(StorageManager, "idbLoad").mockReset();

View File

@ -39,6 +39,9 @@ jest.mock("matrix-js-sdk/src/matrix", () => ({
}));
jest.useFakeTimers();
/** The matrix versions our mock server claims to support */
const SERVER_SUPPORTED_MATRIX_VERSIONS = ["v1.1", "v1.5", "v1.6", "v1.8", "v1.9"];
describe("Registration", function () {
let mockClient!: MockedObject<MatrixClient>;
@ -50,7 +53,7 @@ describe("Registration", function () {
mockClient = getMockClientWithEventEmitter({
registerRequest: jest.fn(),
loginFlows: jest.fn(),
getVersions: jest.fn().mockResolvedValue({ versions: ["v1.1"] }),
getVersions: jest.fn().mockResolvedValue({ versions: SERVER_SUPPORTED_MATRIX_VERSIONS }),
});
mockClient.registerRequest.mockRejectedValueOnce(
new MatrixError(
@ -69,7 +72,7 @@ describe("Registration", function () {
fetchMock.catch(404);
fetchMock.get("https://matrix.org/_matrix/client/versions", {
unstable_features: {},
versions: ["v1.1"],
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
});
mockPlatformPeg({
startSingleSignOn: jest.fn(),
@ -138,7 +141,7 @@ describe("Registration", function () {
fetchMock.get("https://server2/_matrix/client/versions", {
unstable_features: {},
versions: ["v1.1"],
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
});
rerender(getRawComponent("https://server2"));
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

View File

@ -23,6 +23,9 @@ import SdkConfig from "../../../../src/SdkConfig";
import { flushPromises } from "../../../test-utils";
import { ValidatedServerConfig } from "../../../../src/utils/ValidatedServerConfig";
/** The matrix versions our mock server claims to support */
const SERVER_SUPPORTED_MATRIX_VERSIONS = ["v1.1", "v1.5", "v1.6", "v1.8", "v1.9"];
describe("<ServerPickerDialog />", () => {
const defaultServerConfig = {
hsUrl: "https://matrix.org",
@ -112,7 +115,7 @@ describe("<ServerPickerDialog />", () => {
it("should allow user to revert from a custom server to the default", async () => {
fetchMock.get(`https://custom.org/_matrix/client/versions`, {
unstable_features: {},
versions: ["v1.1"],
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
});
const onFinished = jest.fn();
@ -142,7 +145,7 @@ describe("<ServerPickerDialog />", () => {
const homeserver = "https://myhomeserver.site";
fetchMock.get(`${homeserver}/_matrix/client/versions`, {
unstable_features: {},
versions: ["v1.1"],
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
});
const onFinished = jest.fn();
getComponent({ onFinished });
@ -195,7 +198,7 @@ describe("<ServerPickerDialog />", () => {
fetchMock.getOnce(wellKnownUrl, validWellKnown);
fetchMock.getOnce(versionsUrl, {
versions: ["v1.1"],
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
});
fetchMock.getOnce(isWellKnownUrl, {});
const onFinished = jest.fn();
@ -231,7 +234,9 @@ describe("<ServerPickerDialog />", () => {
const wellKnownUrl = `https://${homeserver}/.well-known/matrix/client`;
fetchMock.get(wellKnownUrl, { status: 404 });
// but is otherwise live (happy versions response)
fetchMock.get(`https://${homeserver}/_matrix/client/versions`, { versions: ["v1.1"] });
fetchMock.get(`https://${homeserver}/_matrix/client/versions`, {
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
});
const onFinished = jest.fn();
getComponent({ onFinished });