@@ -16,7 +16,6 @@ limitations under the License.
16
16
17
17
import { MatrixEvent , MatrixEventEvent } from "../../../src/models/event" ;
18
18
import { emitPromise } from "../../test-utils/test-utils" ;
19
- import { EventType } from "../../../src" ;
20
19
import { Crypto } from "../../../src/crypto" ;
21
20
22
21
describe ( "MatrixEvent" , ( ) => {
@@ -88,22 +87,6 @@ describe("MatrixEvent", () => {
88
87
expect ( ev . getWireContent ( ) . ciphertext ) . toBeUndefined ( ) ;
89
88
} ) ;
90
89
91
- it ( "should abort decryption if fails with an error other than a DecryptionError" , async ( ) => {
92
- const ev = new MatrixEvent ( {
93
- type : EventType . RoomMessageEncrypted ,
94
- content : {
95
- body : "Test" ,
96
- } ,
97
- event_id : "$event1:server" ,
98
- } ) ;
99
- await ev . attemptDecryption ( {
100
- decryptEvent : jest . fn ( ) . mockRejectedValue ( new Error ( "Not a DecryptionError" ) ) ,
101
- } as unknown as Crypto ) ;
102
- expect ( ev . isEncrypted ( ) ) . toBeTruthy ( ) ;
103
- expect ( ev . isBeingDecrypted ( ) ) . toBeFalsy ( ) ;
104
- expect ( ev . isDecryptionFailure ( ) ) . toBeFalsy ( ) ;
105
- } ) ;
106
-
107
90
describe ( "applyVisibilityEvent" , ( ) => {
108
91
it ( "should emit VisibilityChange if a change was made" , async ( ) => {
109
92
const ev = new MatrixEvent ( {
@@ -134,6 +117,21 @@ describe("MatrixEvent", () => {
134
117
} ) ;
135
118
} ) ;
136
119
120
+ it ( "should report decryption errors" , async ( ) => {
121
+ const crypto = {
122
+ decryptEvent : jest . fn ( ) . mockRejectedValue ( new Error ( "test error" ) ) ,
123
+ } as unknown as Crypto ;
124
+
125
+ await encryptedEvent . attemptDecryption ( crypto ) ;
126
+ expect ( encryptedEvent . isEncrypted ( ) ) . toBeTruthy ( ) ;
127
+ expect ( encryptedEvent . isBeingDecrypted ( ) ) . toBeFalsy ( ) ;
128
+ expect ( encryptedEvent . isDecryptionFailure ( ) ) . toBeTruthy ( ) ;
129
+ expect ( encryptedEvent . getContent ( ) ) . toEqual ( {
130
+ msgtype : "m.bad.encrypted" ,
131
+ body : "** Unable to decrypt: Error: test error **" ,
132
+ } ) ;
133
+ } ) ;
134
+
137
135
it ( "should retry decryption if a retry is queued" , async ( ) => {
138
136
const eventAttemptDecryptionSpy = jest . spyOn ( encryptedEvent , "attemptDecryption" ) ;
139
137
0 commit comments