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/28788/head^2
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(), 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 />", () => { describe("<MatrixChat />", () => {
const userId = "@alice:server.org"; const userId = "@alice:server.org";
const deviceId = "qwertyui"; const deviceId = "qwertyui";
@ -69,7 +72,7 @@ describe("<MatrixChat />", () => {
// reused in createClient mock below // reused in createClient mock below
const getMockClientMethods = () => ({ const getMockClientMethods = () => ({
...mockClientMethodsUser(userId), ...mockClientMethodsUser(userId),
getVersions: jest.fn().mockResolvedValue({ versions: ["v1.1"] }), getVersions: jest.fn().mockResolvedValue({ versions: SERVER_SUPPORTED_MATRIX_VERSIONS }),
startClient: jest.fn(), startClient: jest.fn(),
stopClient: jest.fn(), stopClient: jest.fn(),
setCanResetTimelineCallback: jest.fn(), setCanResetTimelineCallback: jest.fn(),
@ -202,7 +205,7 @@ describe("<MatrixChat />", () => {
mockClient = getMockClientWithEventEmitter(getMockClientMethods()); mockClient = getMockClientWithEventEmitter(getMockClientMethods());
fetchMock.get("https://test.com/_matrix/client/versions", { fetchMock.get("https://test.com/_matrix/client/versions", {
unstable_features: {}, unstable_features: {},
versions: ["v1.1"], versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
}); });
jest.spyOn(StorageManager, "idbLoad").mockReset(); jest.spyOn(StorageManager, "idbLoad").mockReset();

View File

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

View File

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