2022-03-25 00:32:22 +03:00
|
|
|
import { canEncryptToAllUsers } from '../src/createRoom';
|
2020-02-18 14:25:19 +03:00
|
|
|
|
|
|
|
describe("canEncryptToAllUsers", () => {
|
|
|
|
const trueUser = {
|
|
|
|
"@goodUser:localhost": {
|
|
|
|
"DEV1": {},
|
|
|
|
"DEV2": {},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const falseUser = {
|
|
|
|
"@badUser:localhost": {},
|
|
|
|
};
|
|
|
|
|
2022-02-02 15:02:17 +03:00
|
|
|
it("returns true if all devices have crypto", async () => {
|
2020-02-18 14:25:19 +03:00
|
|
|
const client = {
|
|
|
|
downloadKeys: async function(userIds) { return trueUser; },
|
|
|
|
};
|
|
|
|
const response = await canEncryptToAllUsers(client, ["@goodUser:localhost"]);
|
|
|
|
expect(response).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-02-02 15:02:17 +03:00
|
|
|
it("returns false if not all users have crypto", async () => {
|
2020-02-18 14:25:19 +03:00
|
|
|
const client = {
|
2021-06-29 15:11:58 +03:00
|
|
|
downloadKeys: async function(userIds) { return { ...trueUser, ...falseUser }; },
|
2020-02-18 14:25:19 +03:00
|
|
|
};
|
|
|
|
const response = await canEncryptToAllUsers(client, ["@goodUser:localhost", "@badUser:localhost"]);
|
|
|
|
expect(response).toBe(false);
|
|
|
|
});
|
|
|
|
});
|