You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-28 15:22:05 +03:00
Element-R: Starting a DMs with a user (#10673)
* Use `cli.getUserDeviceInfo` instead of `cli.downloadKeys` to create a room * Use `client.getCrypto().getUserDeviceInfo` instead of `client.getUserDeviceInfo` * Update `createRoom-test.ts` to use `getUserDeviceInfo` * Remove duplicate field
This commit is contained in:
@ -15,8 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { mocked, Mocked } from "jest-mock";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
||||
import { CryptoApi, MatrixClient, Device } from "matrix-js-sdk/src/matrix";
|
||||
import { RoomType } from "matrix-js-sdk/src/@types/event";
|
||||
|
||||
import { stubClient, setupAsyncStoreWithClient, mockPlatformPeg } from "./test-utils";
|
||||
@ -151,30 +150,32 @@ describe("canEncryptToAllUsers", () => {
|
||||
const user2Id = "@user2:example.com";
|
||||
|
||||
const devices = new Map([
|
||||
["DEV1", {} as unknown as DeviceInfo],
|
||||
["DEV2", {} as unknown as DeviceInfo],
|
||||
["DEV1", {} as unknown as Device],
|
||||
["DEV2", {} as unknown as Device],
|
||||
]);
|
||||
|
||||
let client: Mocked<MatrixClient>;
|
||||
let cryptoApi: Mocked<CryptoApi>;
|
||||
|
||||
beforeAll(() => {
|
||||
client = mocked(stubClient());
|
||||
cryptoApi = mocked(client.getCrypto()!);
|
||||
});
|
||||
|
||||
it("should return true if userIds is empty", async () => {
|
||||
client.downloadKeys.mockResolvedValue(new Map());
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(new Map());
|
||||
const result = await canEncryptToAllUsers(client, []);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true if download keys does not return any user", async () => {
|
||||
client.downloadKeys.mockResolvedValue(new Map());
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(new Map());
|
||||
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if none of the users has a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, new Map()],
|
||||
[user2Id, new Map()],
|
||||
@ -185,7 +186,7 @@ describe("canEncryptToAllUsers", () => {
|
||||
});
|
||||
|
||||
it("should return false if some of the users don't have a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, new Map()],
|
||||
[user2Id, devices],
|
||||
@ -196,7 +197,7 @@ describe("canEncryptToAllUsers", () => {
|
||||
});
|
||||
|
||||
it("should return true if all users have a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, devices],
|
||||
[user2Id, devices],
|
||||
|
Reference in New Issue
Block a user