Commit 3a375772 authored by JC Brand's avatar JC Brand

Refactor to not have to rely on a spy

parent 4bcf8e7b
...@@ -125,28 +125,35 @@ ...@@ -125,28 +125,35 @@
}; };
utils.openAndEnterChatRoom = function (_converse, room, server, nick) { utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
let last_stanza;
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
sinon.spy(_converse.connection, 'sendIQ');
_converse.api.rooms.open(`${room}@${server}`); _converse.api.rooms.open(`${room}@${server}`);
var view = _converse.chatboxviews.get((room+'@'+server).toLowerCase()); const view = _converse.chatboxviews.get((room+'@'+server).toLowerCase());
// We pretend this is a new room, so no disco info is returned. // We pretend this is a new room, so no disco info is returned.
var IQ_id = _converse.connection.sendIQ.firstCall.returnValue; last_stanza = _.last(_converse.connection.IQ_stanzas).nodeTree;
var features_stanza = $iq({ const IQ_id = last_stanza.getAttribute('id');
const features_stanza = $iq({
'from': room+'@'+server, 'from': room+'@'+server,
'id': IQ_id, 'id': IQ_id,
'to': nick+'@'+server+'/desktop', 'to': nick+'@'+server,
'type': 'error' 'type': 'error'
}).c('error', {'type': 'cancel'}) }).c('error', {'type': 'cancel'})
.c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"}); .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
_converse.connection._dataRecv(utils.createRequest(features_stanza)); _converse.connection._dataRecv(utils.createRequest(features_stanza));
utils.waitUntil(function () { utils.waitUntil(() => {
return _converse.connection.sendIQ.secondCall; return _.filter(
_converse.connection.IQ_stanzas, (node) => node.nodeTree.querySelector('query').getAttribute('node') === 'x-roomuser-item'
).length
}).then(function () { }).then(function () {
const last_stanza = _.filter(
_converse.connection.IQ_stanzas, (node) => node.nodeTree.querySelector('query').getAttribute('node') === 'x-roomuser-item'
).pop().nodeTree;
// The XMPP server returns the reserved nick for this user. // The XMPP server returns the reserved nick for this user.
IQ_id = _converse.connection.sendIQ.secondCall.returnValue; const IQ_id = last_stanza.getAttribute('id');
var stanza = $iq({ const stanza = $iq({
'type': 'result', 'type': 'result',
'id': IQ_id, 'id': IQ_id,
'from': view.model.get('jid'), 'from': view.model.get('jid'),
...@@ -169,10 +176,9 @@ ...@@ -169,10 +176,9 @@
}).up() }).up()
.c('status').attrs({code:'110'}); .c('status').attrs({code:'110'});
_converse.connection._dataRecv(utils.createRequest(presence)); _converse.connection._dataRecv(utils.createRequest(presence));
_converse.connection.sendIQ.restore();
resolve(); resolve();
}).catch(_.partial(console.error, _)); });
}).catch(_.partial(console.error, _)); });
}; };
utils.clearBrowserStorage = function () { utils.clearBrowserStorage = function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment