2020-08-05 18:38:55 +02:00
|
|
|
/*
|
|
|
|
Copyright 2020 Bruno Windels <bruno@windels.cloud>
|
2020-09-22 13:40:38 +02:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2020-08-05 18:38:55 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-11-21 16:42:28 +01:00
|
|
|
import {encodeQueryParams, encodeBody} from "./common";
|
2021-11-21 16:58:16 +01:00
|
|
|
import {HomeServerRequest} from "./HomeServerRequest";
|
2021-11-23 13:39:33 +01:00
|
|
|
import type {Reconnector} from "./Reconnector";
|
|
|
|
import type {IEncodedBody} from "./common";
|
2021-11-23 15:07:25 +01:00
|
|
|
import type {IRequestOptions, RequestFunction} from "../../platform/types/types";
|
2021-11-23 13:39:33 +01:00
|
|
|
import type {LogItem} from "../../logging/LogItem";
|
|
|
|
|
|
|
|
type RequestMethod = "POST" | "GET" | "PUT";
|
2020-11-11 10:45:23 +01:00
|
|
|
|
2021-10-26 18:47:46 +02:00
|
|
|
const CS_R0_PREFIX = "/_matrix/client/r0";
|
2021-10-27 15:08:53 +02:00
|
|
|
const DEHYDRATION_PREFIX = "/_matrix/client/unstable/org.matrix.msc2697.v2";
|
2021-10-26 18:47:46 +02:00
|
|
|
|
2021-11-24 08:35:13 +01:00
|
|
|
type Ctor = {
|
|
|
|
homeserver: string;
|
|
|
|
accessToken: string;
|
|
|
|
request: RequestFunction;
|
|
|
|
reconnector: Reconnector;
|
|
|
|
};
|
|
|
|
|
2020-04-20 21:26:39 +02:00
|
|
|
export class HomeServerApi {
|
2021-11-23 13:39:33 +01:00
|
|
|
private readonly _homeserver: string;
|
|
|
|
private readonly _accessToken: string;
|
|
|
|
private readonly _requestFn: RequestFunction;
|
|
|
|
private readonly _reconnector: Reconnector;
|
|
|
|
|
2021-11-24 08:35:13 +01:00
|
|
|
constructor({homeserver, accessToken, request, reconnector}: Ctor) {
|
2019-03-08 20:03:47 +01:00
|
|
|
// store these both in a closure somehow so it's harder to get at in case of XSS?
|
|
|
|
// one could change the homeserver as well so the token gets sent there, so both must be protected from read/write
|
2021-08-23 19:26:39 +02:00
|
|
|
this._homeserver = homeserver;
|
2019-06-26 22:31:36 +02:00
|
|
|
this._accessToken = accessToken;
|
2019-12-23 14:28:27 +01:00
|
|
|
this._requestFn = request;
|
2020-04-05 15:11:15 +02:00
|
|
|
this._reconnector = reconnector;
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2018-12-21 14:35:24 +01:00
|
|
|
|
2021-11-23 15:01:13 +01:00
|
|
|
private _url(csPath: string, prefix: string = CS_R0_PREFIX): string {
|
2021-10-26 18:47:46 +02:00
|
|
|
return this._homeserver + prefix + csPath;
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2018-12-21 14:35:24 +01:00
|
|
|
|
2021-11-23 15:01:13 +01:00
|
|
|
private _baseRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions, accessToken?: string): HomeServerRequest {
|
2020-08-20 15:40:43 +02:00
|
|
|
const queryString = encodeQueryParams(queryParams);
|
2020-03-30 23:56:03 +02:00
|
|
|
url = `${url}?${queryString}`;
|
2021-11-23 13:39:33 +01:00
|
|
|
let log: LogItem | undefined;
|
2021-02-12 18:35:33 +01:00
|
|
|
if (options?.log) {
|
|
|
|
const parent = options?.log;
|
|
|
|
log = parent.child({
|
2021-02-17 18:45:12 +01:00
|
|
|
t: "network",
|
2021-02-12 18:35:33 +01:00
|
|
|
url,
|
|
|
|
method,
|
|
|
|
}, parent.level.Info);
|
|
|
|
}
|
2021-11-23 13:39:33 +01:00
|
|
|
let encodedBody: IEncodedBody["body"];
|
|
|
|
const headers: Map<string, string | number> = new Map();
|
2020-09-18 18:13:20 +02:00
|
|
|
if (accessToken) {
|
|
|
|
headers.set("Authorization", `Bearer ${accessToken}`);
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2020-04-22 20:46:47 +02:00
|
|
|
headers.set("Accept", "application/json");
|
2019-06-26 22:31:36 +02:00
|
|
|
if (body) {
|
2020-11-11 10:45:23 +01:00
|
|
|
const encoded = encodeBody(body);
|
|
|
|
headers.set("Content-Type", encoded.mimeType);
|
2021-11-23 13:39:33 +01:00
|
|
|
//todo: remove this?
|
2020-11-11 10:45:23 +01:00
|
|
|
headers.set("Content-Length", encoded.length);
|
|
|
|
encodedBody = encoded.body;
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2021-02-12 18:35:33 +01:00
|
|
|
|
2019-12-23 14:28:27 +01:00
|
|
|
const requestResult = this._requestFn(url, {
|
2019-06-26 22:31:36 +02:00
|
|
|
method,
|
|
|
|
headers,
|
2020-11-11 10:45:23 +01:00
|
|
|
body: encodedBody,
|
2020-10-23 17:18:11 +02:00
|
|
|
timeout: options?.timeout,
|
2020-11-16 10:45:46 +01:00
|
|
|
uploadProgress: options?.uploadProgress,
|
2020-11-11 10:45:23 +01:00
|
|
|
format: "json" // response format
|
2019-06-26 22:31:36 +02:00
|
|
|
});
|
2020-04-05 15:11:15 +02:00
|
|
|
|
2021-04-09 15:15:28 +02:00
|
|
|
const hsRequest = new HomeServerRequest(method, url, requestResult, log);
|
2020-04-05 15:11:15 +02:00
|
|
|
|
|
|
|
if (this._reconnector) {
|
2021-04-09 15:15:28 +02:00
|
|
|
hsRequest.response().catch(err => {
|
2020-09-25 10:45:41 +02:00
|
|
|
// Some endpoints such as /sync legitimately time-out
|
|
|
|
// (which is also reported as a ConnectionError) and will re-attempt,
|
|
|
|
// but spinning up the reconnector in this case is ok,
|
|
|
|
// as all code ran on session and sync start should be reentrant
|
2020-05-06 19:38:33 +02:00
|
|
|
if (err.name === "ConnectionError") {
|
2020-04-05 15:11:15 +02:00
|
|
|
this._reconnector.onRequestFailed(this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-09 15:15:28 +02:00
|
|
|
return hsRequest;
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2019-02-04 23:26:24 +01:00
|
|
|
|
2021-11-23 15:01:13 +01:00
|
|
|
private _unauthedRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._baseRequest(method, url, queryParams, body, options);
|
2020-09-18 18:13:20 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 15:01:13 +01:00
|
|
|
private _authedRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2020-09-18 18:13:20 +02:00
|
|
|
return this._baseRequest(method, url, queryParams, body, options, this._accessToken);
|
|
|
|
}
|
|
|
|
|
2021-11-23 15:01:13 +01:00
|
|
|
private _post(csPath: string, queryParams: Record<string, any>, body: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-10-26 18:47:46 +02:00
|
|
|
return this._authedRequest("POST", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options);
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2019-02-04 23:26:24 +01:00
|
|
|
|
2021-11-23 15:01:13 +01:00
|
|
|
private _put(csPath: string, queryParams: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-10-26 18:47:46 +02:00
|
|
|
return this._authedRequest("PUT", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options);
|
2019-07-26 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 15:01:13 +01:00
|
|
|
private _get(csPath: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-10-26 18:47:46 +02:00
|
|
|
return this._authedRequest("GET", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options);
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2018-12-21 14:35:24 +01:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
sync(since: string, filter: string, timeout: number, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._get("/sync", {since, timeout, filter}, undefined, options);
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2019-02-04 23:26:24 +01:00
|
|
|
|
2019-03-09 00:41:06 +01:00
|
|
|
// params is from, dir and optionally to, limit, filter.
|
2021-11-23 14:42:18 +01:00
|
|
|
messages(roomId: string, params: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._get(`/rooms/${encodeURIComponent(roomId)}/messages`, params, undefined, options);
|
2019-03-09 00:41:06 +01:00
|
|
|
}
|
|
|
|
|
2020-08-19 16:11:33 +02:00
|
|
|
// params is at, membership and not_membership
|
2021-11-23 14:42:18 +01:00
|
|
|
members(roomId: string, params: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._get(`/rooms/${encodeURIComponent(roomId)}/members`, params, undefined, options);
|
2020-08-19 16:11:33 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
send(roomId: string, eventType: string, txnId: string, content: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2020-04-05 15:11:15 +02:00
|
|
|
return this._put(`/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/${encodeURIComponent(txnId)}`, {}, content, options);
|
2019-07-26 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
redact(roomId: string, eventId: string, txnId: string, content: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-05-19 16:41:07 +02:00
|
|
|
return this._put(`/rooms/${encodeURIComponent(roomId)}/redact/${encodeURIComponent(eventId)}/${encodeURIComponent(txnId)}`, {}, content, options);
|
|
|
|
}
|
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
receipt(roomId: string, receiptType: string, eventId: string, options?: IRequestOptions): HomeServerRequest {
|
2020-08-21 15:16:57 +02:00
|
|
|
return this._post(`/rooms/${encodeURIComponent(roomId)}/receipt/${encodeURIComponent(receiptType)}/${encodeURIComponent(eventId)}`,
|
|
|
|
{}, {}, options);
|
|
|
|
}
|
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
state(roomId: string, eventType: string, stateKey: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._get(`/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/${encodeURIComponent(stateKey)}`, {}, undefined, options);
|
2021-08-02 14:20:09 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
getLoginFlows(): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._unauthedRequest("GET", this._url("/login"));
|
2021-07-27 15:53:46 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
passwordLogin(username: string, password: string, initialDeviceDisplayName: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._unauthedRequest("POST", this._url("/login"), undefined, {
|
2019-02-04 23:26:24 +01:00
|
|
|
"type": "m.login.password",
|
|
|
|
"identifier": {
|
|
|
|
"type": "m.id.user",
|
|
|
|
"user": username
|
|
|
|
},
|
2020-09-08 10:53:15 +02:00
|
|
|
"password": password,
|
|
|
|
"initial_device_display_name": initialDeviceDisplayName
|
2020-04-05 15:11:15 +02:00
|
|
|
}, options);
|
2019-06-26 22:31:36 +02:00
|
|
|
}
|
2019-10-12 20:24:09 +02:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
tokenLogin(loginToken: string, txnId: string, initialDeviceDisplayName: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._unauthedRequest("POST", this._url("/login"), undefined, {
|
2021-08-15 08:53:32 +02:00
|
|
|
"type": "m.login.token",
|
|
|
|
"identifier": {
|
|
|
|
"type": "m.id.user",
|
|
|
|
},
|
|
|
|
"token": loginToken,
|
|
|
|
"txn_id": txnId,
|
|
|
|
"initial_device_display_name": initialDeviceDisplayName
|
|
|
|
}, options);
|
|
|
|
}
|
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
createFilter(userId: string, filter: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post(`/user/${encodeURIComponent(userId)}/filter`, {}, filter, options);
|
2019-10-12 20:24:09 +02:00
|
|
|
}
|
2020-03-30 23:56:03 +02:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
versions(options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._unauthedRequest("GET", `${this._homeserver}/_matrix/client/versions`, undefined, undefined, options);
|
2020-03-30 23:56:03 +02:00
|
|
|
}
|
2020-05-09 20:02:08 +02:00
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
uploadKeys(dehydratedDeviceId: string, payload: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-10-26 18:47:46 +02:00
|
|
|
let path = "/keys/upload";
|
|
|
|
if (dehydratedDeviceId) {
|
|
|
|
path = path + `/${encodeURIComponent(dehydratedDeviceId)}`;
|
|
|
|
}
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post(path, {}, payload, options);
|
2020-08-27 19:13:24 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
queryKeys(queryRequest: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post("/keys/query", {}, queryRequest, options);
|
2020-08-31 14:24:09 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
claimKeys(payload: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post("/keys/claim", {}, payload, options);
|
2020-09-03 15:33:23 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
sendToDevice(type: string, payload: Record<string, any>, txnId: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._put(`/sendToDevice/${encodeURIComponent(type)}/${encodeURIComponent(txnId)}`, {}, payload, options);
|
2020-09-03 15:36:17 +02:00
|
|
|
}
|
2020-09-17 14:19:57 +02:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
roomKeysVersion(version?: string, options?: IRequestOptions): HomeServerRequest {
|
2020-09-17 17:57:12 +02:00
|
|
|
let versionPart = "";
|
|
|
|
if (version) {
|
|
|
|
versionPart = `/${encodeURIComponent(version)}`;
|
2020-09-17 14:19:57 +02:00
|
|
|
}
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._get(`/room_keys/version${versionPart}`, undefined, undefined, options);
|
2020-09-17 14:19:57 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
roomKeyForRoomAndSession(version: string, roomId: string, sessionId: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._get(`/room_keys/keys/${encodeURIComponent(roomId)}/${encodeURIComponent(sessionId)}`, {version}, undefined, options);
|
2020-09-17 14:19:57 +02:00
|
|
|
}
|
2020-11-11 10:45:44 +01:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
uploadAttachment(blob: Blob, filename: string, options?: IRequestOptions): HomeServerRequest {
|
2020-11-11 11:50:40 +01:00
|
|
|
return this._authedRequest("POST", `${this._homeserver}/_matrix/media/r0/upload`, {filename}, blob, options);
|
2020-11-11 10:45:44 +01:00
|
|
|
}
|
2021-03-18 20:42:46 +01:00
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
setPusher(pusher: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post("/pushers/set", {}, pusher, options);
|
2021-03-18 20:42:46 +01:00
|
|
|
}
|
2021-04-01 14:59:46 +02:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
getPushers(options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._get("/pushers", undefined, undefined, options);
|
2021-04-01 14:59:46 +02:00
|
|
|
}
|
2021-04-20 19:02:45 +02:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
join(roomId: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post(`/rooms/${encodeURIComponent(roomId)}/join`, {}, {}, options);
|
2021-04-20 19:02:45 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
joinIdOrAlias(roomIdOrAlias: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`, {}, {}, options);
|
2021-05-18 11:05:31 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
leave(roomId: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post(`/rooms/${encodeURIComponent(roomId)}/leave`, {}, {}, options);
|
2021-04-20 19:02:45 +02:00
|
|
|
}
|
2021-05-12 15:38:54 +02:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
forget(roomId: string, options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post(`/rooms/${encodeURIComponent(roomId)}/forget`, {}, {}, options);
|
2021-05-12 15:38:54 +02:00
|
|
|
}
|
2021-10-26 12:49:31 +02:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
logout(options?: IRequestOptions): HomeServerRequest {
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post(`/logout`, {}, {}, options);
|
2021-10-26 12:49:31 +02:00
|
|
|
}
|
2021-10-26 18:47:46 +02:00
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
getDehydratedDevice(options: IRequestOptions): HomeServerRequest {
|
2021-10-26 18:47:46 +02:00
|
|
|
options.prefix = DEHYDRATION_PREFIX;
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._get(`/dehydrated_device`, undefined, undefined, options);
|
2021-10-26 18:47:46 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 14:42:18 +01:00
|
|
|
createDehydratedDevice(payload: Record<string, any>, options: IRequestOptions): HomeServerRequest {
|
2021-10-26 18:47:46 +02:00
|
|
|
options.prefix = DEHYDRATION_PREFIX;
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._put(`/dehydrated_device`, {}, payload, options);
|
2021-10-26 18:47:46 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 13:43:40 +01:00
|
|
|
claimDehydratedDevice(deviceId: string, options: IRequestOptions): HomeServerRequest {
|
2021-10-26 18:47:46 +02:00
|
|
|
options.prefix = DEHYDRATION_PREFIX;
|
2021-11-23 13:39:33 +01:00
|
|
|
return this._post(`/dehydrated_device/claim`, {}, {device_id: deviceId}, options);
|
2021-10-26 18:47:46 +02:00
|
|
|
}
|
2019-03-08 12:26:59 +01:00
|
|
|
}
|
2020-04-22 20:47:31 +02:00
|
|
|
|
2021-04-09 15:15:28 +02:00
|
|
|
import {Request as MockRequest} from "../../mocks/Request.js";
|
2020-04-22 20:47:31 +02:00
|
|
|
|
2021-04-09 15:15:28 +02:00
|
|
|
export function tests() {
|
2020-04-22 20:47:31 +02:00
|
|
|
return {
|
|
|
|
"superficial happy path for GET": async assert => {
|
2021-11-23 13:39:33 +01:00
|
|
|
// @ts-ignore
|
2020-04-22 20:47:31 +02:00
|
|
|
const hsApi = new HomeServerApi({
|
2021-04-09 15:15:28 +02:00
|
|
|
request: () => new MockRequest().respond(200, 42),
|
2021-11-23 13:39:33 +01:00
|
|
|
homeserver: "https://hs.tld",
|
2020-04-22 20:47:31 +02:00
|
|
|
});
|
2021-11-23 15:01:13 +01:00
|
|
|
// @ts-ignore
|
2021-11-24 08:29:10 +01:00
|
|
|
const result = await hsApi._get("foo").response();
|
2020-04-22 20:47:31 +02:00
|
|
|
assert.strictEqual(result, 42);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|