You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-30 04:23:07 +03:00
Add new decryptExistingEvent
test helper (#4133)
* grammar fix * IEncryptionResult -> EncryptionResult These are the same thing; the former is the old name. * Support setting event IDs * Helper for decrypting existing decryption failures
This commit is contained in:
committed by
GitHub
parent
0b290fffa1
commit
9f1d0c3896
@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { mkDecryptionFailureMatrixEvent, mkEncryptedMatrixEvent, mkMatrixEvent } from "../../src/testing";
|
||||
import {
|
||||
decryptExistingEvent,
|
||||
mkDecryptionFailureMatrixEvent,
|
||||
mkEncryptedMatrixEvent,
|
||||
mkMatrixEvent,
|
||||
} from "../../src/testing";
|
||||
import { EventType } from "../../src";
|
||||
import { DecryptionFailureCode } from "../../src/crypto-api";
|
||||
|
||||
@ -88,4 +93,28 @@ describe("testing", () => {
|
||||
expect(event.isState()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("decryptExistingEvent", () => {
|
||||
it("decrypts an event", async () => {
|
||||
const event = await mkDecryptionFailureMatrixEvent({
|
||||
sender: "@alice:test",
|
||||
roomId: "!test:room",
|
||||
code: DecryptionFailureCode.UNKNOWN_ERROR,
|
||||
msg: "blah",
|
||||
});
|
||||
|
||||
expect(event.isEncrypted()).toBe(true);
|
||||
expect(event.isDecryptionFailure()).toBe(true);
|
||||
await decryptExistingEvent(event, {
|
||||
plainContent: { body: "blah" },
|
||||
plainType: "m.room.test",
|
||||
});
|
||||
|
||||
expect(event.isEncrypted()).toBe(true);
|
||||
expect(event.isDecryptionFailure()).toBe(false);
|
||||
expect(event.decryptionFailureReason).toBe(null);
|
||||
expect(event.getContent()).toEqual({ body: "blah" });
|
||||
expect(event.getType()).toEqual("m.room.test");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user