|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import '../../../olm-loader'; |
| 18 | + |
| 19 | +import { CRYPTO_ENABLED, MatrixClient } from "../../../../src/client"; |
| 20 | +import { TestClient } from "../../../TestClient"; |
| 21 | + |
| 22 | +const Olm = global.Olm; |
| 23 | + |
| 24 | +describe("crypto.setDeviceVerification", () => { |
| 25 | + const userId = "@alice:example.com"; |
| 26 | + const deviceId1 = "device1"; |
| 27 | + let client: MatrixClient; |
| 28 | + |
| 29 | + if (!CRYPTO_ENABLED) { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + beforeAll(async () => { |
| 34 | + await Olm.init(); |
| 35 | + }); |
| 36 | + |
| 37 | + beforeEach(async () => { |
| 38 | + client = (new TestClient(userId, deviceId1)).client; |
| 39 | + await client.initCrypto(); |
| 40 | + }); |
| 41 | + |
| 42 | + it("client should provide crypto", () => { |
| 43 | + expect(client.crypto).not.toBeUndefined(); |
| 44 | + }); |
| 45 | + |
| 46 | + describe("when setting an own device as verified", () => { |
| 47 | + beforeEach(async () => { |
| 48 | + jest.spyOn(client.crypto!, "cancelAndResendAllOutgoingKeyRequests"); |
| 49 | + await client.crypto!.setDeviceVerification( |
| 50 | + userId, |
| 51 | + deviceId1, |
| 52 | + true, |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it("cancelAndResendAllOutgoingKeyRequests should be called", () => { |
| 57 | + expect(client.crypto!.cancelAndResendAllOutgoingKeyRequests).toHaveBeenCalled(); |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments