@@ -6,8 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
6
6
Please see LICENSE files in the repository root for full details.
7
7
*/
8
8
9
+ import * as MatrixJs from "matrix-js-sdk/src/matrix" ;
9
10
import { logger } from "matrix-js-sdk/src/logger" ;
10
- import fetchMockJest from "fetch-mock-jest" ;
11
11
12
12
import { advanceDateAndTime , stubClient } from "./test-utils" ;
13
13
import { IMatrixClientPeg , MatrixClientPeg as peg } from "../src/MatrixClientPeg" ;
@@ -19,9 +19,14 @@ jest.useFakeTimers();
19
19
const PegClass = Object . getPrototypeOf ( peg ) . constructor ;
20
20
21
21
describe ( "MatrixClientPeg" , ( ) => {
22
+ let mockClient : MatrixJs . MatrixClient ;
23
+
22
24
beforeEach ( ( ) => {
23
25
// stub out Logger.log which gets called a lot and clutters up the test output
24
26
jest . spyOn ( logger , "log" ) . mockImplementation ( ( ) => { } ) ;
27
+
28
+ mockClient = stubClient ( ) ;
29
+ jest . spyOn ( MatrixJs , "createClient" ) . mockReturnValue ( mockClient ) ;
25
30
} ) ;
26
31
27
32
afterEach ( ( ) => {
@@ -33,7 +38,6 @@ describe("MatrixClientPeg", () => {
33
38
} ) ;
34
39
35
40
it ( "setJustRegisteredUserId" , ( ) => {
36
- stubClient ( ) ;
37
41
( peg as any ) . matrixClient = peg . get ( ) ;
38
42
peg . setJustRegisteredUserId ( "@userId:matrix.org" ) ;
39
43
expect ( peg . safeGet ( ) . credentials . userId ) . toBe ( "@userId:matrix.org" ) ;
@@ -52,7 +56,6 @@ describe("MatrixClientPeg", () => {
52
56
} ) ;
53
57
54
58
it ( "setJustRegisteredUserId(null)" , ( ) => {
55
- stubClient ( ) ;
56
59
( peg as any ) . matrixClient = peg . get ( ) ;
57
60
peg . setJustRegisteredUserId ( null ) ;
58
61
expect ( peg . currentUserIsJustRegistered ( ) ) . toBe ( false ) ;
@@ -71,7 +74,6 @@ describe("MatrixClientPeg", () => {
71
74
beforeEach ( ( ) => {
72
75
// instantiate a MatrixClientPegClass instance, with a new MatrixClient
73
76
testPeg = new PegClass ( ) ;
74
- fetchMockJest . get ( "http://example.com/_matrix/client/versions" , { } ) ;
75
77
testPeg . replaceUsingCreds ( {
76
78
accessToken : "SEKRET" ,
77
79
homeserverUrl : "http://example.com" ,
@@ -83,24 +85,20 @@ describe("MatrixClientPeg", () => {
83
85
it ( "should initialise the rust crypto library by default" , async ( ) => {
84
86
const mockSetValue = jest . spyOn ( SettingsStore , "setValue" ) . mockResolvedValue ( undefined ) ;
85
87
86
- const mockInitCrypto = jest . spyOn ( testPeg . safeGet ( ) , "initCrypto" ) . mockResolvedValue ( undefined ) ;
87
- const mockInitRustCrypto = jest . spyOn ( testPeg . safeGet ( ) , "initRustCrypto" ) . mockResolvedValue ( undefined ) ;
88
-
89
88
const cryptoStoreKey = new Uint8Array ( [ 1 , 2 , 3 , 4 ] ) ;
90
89
await testPeg . start ( { rustCryptoStoreKey : cryptoStoreKey } ) ;
91
- expect ( mockInitCrypto ) . not . toHaveBeenCalled ( ) ;
92
- expect ( mockInitRustCrypto ) . toHaveBeenCalledWith ( { storageKey : cryptoStoreKey } ) ;
90
+ expect ( mockClient . initCrypto ) . not . toHaveBeenCalled ( ) ;
91
+ expect ( mockClient . initRustCrypto ) . toHaveBeenCalledWith ( { storageKey : cryptoStoreKey } ) ;
93
92
94
93
// we should have stashed the setting in the settings store
95
94
expect ( mockSetValue ) . toHaveBeenCalledWith ( "feature_rust_crypto" , null , SettingLevel . DEVICE , true ) ;
96
95
} ) ;
97
96
98
97
it ( "Should migrate existing login" , async ( ) => {
99
98
const mockSetValue = jest . spyOn ( SettingsStore , "setValue" ) . mockResolvedValue ( undefined ) ;
100
- const mockInitRustCrypto = jest . spyOn ( testPeg . safeGet ( ) , "initRustCrypto" ) . mockResolvedValue ( undefined ) ;
101
99
102
100
await testPeg . start ( ) ;
103
- expect ( mockInitRustCrypto ) . toHaveBeenCalledTimes ( 1 ) ;
101
+ expect ( mockClient . initRustCrypto ) . toHaveBeenCalledTimes ( 1 ) ;
104
102
105
103
// we should have stashed the setting in the settings store
106
104
expect ( mockSetValue ) . toHaveBeenCalledWith ( "feature_rust_crypto" , null , SettingLevel . DEVICE , true ) ;
0 commit comments