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