spec/integ/matrix-client-crypto.spec.js
function expectAliClaimKeys() {
    return bobTestClient.awaitOneTimeKeyUpload().then((keys) => {
        aliTestClient.httpBackend.when(
            "POST", "/keys/claim",
        ).respond(200, function(path, content) {
            const claimType = content.one_time_keys[bobUserId][bobDeviceId];
            expect(claimType).toEqual("signed_curve25519");
            let keyId = null;
            for (keyId in keys) {
                if (bobTestClient.oneTimeKeys.hasOwnProperty(keyId)) {
                    if (keyId.indexOf(claimType + ":") === 0) {
                        break;
                    }
                }
            }
            const result = {};
            result[bobUserId] = {};
            result[bobUserId][bobDeviceId] = {};
            result[bobUserId][bobDeviceId][keyId] = keys[keyId];
            return {one_time_keys: result};
        });
    }).then(() => {
        // it can take a while to process the key query, so give it some extra
        // time, and make sure the claim actually happens rather than ploughing on
        // confusingly.
        return aliTestClient.httpBackend.flush("/keys/claim", 1, 500).then((r) => {
            expect(r).toEqual(1, "Ali did not claim Bob's keys");
        });
    });
}
function expectAliClaimKeys() {
    return bobTestClient.awaitOneTimeKeyUpload().then((keys) => {
        aliTestClient.httpBackend.when(
            "POST", "/keys/claim",
        ).respond(200, function(path, content) {
            const claimType = content.one_time_keys[bobUserId][bobDeviceId];
            expect(claimType).toEqual("signed_curve25519");
            let keyId = null;
            for (keyId in keys) {
                if (bobTestClient.oneTimeKeys.hasOwnProperty(keyId)) {
                    if (keyId.indexOf(claimType + ":") === 0) {
                        break;
                    }
                }
            }
            const result = {};
            result[bobUserId] = {};
            result[bobUserId][bobDeviceId] = {};
            result[bobUserId][bobDeviceId][keyId] = keys[keyId];
            return {one_time_keys: result};
        });
    }).then(() => {
        // it can take a while to process the key query, so give it some extra
        // time, and make sure the claim actually happens rather than ploughing on
        // confusingly.
        return aliTestClient.httpBackend.flush("/keys/claim", 1, 500).then((r) => {
            expect(r).toEqual(1, "Ali did not claim Bob's keys");
        });
    });
}
function expectAliClaimKeys ( ) { return bobTestClient . awaitOneTimeKeyUpload ( ) . then ( ( keys ) => { aliTestClient . httpBackend . when ( "POST" , "/keys/claim" , ) . respond ( 200 , function ( path , content ) { const claimType = content . one_time_keys [ bobUserId ] [ bobDeviceId ] ; expect ( claimType ) . toEqual ( "signed_curve25519" ) ; let keyId = null ; for ( keyId in keys ) { if ( bobTestClient . oneTimeKeys . hasOwnProperty ( keyId ) ) { if ( keyId . indexOf ( claimType + ":" ) === 0 ) { break ; } } } const result = { } ; result [ bobUserId ] = { } ; result [ bobUserId ] [ bobDeviceId ] = { } ; result [ bobUserId ] [ bobDeviceId ] [ keyId ] = keys [ keyId ] ; return { one_time_keys : result } ; } ) ; } ) . then ( ( ) => { // it can take a while to process the key query, so give it some extra // time, and make sure the claim actually happens rather than ploughing on // confusingly. return aliTestClient . httpBackend . flush ( "/keys/claim" , 1 , 500 ) . then ( ( r ) => { expect ( r ) . toEqual ( 1 , "Ali did not claim Bob's keys" ) ; } ) ; } ) ; }
Set an expectation that ali will claim one of bob's keys; then flush the http request.

@return {promise} resolves once the http request has completed.
Set an expectation that ali will claim one of bob s keys ; then flush the http request .