Thread test utilities (#7881)

* move js utils into directory

Signed-off-by: Kerry Archibald <kerrya@element.io>

* typescripterize js test-utils

Signed-off-by: Kerry Archibald <kerrya@element.io>

* move test utils to directory

Signed-off-by: Kerry Archibald <kerrya@element.io>

* move remaining mock functions to directory

Signed-off-by: Kerry Archibald <kerrya@element.io>

* update imports

Signed-off-by: Kerry Archibald <kerrya@element.io>

* missed copyright

Signed-off-by: Kerry Archibald <kerrya@element.io>

* threads test helpers

Signed-off-by: Kerry Archibald <kerrya@element.io>

* forgotten copyright

Signed-off-by: Kerry Archibald <kerrya@element.io>

* comments

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add unsigned to root event

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-02-23 17:12:48 +01:00 committed by GitHub
parent 49bf0abeb5
commit 1830de2733
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 105 additions and 5 deletions

View file

@ -12,6 +12,7 @@ import {
EventTimeline,
RoomState,
EventType,
IEventRelation,
} from 'matrix-js-sdk';
import { MatrixClientPeg as peg } from '../../src/MatrixClientPeg';
@ -259,6 +260,12 @@ export function mkMembership(opts: MakeEventPassThruProps & {
return e;
}
export type MessageEventProps = MakeEventPassThruProps & {
room: Room["roomId"];
relatesTo?: IEventRelation;
msg?: string;
};
/**
* Create an m.room.message event.
* @param {Object} opts Values for the message
@ -269,20 +276,20 @@ export function mkMembership(opts: MakeEventPassThruProps & {
* @param {string=} opts.msg Optional. The content.body for the event.
* @return {Object|MatrixEvent} The event
*/
export function mkMessage(opts: MakeEventPassThruProps & {
room: Room["roomId"];
msg?: string;
}): MatrixEvent {
export function mkMessage({
msg, relatesTo, ...opts
}: MessageEventProps): MatrixEvent {
if (!opts.room || !opts.user) {
throw new Error("Missing .room or .user from options");
}
const message = opts.msg ?? "Random->" + Math.random();
const message = msg ?? "Random->" + Math.random();
const event: MakeEventProps = {
...opts,
type: "m.room.message",
content: {
msgtype: "m.text",
body: message,
['m.relates_to']: relatesTo,
},
};