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() {
|
result.toString = function() {
|
||||||
return "mock" + (name ? " of " + name : "");
|
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 {
|
try {
|
||||||
if (constr.prototype[key] instanceof Function) {
|
if (constr.prototype[key] instanceof Function) {
|
||||||
result[key] = jest.fn();
|
result[key] = jest.fn();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as utils from "../test-utils";
|
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 { EventTimeline } from "../../src/models/event-timeline";
|
||||||
import { RoomState } from "../../src/models/room-state";
|
import { RoomState } from "../../src";
|
||||||
import { Room } from "../../src/models/room";
|
import { Room } from "../../src";
|
||||||
import { TestClient } from "../TestClient";
|
import { TestClient } from "../TestClient";
|
||||||
|
|
||||||
describe("Room", function() {
|
describe("Room", function() {
|
||||||
@@ -86,9 +86,11 @@ describe("Room", function() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
it("should call RoomState.setTypingEvent on m.typing events", function() {
|
it("should call RoomState.setTypingEvent on m.typing events", function() {
|
||||||
room.currentState = utils.mock(RoomState);
|
|
||||||
const typing = utils.mkEvent({
|
const typing = utils.mkEvent({
|
||||||
room: roomId, type: "m.typing", event: true, content: {
|
room: roomId,
|
||||||
|
type: "m.typing",
|
||||||
|
event: true,
|
||||||
|
content: {
|
||||||
user_ids: [userA],
|
user_ids: [userA],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -140,8 +142,8 @@ describe("Room", function() {
|
|||||||
expect(callCount).toEqual(2);
|
expect(callCount).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call setStateEvents on the right RoomState with the right " +
|
it("should call setStateEvents on the right RoomState with the right forwardLooking value for new events",
|
||||||
"forwardLooking value for new events", function() {
|
function() {
|
||||||
const events = [
|
const events = [
|
||||||
utils.mkMembership({
|
utils.mkMembership({
|
||||||
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
||||||
@@ -652,6 +654,7 @@ describe("Room", function() {
|
|||||||
const roomName = "flibble";
|
const roomName = "flibble";
|
||||||
|
|
||||||
const event = addMember(userA, "invite");
|
const event = addMember(userA, "invite");
|
||||||
|
event.event.unsigned = {};
|
||||||
event.event.unsigned.invite_room_state = [
|
event.event.unsigned.invite_room_state = [
|
||||||
{
|
{
|
||||||
type: "m.room.name",
|
type: "m.room.name",
|
||||||
@@ -671,6 +674,7 @@ describe("Room", function() {
|
|||||||
const roomName = "flibble";
|
const roomName = "flibble";
|
||||||
setRoomName(roomName);
|
setRoomName(roomName);
|
||||||
const roomNameToIgnore = "ignoreme";
|
const roomNameToIgnore = "ignoreme";
|
||||||
|
event.event.unsigned = {};
|
||||||
event.event.unsigned.invite_room_state = [
|
event.event.unsigned.invite_room_state = [
|
||||||
{
|
{
|
||||||
type: "m.room.name",
|
type: "m.room.name",
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ export class Room extends EventEmitter {
|
|||||||
.reverse()
|
.reverse()
|
||||||
.map(event => event.attemptDecryption(this.client.crypto, { isRetry: true }));
|
.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()
|
.reverse()
|
||||||
.map(event => event.attemptDecryption(this.client.crypto, { isRetry: true }));
|
.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"
|
* @fires module:client~MatrixClient#event:"Room.timeline"
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private addLiveEvent(event: MatrixEvent, duplicateStrategy: "ignore" | "replace", fromCache: boolean): void {
|
private addLiveEvent(event: MatrixEvent, duplicateStrategy?: "ignore" | "replace", fromCache = false): void {
|
||||||
if (event.isRedaction()) {
|
if (event.isRedaction()) {
|
||||||
const redactId = event.event.redacts;
|
const redactId = event.event.redacts;
|
||||||
|
|
||||||
@@ -1336,11 +1336,7 @@ export class Room extends EventEmitter {
|
|||||||
// call setEventMetadata to set up event.sender etc
|
// call setEventMetadata to set up event.sender etc
|
||||||
// as event is shared over all timelineSets, we set up its metadata based
|
// as event is shared over all timelineSets, we set up its metadata based
|
||||||
// on the unfiltered timelineSet.
|
// on the unfiltered timelineSet.
|
||||||
EventTimeline.setEventMetadata(
|
EventTimeline.setEventMetadata(event, this.getLiveTimeline().getState(EventTimeline.FORWARDS), false);
|
||||||
event,
|
|
||||||
this.getLiveTimeline().getState(EventTimeline.FORWARDS),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.txnToEvent[txnId] = event;
|
this.txnToEvent[txnId] = event;
|
||||||
|
|
||||||
@@ -1612,7 +1608,7 @@ export class Room extends EventEmitter {
|
|||||||
* @param {boolean} fromCache whether the sync response came from cache
|
* @param {boolean} fromCache whether the sync response came from cache
|
||||||
* @throws If <code>duplicateStrategy</code> is not falsey, 'replace' or 'ignore'.
|
* @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;
|
let i;
|
||||||
if (duplicateStrategy && ["replace", "ignore"].indexOf(duplicateStrategy) === -1) {
|
if (duplicateStrategy && ["replace", "ignore"].indexOf(duplicateStrategy) === -1) {
|
||||||
throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'");
|
throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'");
|
||||||
|
|||||||
Reference in New Issue
Block a user