|
| 1 | +/* |
| 2 | +Copyright 2026 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import { MatrixClient } from "../../src/client"; |
| 18 | + |
| 19 | +describe("Room upgrades", function () { |
| 20 | + it("Sends an HTTP request upgrading the room", () => { |
| 21 | + // Given a client with a fake authedRequest method |
| 22 | + const { client, authedRequest } = createClient(); |
| 23 | + |
| 24 | + // When we upgrade the room to version 12 |
| 25 | + client.upgradeRoom("!r1", "12"); |
| 26 | + |
| 27 | + // Then we make an HTTP request to the correct endpoint, with the |
| 28 | + // version provided in the JSON. |
| 29 | + expect(authedRequest).toHaveBeenCalledWith("POST", "/rooms/!r1/upgrade", undefined, { new_version: "12" }); |
| 30 | + }); |
| 31 | + |
| 32 | + it("Includes additional_creators if provided", () => { |
| 33 | + // Given a client with a fake authedRequest method |
| 34 | + const { client, authedRequest } = createClient(); |
| 35 | + |
| 36 | + // When we upgrade the room to version 13 and supply additionalCreators |
| 37 | + client.upgradeRoom("!r1", "13", ["@u:s.co", "@v:a.b"]); |
| 38 | + |
| 39 | + // Then we make an HTTP request to the correct endpoint, with the |
| 40 | + // version and additional creators provided. |
| 41 | + expect(authedRequest).toHaveBeenCalledWith("POST", "/rooms/!r1/upgrade", undefined, { |
| 42 | + new_version: "13", |
| 43 | + additional_creators: ["@u:s.co", "@v:a.b"], |
| 44 | + }); |
| 45 | + }); |
| 46 | +}); |
| 47 | + |
| 48 | +/// |
| 49 | +function createClient(): { client: MatrixClient; authedRequest: any } { |
| 50 | + const authedRequest = vi.fn(); |
| 51 | + const client = new MatrixClient({ |
| 52 | + baseUrl: "https://my.home.server", |
| 53 | + userId: "@u:s.co", |
| 54 | + }); |
| 55 | + client.http.authedRequest = authedRequest; |
| 56 | + return { client, authedRequest }; |
| 57 | +} |
0 commit comments