From 143b6c6fdb336256592a9e7fce176e638d8d213e Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 14 Jun 2023 16:12:41 +0100 Subject: [PATCH] Avoid deprecated classes in verification integ test https://github.com/matrix-org/matrix-js-sdk/pull/3449 deprecated a bunch of exports from `src/crypto/verification/request/VerificationRequest`. Let's stop using them in the integration test. --- spec/integ/crypto/verification.spec.ts | 40 ++++++++++++++------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index 2f366558723..0ceac47246d 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -18,7 +18,16 @@ import fetchMock from "fetch-mock-jest"; import { MockResponse } from "fetch-mock"; import { createClient, CryptoEvent, MatrixClient } from "../../../src"; -import { ShowQrCodeCallbacks, ShowSasCallbacks, Verifier, VerifierEvent } from "../../../src/crypto-api/verification"; +import { + ShowQrCodeCallbacks, + ShowSasCallbacks, + Verifier, + VerifierEvent, + VerificationPhase, + VerificationRequest, + VerificationRequestEvent, + canAcceptVerificationRequest, +} from "../../../src/crypto-api/verification"; import { escapeRegExp } from "../../../src/utils"; import { CRYPTO_BACKENDS, emitPromise, InitCrypto } from "../../test-utils/test-utils"; import { SyncResponder } from "../../test-utils/SyncResponder"; @@ -31,11 +40,6 @@ import { TEST_USER_ID, } from "../../test-utils/test-data"; import { mockInitialApiRequests } from "../../test-utils/mockEndpoints"; -import { - Phase, - VerificationRequest, - VerificationRequestEvent, -} from "../../../src/crypto/verification/request/VerificationRequest"; // The verification flows use javascript timers to set timeouts. We tell jest to use mock timer implementations // to ensure that we don't end up with dangling timeouts. @@ -130,7 +134,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st ]); const transactionId = request.transactionId; expect(transactionId).toBeDefined(); - expect(request.phase).toEqual(Phase.Requested); + expect(request.phase).toEqual(VerificationPhase.Requested); expect(request.roomId).toBeUndefined(); let toDeviceMessage = requestBody.messages[TEST_USER_ID][TEST_DEVICE_ID]; @@ -148,7 +152,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st }, }); await waitForVerificationRequestChanged(request); - expect(request.phase).toEqual(Phase.Ready); + expect(request.phase).toEqual(VerificationPhase.Ready); expect(request.otherDeviceId).toEqual(TEST_DEVICE_ID); // ... and picks a method with m.key.verification.start @@ -165,7 +169,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st }, }); await waitForVerificationRequestChanged(request); - expect(request.phase).toEqual(Phase.Started); + expect(request.phase).toEqual(VerificationPhase.Started); expect(request.chosenMethod).toEqual("m.sas.v1"); // there should now be a verifier @@ -238,7 +242,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st // ... and the whole thing should be done! await verificationPromise; - expect(request.phase).toEqual(Phase.Done); + expect(request.phase).toEqual(VerificationPhase.Done); // we're done with the temporary keypair olmSAS.free(); @@ -290,7 +294,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st }, }); await waitForVerificationRequestChanged(request); - expect(request.phase).toEqual(Phase.Ready); + expect(request.phase).toEqual(VerificationPhase.Ready); // we should now have QR data we can display const qrCodeBuffer = request.getQRCodeBytes()!; @@ -320,7 +324,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st }, }); await waitForVerificationRequestChanged(request); - expect(request.phase).toEqual(Phase.Started); + expect(request.phase).toEqual(VerificationPhase.Started); expect(request.chosenMethod).toEqual("m.reciprocate.v1"); // there should now be a verifier @@ -346,7 +350,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st // ... and the whole thing should be done! await verificationPromise; - expect(request.phase).toEqual(Phase.Done); + expect(request.phase).toEqual(VerificationPhase.Done); }, ); @@ -374,18 +378,18 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st }); const request: VerificationRequest = await emitPromise(aliceClient, CryptoEvent.VerificationRequest); expect(request.transactionId).toEqual(TRANSACTION_ID); - expect(request.phase).toEqual(Phase.Requested); + expect(request.phase).toEqual(VerificationPhase.Requested); expect(request.roomId).toBeUndefined(); - expect(request.canAccept).toBe(true); + expect(canAcceptVerificationRequest(request)).toBe(true); // Alice accepts, by sending a to-device message const sendToDevicePromise = expectSendToDeviceMessage("m.key.verification.ready"); const acceptPromise = request.accept(); - expect(request.canAccept).toBe(false); - expect(request.phase).toEqual(Phase.Requested); + expect(canAcceptVerificationRequest(request)).toBe(false); + expect(request.phase).toEqual(VerificationPhase.Requested); await acceptPromise; const requestBody = await sendToDevicePromise; - expect(request.phase).toEqual(Phase.Ready); + expect(request.phase).toEqual(VerificationPhase.Ready); const toDeviceMessage = requestBody.messages[TEST_USER_ID][TEST_DEVICE_ID]; expect(toDeviceMessage.methods).toContain("m.sas.v1");