You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Fix tests and tweak some optional types
This commit is contained in:
@@ -51,7 +51,7 @@ export function mock(constr, name) {
|
||||
result.toString = function() {
|
||||
return "mock" + (name ? " of " + name : "");
|
||||
};
|
||||
for (const key in constr.prototype) { // eslint-disable-line guard-for-in
|
||||
for (const key of Object.getOwnPropertyNames(constr.prototype)) { // eslint-disable-line guard-for-in
|
||||
try {
|
||||
if (constr.prototype[key] instanceof Function) {
|
||||
result[key] = jest.fn();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as utils from "../test-utils";
|
||||
import { EventStatus, MatrixEvent } from "../../src/models/event";
|
||||
import { EventStatus, MatrixEvent } from "../../src";
|
||||
import { EventTimeline } from "../../src/models/event-timeline";
|
||||
import { RoomState } from "../../src/models/room-state";
|
||||
import { Room } from "../../src/models/room";
|
||||
import { RoomState } from "../../src";
|
||||
import { Room } from "../../src";
|
||||
import { TestClient } from "../TestClient";
|
||||
|
||||
describe("Room", function() {
|
||||
@@ -86,9 +86,11 @@ describe("Room", function() {
|
||||
];
|
||||
|
||||
it("should call RoomState.setTypingEvent on m.typing events", function() {
|
||||
room.currentState = utils.mock(RoomState);
|
||||
const typing = utils.mkEvent({
|
||||
room: roomId, type: "m.typing", event: true, content: {
|
||||
room: roomId,
|
||||
type: "m.typing",
|
||||
event: true,
|
||||
content: {
|
||||
user_ids: [userA],
|
||||
},
|
||||
});
|
||||
@@ -140,8 +142,8 @@ describe("Room", function() {
|
||||
expect(callCount).toEqual(2);
|
||||
});
|
||||
|
||||
it("should call setStateEvents on the right RoomState with the right " +
|
||||
"forwardLooking value for new events", function() {
|
||||
it("should call setStateEvents on the right RoomState with the right forwardLooking value for new events",
|
||||
function() {
|
||||
const events = [
|
||||
utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
||||
@@ -652,6 +654,7 @@ describe("Room", function() {
|
||||
const roomName = "flibble";
|
||||
|
||||
const event = addMember(userA, "invite");
|
||||
event.event.unsigned = {};
|
||||
event.event.unsigned.invite_room_state = [
|
||||
{
|
||||
type: "m.room.name",
|
||||
@@ -671,6 +674,7 @@ describe("Room", function() {
|
||||
const roomName = "flibble";
|
||||
setRoomName(roomName);
|
||||
const roomNameToIgnore = "ignoreme";
|
||||
event.event.unsigned = {};
|
||||
event.event.unsigned.invite_room_state = [
|
||||
{
|
||||
type: "m.room.name",
|
||||
|
||||
@@ -284,7 +284,7 @@ export class Room extends EventEmitter {
|
||||
.reverse()
|
||||
.map(event => event.attemptDecryption(this.client.crypto, { isRetry: true }));
|
||||
|
||||
return Promise.allSettled(decryptionPromises);
|
||||
return Promise.allSettled(decryptionPromises) as Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,7 +301,7 @@ export class Room extends EventEmitter {
|
||||
.reverse()
|
||||
.map(event => event.attemptDecryption(this.client.crypto, { isRetry: true }));
|
||||
|
||||
return Promise.allSettled(decryptionPromises);
|
||||
return Promise.allSettled(decryptionPromises) as Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1237,7 +1237,7 @@ export class Room extends EventEmitter {
|
||||
* @fires module:client~MatrixClient#event:"Room.timeline"
|
||||
* @private
|
||||
*/
|
||||
private addLiveEvent(event: MatrixEvent, duplicateStrategy: "ignore" | "replace", fromCache: boolean): void {
|
||||
private addLiveEvent(event: MatrixEvent, duplicateStrategy?: "ignore" | "replace", fromCache = false): void {
|
||||
if (event.isRedaction()) {
|
||||
const redactId = event.event.redacts;
|
||||
|
||||
@@ -1336,11 +1336,7 @@ export class Room extends EventEmitter {
|
||||
// call setEventMetadata to set up event.sender etc
|
||||
// as event is shared over all timelineSets, we set up its metadata based
|
||||
// on the unfiltered timelineSet.
|
||||
EventTimeline.setEventMetadata(
|
||||
event,
|
||||
this.getLiveTimeline().getState(EventTimeline.FORWARDS),
|
||||
false,
|
||||
);
|
||||
EventTimeline.setEventMetadata(event, this.getLiveTimeline().getState(EventTimeline.FORWARDS), false);
|
||||
|
||||
this.txnToEvent[txnId] = event;
|
||||
|
||||
@@ -1612,7 +1608,7 @@ export class Room extends EventEmitter {
|
||||
* @param {boolean} fromCache whether the sync response came from cache
|
||||
* @throws If <code>duplicateStrategy</code> is not falsey, 'replace' or 'ignore'.
|
||||
*/
|
||||
public addLiveEvents(events: MatrixEvent[], duplicateStrategy: "replace" | "ignore", fromCache: boolean): void {
|
||||
public addLiveEvents(events: MatrixEvent[], duplicateStrategy?: "replace" | "ignore", fromCache = false): void {
|
||||
let i;
|
||||
if (duplicateStrategy && ["replace", "ignore"].indexOf(duplicateStrategy) === -1) {
|
||||
throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'");
|
||||
|
||||
Reference in New Issue
Block a user