spec/integ/megolm-integ.spec.js
function encryptMegolmEvent(opts) {
    expect(opts.senderKey).toBeTruthy();
    expect(opts.groupSession).toBeTruthy();

    const plaintext = opts.plaintext || {};
    if (!plaintext.content) {
        plaintext.content = {
            body: '42',
            msgtype: "m.text",
        };
    }
    if (!plaintext.type) {
        plaintext.type = "m.room.message";
    }
    if (!plaintext.room_id) {
        expect(opts.room_id).toBeTruthy();
        plaintext.room_id = opts.room_id;
    }

    return {
        event_id: 'test_megolm_event',
        content: {
            algorithm: "m.megolm.v1.aes-sha2",
            ciphertext: opts.groupSession.encrypt(JSON.stringify(plaintext)),
            device_id: "testDevice",
            sender_key: opts.senderKey,
            session_id: opts.groupSession.session_id(),
        },
        type: "m.room.encrypted",
    };
}
function encryptMegolmEvent(opts) {
    expect(opts.senderKey).toBeTruthy();
    expect(opts.groupSession).toBeTruthy();

    const plaintext = opts.plaintext || {};
    if (!plaintext.content) {
        plaintext.content = {
            body: '42',
            msgtype: "m.text",
        };
    }
    if (!plaintext.type) {
        plaintext.type = "m.room.message";
    }
    if (!plaintext.room_id) {
        expect(opts.room_id).toBeTruthy();
        plaintext.room_id = opts.room_id;
    }

    return {
        event_id: 'test_megolm_event',
        content: {
            algorithm: "m.megolm.v1.aes-sha2",
            ciphertext: opts.groupSession.encrypt(JSON.stringify(plaintext)),
            device_id: "testDevice",
            sender_key: opts.senderKey,
            session_id: opts.groupSession.session_id(),
        },
        type: "m.room.encrypted",
    };
}
function encryptMegolmEvent ( opts ) { expect ( opts . senderKey ) . toBeTruthy ( ) ; expect ( opts . groupSession ) . toBeTruthy ( ) ; const plaintext = opts . plaintext || { } ; if ( ! plaintext . content ) { plaintext . content = { body : '42' , msgtype : "m.text" , } ; } if ( ! plaintext . type ) { plaintext . type = "m.room.message" ; } if ( ! plaintext . room_id ) { expect ( opts . room_id ) . toBeTruthy ( ) ; plaintext . room_id = opts . room_id ; } return { event_id : 'test_megolm_event' , content : { algorithm : "m.megolm.v1.aes-sha2" , ciphertext : opts . groupSession . encrypt ( JSON . stringify ( plaintext ) ) , device_id : "testDevice" , sender_key : opts . senderKey , session_id : opts . groupSession . session_id ( ) , } , type : "m.room.encrypted" , } ; }
encrypt an event with megolm

@param {object} opts
@param {string} opts.senderKey
@param {Olm.OutboundGroupSession} opts.groupSession
@param {object=} opts.plaintext
@param {string=} opts.room_id

@return {object} event
encrypt an event with megolm