Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit db7f0ba

Browse files
authored
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.
1 parent 8601763 commit db7f0ba

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

test/components/structures/MatrixChat-test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@ jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
6262
completeAuthorizationCodeGrant: jest.fn(),
6363
}));
6464

65+
/** The matrix versions our mock server claims to support */
66+
const SERVER_SUPPORTED_MATRIX_VERSIONS = ["v1.1", "v1.5", "v1.6", "v1.8", "v1.9"];
67+
6568
describe("<MatrixChat />", () => {
6669
const userId = "@alice:server.org";
6770
const deviceId = "qwertyui";
6871
const accessToken = "abc123";
6972
// reused in createClient mock below
7073
const getMockClientMethods = () => ({
7174
...mockClientMethodsUser(userId),
72-
getVersions: jest.fn().mockResolvedValue({ versions: ["v1.1"] }),
75+
getVersions: jest.fn().mockResolvedValue({ versions: SERVER_SUPPORTED_MATRIX_VERSIONS }),
7376
startClient: jest.fn(),
7477
stopClient: jest.fn(),
7578
setCanResetTimelineCallback: jest.fn(),
@@ -202,7 +205,7 @@ describe("<MatrixChat />", () => {
202205
mockClient = getMockClientWithEventEmitter(getMockClientMethods());
203206
fetchMock.get("https://test.com/_matrix/client/versions", {
204207
unstable_features: {},
205-
versions: ["v1.1"],
208+
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
206209
});
207210

208211
jest.spyOn(StorageManager, "idbLoad").mockReset();

test/components/structures/auth/Registration-test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jest.mock("matrix-js-sdk/src/matrix", () => ({
3939
}));
4040
jest.useFakeTimers();
4141

42+
/** The matrix versions our mock server claims to support */
43+
const SERVER_SUPPORTED_MATRIX_VERSIONS = ["v1.1", "v1.5", "v1.6", "v1.8", "v1.9"];
44+
4245
describe("Registration", function () {
4346
let mockClient!: MockedObject<MatrixClient>;
4447

@@ -50,7 +53,7 @@ describe("Registration", function () {
5053
mockClient = getMockClientWithEventEmitter({
5154
registerRequest: jest.fn(),
5255
loginFlows: jest.fn(),
53-
getVersions: jest.fn().mockResolvedValue({ versions: ["v1.1"] }),
56+
getVersions: jest.fn().mockResolvedValue({ versions: SERVER_SUPPORTED_MATRIX_VERSIONS }),
5457
});
5558
mockClient.registerRequest.mockRejectedValueOnce(
5659
new MatrixError(
@@ -69,7 +72,7 @@ describe("Registration", function () {
6972
fetchMock.catch(404);
7073
fetchMock.get("https://matrix.org/_matrix/client/versions", {
7174
unstable_features: {},
72-
versions: ["v1.1"],
75+
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
7376
});
7477
mockPlatformPeg({
7578
startSingleSignOn: jest.fn(),
@@ -138,7 +141,7 @@ describe("Registration", function () {
138141

139142
fetchMock.get("https://server2/_matrix/client/versions", {
140143
unstable_features: {},
141-
versions: ["v1.1"],
144+
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
142145
});
143146
rerender(getRawComponent("https://server2"));
144147
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

test/components/views/dialogs/ServerPickerDialog-test.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import SdkConfig from "../../../../src/SdkConfig";
2323
import { flushPromises } from "../../../test-utils";
2424
import { ValidatedServerConfig } from "../../../../src/utils/ValidatedServerConfig";
2525

26+
/** The matrix versions our mock server claims to support */
27+
const SERVER_SUPPORTED_MATRIX_VERSIONS = ["v1.1", "v1.5", "v1.6", "v1.8", "v1.9"];
28+
2629
describe("<ServerPickerDialog />", () => {
2730
const defaultServerConfig = {
2831
hsUrl: "https://matrix.org",
@@ -112,7 +115,7 @@ describe("<ServerPickerDialog />", () => {
112115
it("should allow user to revert from a custom server to the default", async () => {
113116
fetchMock.get(`https://custom.org/_matrix/client/versions`, {
114117
unstable_features: {},
115-
versions: ["v1.1"],
118+
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
116119
});
117120

118121
const onFinished = jest.fn();
@@ -142,7 +145,7 @@ describe("<ServerPickerDialog />", () => {
142145
const homeserver = "https://myhomeserver.site";
143146
fetchMock.get(`${homeserver}/_matrix/client/versions`, {
144147
unstable_features: {},
145-
versions: ["v1.1"],
148+
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
146149
});
147150
const onFinished = jest.fn();
148151
getComponent({ onFinished });
@@ -195,7 +198,7 @@ describe("<ServerPickerDialog />", () => {
195198

196199
fetchMock.getOnce(wellKnownUrl, validWellKnown);
197200
fetchMock.getOnce(versionsUrl, {
198-
versions: ["v1.1"],
201+
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
199202
});
200203
fetchMock.getOnce(isWellKnownUrl, {});
201204
const onFinished = jest.fn();
@@ -231,7 +234,9 @@ describe("<ServerPickerDialog />", () => {
231234
const wellKnownUrl = `https://${homeserver}/.well-known/matrix/client`;
232235
fetchMock.get(wellKnownUrl, { status: 404 });
233236
// but is otherwise live (happy versions response)
234-
fetchMock.get(`https://${homeserver}/_matrix/client/versions`, { versions: ["v1.1"] });
237+
fetchMock.get(`https://${homeserver}/_matrix/client/versions`, {
238+
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
239+
});
235240
const onFinished = jest.fn();
236241
getComponent({ onFinished });
237242

0 commit comments

Comments
 (0)