@@ -20,7 +20,6 @@ import { IDBFactory } from "fake-indexeddb";
20
20
import { IndexedDBCryptoStore } from "matrix-js-sdk/src/matrix" ;
21
21
22
22
import * as StorageManager from "../../src/utils/StorageManager" ;
23
- import SettingsStore from "../../src/settings/SettingsStore" ;
24
23
25
24
const LEGACY_CRYPTO_STORE_NAME = "matrix-js-sdk:crypto" ;
26
25
const RUST_CRYPTO_STORE_NAME = "matrix-js-sdk::matrix-sdk-crypto" ;
@@ -77,98 +76,54 @@ describe("StorageManager", () => {
77
76
indexedDB = new IDBFactory ( ) ;
78
77
} ) ;
79
78
80
- describe ( "with `feature_rust_crypto` enabled" , ( ) => {
81
- beforeEach ( ( ) => {
82
- jest . spyOn ( SettingsStore , "getValue" ) . mockImplementation ( async ( key ) => {
83
- if ( key === "feature_rust_crypto" ) {
84
- return true ;
85
- }
86
- throw new Error ( `Unknown key ${ key } ` ) ;
87
- } ) ;
88
- } ) ;
79
+ it ( "should not be ok if sync store but no crypto store" , async ( ) => {
80
+ const result = await StorageManager . checkConsistency ( ) ;
81
+ expect ( result . healthy ) . toBe ( true ) ;
82
+ expect ( result . dataInCryptoStore ) . toBe ( false ) ;
83
+ } ) ;
89
84
90
- it ( "should not be ok if sync store but no crypto store" , async ( ) => {
91
- const result = await StorageManager . checkConsistency ( ) ;
92
- expect ( result . healthy ) . toBe ( true ) ;
93
- expect ( result . dataInCryptoStore ) . toBe ( false ) ;
94
- } ) ;
85
+ it ( "should be ok if sync store and a rust crypto store" , async ( ) => {
86
+ await createDB ( RUST_CRYPTO_STORE_NAME ) ;
95
87
96
- it ( "should be ok if sync store and a rust crypto store" , async ( ) => {
97
- await createDB ( RUST_CRYPTO_STORE_NAME ) ;
88
+ const result = await StorageManager . checkConsistency ( ) ;
89
+ expect ( result . healthy ) . toBe ( true ) ;
90
+ expect ( result . dataInCryptoStore ) . toBe ( true ) ;
91
+ } ) ;
92
+
93
+ describe ( "without rust store" , ( ) => {
94
+ it ( "should be ok if there is non migrated legacy crypto store" , async ( ) => {
95
+ await populateLegacyStore ( undefined ) ;
98
96
99
97
const result = await StorageManager . checkConsistency ( ) ;
100
98
expect ( result . healthy ) . toBe ( true ) ;
101
99
expect ( result . dataInCryptoStore ) . toBe ( true ) ;
102
100
} ) ;
103
101
104
- describe ( "without rust store" , ( ) => {
105
- it ( "should be ok if there is non migrated legacy crypto store" , async ( ) => {
106
- await populateLegacyStore ( undefined ) ;
107
-
108
- const result = await StorageManager . checkConsistency ( ) ;
109
- expect ( result . healthy ) . toBe ( true ) ;
110
- expect ( result . dataInCryptoStore ) . toBe ( true ) ;
111
- } ) ;
112
-
113
- it ( "should be ok if legacy store in MigrationState `NOT_STARTED`" , async ( ) => {
114
- await populateLegacyStore ( 0 /* MigrationState.NOT_STARTED*/ ) ;
115
-
116
- const result = await StorageManager . checkConsistency ( ) ;
117
- expect ( result . healthy ) . toBe ( true ) ;
118
- expect ( result . dataInCryptoStore ) . toBe ( true ) ;
119
- } ) ;
120
-
121
- it ( "should not be ok if MigrationState greater than `NOT_STARTED`" , async ( ) => {
122
- await populateLegacyStore ( 1 /*INITIAL_DATA_MIGRATED*/ ) ;
123
-
124
- const result = await StorageManager . checkConsistency ( ) ;
125
- expect ( result . healthy ) . toBe ( true ) ;
126
- expect ( result . dataInCryptoStore ) . toBe ( false ) ;
127
- } ) ;
102
+ it ( "should be ok if legacy store in MigrationState `NOT_STARTED`" , async ( ) => {
103
+ await populateLegacyStore ( 0 /* MigrationState.NOT_STARTED*/ ) ;
128
104
129
- it ( "should not be healthy if no indexeddb" , async ( ) => {
130
- // eslint-disable-next-line no-global-assign
131
- indexedDB = { } as IDBFactory ;
132
-
133
- const result = await StorageManager . checkConsistency ( ) ;
134
- expect ( result . healthy ) . toBe ( false ) ;
135
-
136
- // eslint-disable-next-line no-global-assign
137
- indexedDB = new IDBFactory ( ) ;
138
- } ) ;
139
- } ) ;
140
- } ) ;
141
-
142
- describe ( "with `feature_rust_crypto` disabled" , ( ) => {
143
- beforeEach ( ( ) => {
144
- jest . spyOn ( SettingsStore , "getValue" ) . mockImplementation ( async ( key ) => {
145
- if ( key === "feature_rust_crypto" ) {
146
- return false ;
147
- }
148
- throw new Error ( `Unknown key ${ key } ` ) ;
149
- } ) ;
150
- } ) ;
151
-
152
- it ( "should not be ok if sync store but no crypto store" , async ( ) => {
153
105
const result = await StorageManager . checkConsistency ( ) ;
154
106
expect ( result . healthy ) . toBe ( true ) ;
155
- expect ( result . dataInCryptoStore ) . toBe ( false ) ;
107
+ expect ( result . dataInCryptoStore ) . toBe ( true ) ;
156
108
} ) ;
157
109
158
- it ( "should not be ok if sync store but no crypto store and a rust store " , async ( ) => {
159
- await createDB ( RUST_CRYPTO_STORE_NAME ) ;
110
+ it ( "should not be ok if MigrationState greater than `NOT_STARTED` " , async ( ) => {
111
+ await populateLegacyStore ( 1 /*INITIAL_DATA_MIGRATED*/ ) ;
160
112
161
113
const result = await StorageManager . checkConsistency ( ) ;
162
114
expect ( result . healthy ) . toBe ( true ) ;
163
115
expect ( result . dataInCryptoStore ) . toBe ( false ) ;
164
116
} ) ;
165
117
166
- it ( "should be healthy if sync store and a legacy crypto store" , async ( ) => {
167
- await createDB ( LEGACY_CRYPTO_STORE_NAME ) ;
118
+ it ( "should not be healthy if no indexeddb" , async ( ) => {
119
+ // eslint-disable-next-line no-global-assign
120
+ indexedDB = { } as IDBFactory ;
168
121
169
122
const result = await StorageManager . checkConsistency ( ) ;
170
- expect ( result . healthy ) . toBe ( true ) ;
171
- expect ( result . dataInCryptoStore ) . toBe ( true ) ;
123
+ expect ( result . healthy ) . toBe ( false ) ;
124
+
125
+ // eslint-disable-next-line no-global-assign
126
+ indexedDB = new IDBFactory ( ) ;
172
127
} ) ;
173
128
} ) ;
174
129
} ) ;
0 commit comments