-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Docs Signed-off-by: Michael Telatynski <[email protected]> * Avoid reusing user1234 Signed-off-by: Michael Telatynski <[email protected]> * Fix stale-screenshot-reporter.ts Signed-off-by: Michael Telatynski <[email protected]> * Clean up public rooms between tests on reused homeserver Signed-off-by: Michael Telatynski <[email protected]> * Deflake spotlight when homeserver is reused Signed-off-by: Michael Telatynski <[email protected]> * Deflake more tests using existing username Signed-off-by: Michael Telatynski <[email protected]> * Clean mailhog between tests Signed-off-by: Michael Telatynski <[email protected]> * Fix more flakes Signed-off-by: Michael Telatynski <[email protected]> * Fix missing _request Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Fix playwright flaky tests Signed-off-by: Michael Telatynski <[email protected]> * Wipe mailhog between test runs Signed-off-by: Michael Telatynski <[email protected]> * Delint Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * delint Signed-off-by: Michael Telatynski <[email protected]> * Deflake more tests Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Fix flaky tests Signed-off-by: Michael Telatynski <[email protected]> * Fix flaky tests Signed-off-by: Michael Telatynski <[email protected]> * Fix mas config Signed-off-by: Michael Telatynski <[email protected]> * Fix another flaky test Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
- Loading branch information
Showing
10 changed files
with
444 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright 2025 New Vector Ltd. | ||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
import { APIRequestContext } from "@playwright/test"; | ||
|
||
import { Credentials } from "../homeserver"; | ||
|
||
export type Verb = "GET" | "POST" | "PUT" | "DELETE"; | ||
|
||
export class Api { | ||
private _request?: APIRequestContext; | ||
|
||
constructor(private readonly baseUrl: string) {} | ||
|
||
public setRequest(request: APIRequestContext): void { | ||
this._request = request; | ||
} | ||
|
||
public async request<R extends {}>(verb: "GET", path: string, token?: string, data?: never): Promise<R>; | ||
public async request<R extends {}>(verb: Verb, path: string, token?: string, data?: object): Promise<R>; | ||
public async request<R extends {}>(verb: Verb, path: string, token?: string, data?: object): Promise<R> { | ||
const url = `${this.baseUrl}${path}`; | ||
const res = await this._request.fetch(url, { | ||
data, | ||
method: verb, | ||
headers: token | ||
? { | ||
Authorization: `Bearer ${token}`, | ||
} | ||
: undefined, | ||
}); | ||
|
||
if (!res.ok()) { | ||
throw new Error( | ||
`Request to ${url} failed with status ${res.status()}: ${JSON.stringify(await res.json())}`, | ||
); | ||
} | ||
|
||
return res.json(); | ||
} | ||
} | ||
|
||
export class ClientServerApi extends Api { | ||
constructor(baseUrl: string) { | ||
super(`${baseUrl}/_matrix/client`); | ||
} | ||
|
||
public async loginUser(userId: string, password: string): Promise<Credentials> { | ||
const json = await this.request<{ | ||
access_token: string; | ||
user_id: string; | ||
device_id: string; | ||
home_server: string; | ||
}>("POST", "/v3/login", undefined, { | ||
type: "m.login.password", | ||
identifier: { | ||
type: "m.id.user", | ||
user: userId, | ||
}, | ||
password: password, | ||
}); | ||
|
||
return { | ||
password, | ||
accessToken: json.access_token, | ||
userId: json.user_id, | ||
deviceId: json.device_id, | ||
homeServer: json.home_server || json.user_id.split(":").slice(1).join(":"), | ||
username: userId.slice(1).split(":")[0], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.