mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 02:05:45 +03:00
292971dd0e
* use jest@27.4.0, replace jest-environment-jsdom-sixteen with jest-environment-jsdom Signed-off-by: Kerry Archibald <kerrya@element.io> * polyfill setImmediate Signed-off-by: Kerry Archibald <kerrya@element.io> * remove done from async test cases * useRealTimers in test relying on promise flushing Signed-off-by: Kerry Archibald <kerrya@element.io> * remove jest environment file Signed-off-by: Kerry Archibald <kerrya@element.io> * replace ts-jest mocked with jest utils mocked Signed-off-by: Kerry Archibald <kerrya@element.io>
71 lines
2.3 KiB
JavaScript
71 lines
2.3 KiB
JavaScript
import './skinned-sdk'; // Must be first for skinning to work
|
|
import { EventEmitter } from 'events';
|
|
|
|
import { waitForMember, canEncryptToAllUsers } from '../src/createRoom';
|
|
|
|
/* Shorter timeout, we've got tests to run */
|
|
const timeout = 30;
|
|
|
|
describe("waitForMember", () => {
|
|
let client;
|
|
|
|
beforeEach(() => {
|
|
client = new EventEmitter();
|
|
});
|
|
|
|
it("resolves with false if the timeout is reached", (done) => {
|
|
waitForMember(client, "", "", { timeout: 0 }).then((r) => {
|
|
expect(r).toBe(false);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it("resolves with false if the timeout is reached, even if other RoomState.newMember events fire", (done) => {
|
|
const roomId = "!roomId:domain";
|
|
const userId = "@clientId:domain";
|
|
waitForMember(client, roomId, userId, { timeout }).then((r) => {
|
|
expect(r).toBe(false);
|
|
done();
|
|
});
|
|
client.emit("RoomState.newMember", undefined, undefined, { roomId, userId: "@anotherClient:domain" });
|
|
});
|
|
|
|
it("resolves with true if RoomState.newMember fires", (done) => {
|
|
const roomId = "!roomId:domain";
|
|
const userId = "@clientId:domain";
|
|
waitForMember(client, roomId, userId, { timeout }).then((r) => {
|
|
expect(r).toBe(true);
|
|
expect(client.listeners("RoomState.newMember").length).toBe(0);
|
|
done();
|
|
});
|
|
client.emit("RoomState.newMember", undefined, undefined, { roomId, userId });
|
|
});
|
|
});
|
|
|
|
describe("canEncryptToAllUsers", () => {
|
|
const trueUser = {
|
|
"@goodUser:localhost": {
|
|
"DEV1": {},
|
|
"DEV2": {},
|
|
},
|
|
};
|
|
const falseUser = {
|
|
"@badUser:localhost": {},
|
|
};
|
|
|
|
it("returns true if all devices have crypto", async () => {
|
|
const client = {
|
|
downloadKeys: async function(userIds) { return trueUser; },
|
|
};
|
|
const response = await canEncryptToAllUsers(client, ["@goodUser:localhost"]);
|
|
expect(response).toBe(true);
|
|
});
|
|
|
|
it("returns false if not all users have crypto", async () => {
|
|
const client = {
|
|
downloadKeys: async function(userIds) { return { ...trueUser, ...falseUser }; },
|
|
};
|
|
const response = await canEncryptToAllUsers(client, ["@goodUser:localhost", "@badUser:localhost"]);
|
|
expect(response).toBe(false);
|
|
});
|
|
});
|