You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-30 04:23:07 +03:00
Element R: emit events when devices have changed (#4019)
* emit events when Rust crypto wasm tells us devices have changed * lint * add missing stub function * apply workaround for queueMicrotask
This commit is contained in:
@ -94,6 +94,7 @@ describe("initRustCrypto", () => {
|
||||
getSecretsFromInbox: jest.fn().mockResolvedValue([]),
|
||||
deleteSecretsFromInbox: jest.fn(),
|
||||
registerReceiveSecretCallback: jest.fn(),
|
||||
registerDevicesUpdatedCallback: jest.fn(),
|
||||
outgoingRequests: jest.fn(),
|
||||
isBackupEnabled: jest.fn().mockResolvedValue(false),
|
||||
verifyBackup: jest.fn().mockResolvedValue({ trusted: jest.fn().mockReturnValue(false) }),
|
||||
@ -1132,6 +1133,33 @@ describe("RustCrypto", () => {
|
||||
rustCrypto.stop();
|
||||
});
|
||||
|
||||
it("should emit events on device changes", async () => {
|
||||
jest.useFakeTimers({ doNotFake: ["queueMicrotask"] });
|
||||
|
||||
fetchMock.post("path:/_matrix/client/v3/keys/upload", { one_time_key_counts: {} });
|
||||
fetchMock.post("path:/_matrix/client/v3/keys/query", {
|
||||
device_keys: {
|
||||
[testData.TEST_USER_ID]: {
|
||||
[testData.TEST_DEVICE_ID]: testData.SIGNED_TEST_DEVICE_DATA,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const rustCrypto = await makeTestRustCrypto(makeMatrixHttpApi(), testData.TEST_USER_ID);
|
||||
const willUpdateCallback = jest.fn();
|
||||
rustCrypto.on(CryptoEvent.WillUpdateDevices, willUpdateCallback);
|
||||
const devicesUpdatedCallback = jest.fn();
|
||||
rustCrypto.on(CryptoEvent.DevicesUpdated, devicesUpdatedCallback);
|
||||
|
||||
rustCrypto.onSyncCompleted({});
|
||||
|
||||
// wait for the devices to be updated
|
||||
await rustCrypto.getUserDeviceInfo([testData.TEST_USER_ID]);
|
||||
expect(willUpdateCallback).toHaveBeenCalledWith([testData.TEST_USER_ID], false);
|
||||
expect(devicesUpdatedCallback).toHaveBeenCalledWith([testData.TEST_USER_ID], false);
|
||||
rustCrypto.stop();
|
||||
});
|
||||
|
||||
describe("requestDeviceVerification", () => {
|
||||
it("throws an error if the device is unknown", async () => {
|
||||
const rustCrypto = await makeTestRustCrypto();
|
||||
|
Reference in New Issue
Block a user