Refactor to not have to rely on a spy
This commit is contained in:
parent
4bcf8e7bc3
commit
3a37577252
@ -125,28 +125,35 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
|
utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
|
||||||
return new Promise(function (resolve, reject) {
|
let last_stanza;
|
||||||
sinon.spy(_converse.connection, 'sendIQ');
|
|
||||||
_converse.api.rooms.open(`${room}@${server}`);
|
|
||||||
var view = _converse.chatboxviews.get((room+'@'+server).toLowerCase());
|
|
||||||
|
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
_converse.api.rooms.open(`${room}@${server}`);
|
||||||
|
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 @@
|
|||||||
}).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 () {
|
||||||
|
Loading…
Reference in New Issue
Block a user