2018-09-04 11:39:27 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define(["jasmine", "mock", "test-utils" ], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
|
|
|
const _ = converse.env._,
|
|
|
|
$iq = converse.env.$iq,
|
2018-09-13 14:22:59 +02:00
|
|
|
$pres = converse.env.$pres,
|
2018-09-04 11:39:27 +02:00
|
|
|
Strophe = converse.env.Strophe,
|
2018-09-12 12:33:28 +02:00
|
|
|
sizzle = converse.env.sizzle,
|
2018-09-04 11:39:27 +02:00
|
|
|
u = converse.env.utils;
|
|
|
|
|
2018-09-12 07:20:57 +02:00
|
|
|
describe("Chatrooms", function () {
|
2018-09-12 15:06:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
describe("The /register commmand", function () {
|
|
|
|
|
|
|
|
it("allows you to register your nickname in a room",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-09-12 15:06:08 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
let view;
|
|
|
|
const room_jid = 'coven@chat.shakespeare.lit';
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'romeo')
|
|
|
|
.then(() => {
|
|
|
|
view = _converse.chatboxviews.get(room_jid);
|
|
|
|
const textarea = view.el.querySelector('.chat-textarea')
|
|
|
|
textarea.value = '/register';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-09-12 15:06:08 +02:00
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2018-10-02 17:01:39 +02:00
|
|
|
return test_utils.waitUntil(() => _.filter(
|
2018-09-12 15:06:08 +02:00
|
|
|
_converse.connection.IQ_stanzas,
|
2019-05-20 12:38:33 +02:00
|
|
|
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
|
2018-10-02 17:01:39 +02:00
|
|
|
).pop());
|
2019-05-20 12:38:33 +02:00
|
|
|
}).then(stanza => {
|
|
|
|
expect(Strophe.serialize(stanza))
|
2019-06-03 07:58:51 +02:00
|
|
|
.toBe(`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" `+
|
2018-10-02 17:01:39 +02:00
|
|
|
`type="get" xmlns="jabber:client">`+
|
2018-09-12 15:06:08 +02:00
|
|
|
`<query xmlns="jabber:iq:register"/></iq>`);
|
|
|
|
view = _converse.chatboxviews.get(room_jid);
|
|
|
|
const result = $iq({
|
|
|
|
'from': view.model.get('jid'),
|
|
|
|
'id': stanza.getAttribute('id'),
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'type': 'result',
|
|
|
|
}).c('query', {'type': 'jabber:iq:register'})
|
|
|
|
.c('x', {'xmlns': 'jabber:x:data', 'type': 'form'})
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Desired Nickname',
|
|
|
|
'type': 'text-single',
|
|
|
|
'var': 'muc#register_roomnick'
|
|
|
|
}).c('required');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(result));
|
2018-10-02 17:01:39 +02:00
|
|
|
return test_utils.waitUntil(() => _.filter(
|
2018-09-12 15:06:08 +02:00
|
|
|
_converse.connection.IQ_stanzas,
|
2019-05-20 12:38:33 +02:00
|
|
|
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
|
2018-10-02 17:01:39 +02:00
|
|
|
).pop());
|
2019-05-20 12:38:33 +02:00
|
|
|
}).then(stanza => {
|
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
|
2018-09-12 15:06:08 +02:00
|
|
|
`<query xmlns="jabber:iq:register">`+
|
2018-10-02 17:01:39 +02:00
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
2018-09-12 15:06:08 +02:00
|
|
|
`<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#register</value></field>`+
|
|
|
|
`<field var="muc#register_roomnick"><value>romeo</value></field>`+
|
|
|
|
`</x>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
|
|
|
done();
|
|
|
|
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-09-12 07:20:57 +02:00
|
|
|
describe("The auto_register_muc_nickname option", function () {
|
2018-09-04 11:39:27 +02:00
|
|
|
|
2018-09-12 15:06:08 +02:00
|
|
|
it("allows you to automatically register your nickname when joining a room",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-09-12 07:20:57 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
|
|
|
|
function (done, _converse) {
|
2018-09-04 11:39:27 +02:00
|
|
|
|
2018-09-12 07:20:57 +02:00
|
|
|
let view;
|
2019-05-20 12:38:33 +02:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
2018-09-12 07:20:57 +02:00
|
|
|
const room_jid = 'coven@chat.shakespeare.lit';
|
2018-09-13 14:22:59 +02:00
|
|
|
_converse.api.rooms.open(room_jid, {'nick': 'romeo'})
|
2018-09-12 07:20:57 +02:00
|
|
|
.then(() => {
|
2019-05-20 12:38:33 +02:00
|
|
|
return test_utils.waitUntil(() => _.filter(
|
2018-09-13 14:22:59 +02:00
|
|
|
IQ_stanzas,
|
2019-05-20 12:38:33 +02:00
|
|
|
iq => iq.querySelector(
|
2018-09-13 14:22:59 +02:00
|
|
|
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
|
2019-05-20 12:38:33 +02:00
|
|
|
)).pop());
|
2018-09-13 14:22:59 +02:00
|
|
|
}).then(stanza => {
|
|
|
|
const features_stanza = $iq({
|
|
|
|
'from': room_jid,
|
|
|
|
'id': stanza.getAttribute('id'),
|
2019-06-03 07:58:51 +02:00
|
|
|
'to': 'romeo@montague.lit/desktop',
|
2018-09-13 14:22:59 +02:00
|
|
|
'type': 'result'
|
|
|
|
}).c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {
|
|
|
|
'category': 'conference',
|
|
|
|
'name': 'A Dark Cave',
|
|
|
|
'type': 'text'
|
|
|
|
}).up()
|
|
|
|
.c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('feature', {'var': 'jabber:iq:register'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
2018-09-12 07:20:57 +02:00
|
|
|
view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
2018-09-13 14:22:59 +02:00
|
|
|
return test_utils.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
|
|
|
|
}).then(stanza => {
|
|
|
|
// The user has just entered the room (because join was called)
|
|
|
|
// and receives their own presence from the server.
|
2019-03-04 17:49:44 +01:00
|
|
|
// See example 24: https://xmpp.org/extensions/xep-0045.html#enter-pres
|
2018-09-13 14:22:59 +02:00
|
|
|
const presence = $pres({
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
from: room_jid,
|
|
|
|
id: u.getUniqueId()
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'owner',
|
|
|
|
jid: _converse.bare_jid,
|
|
|
|
role: 'moderator'
|
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-10-02 17:01:39 +02:00
|
|
|
return test_utils.waitUntil(() => _.filter(
|
2018-09-12 07:20:57 +02:00
|
|
|
_converse.connection.IQ_stanzas,
|
2019-05-20 12:38:33 +02:00
|
|
|
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
|
2018-10-02 17:01:39 +02:00
|
|
|
).pop());
|
2019-05-20 12:38:33 +02:00
|
|
|
}).then(stanza => {
|
|
|
|
expect(Strophe.serialize(stanza))
|
2019-06-03 07:58:51 +02:00
|
|
|
.toBe(`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" `+
|
2018-10-02 17:01:39 +02:00
|
|
|
`type="get" xmlns="jabber:client">`+
|
2018-09-12 07:20:57 +02:00
|
|
|
`<query xmlns="jabber:iq:register"/></iq>`);
|
|
|
|
view = _converse.chatboxviews.get(room_jid);
|
|
|
|
const result = $iq({
|
|
|
|
'from': view.model.get('jid'),
|
|
|
|
'id': stanza.getAttribute('id'),
|
|
|
|
'to': _converse.bare_jid,
|
2018-09-12 12:33:28 +02:00
|
|
|
'type': 'result',
|
|
|
|
}).c('query', {'type': 'jabber:iq:register'})
|
|
|
|
.c('x', {'xmlns': 'jabber:x:data', 'type': 'form'})
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Desired Nickname',
|
|
|
|
'type': 'text-single',
|
|
|
|
'var': 'muc#register_roomnick'
|
|
|
|
}).c('required');
|
2018-09-12 07:20:57 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(result));
|
2018-10-02 17:01:39 +02:00
|
|
|
return test_utils.waitUntil(() => _.filter(
|
2018-09-12 12:33:28 +02:00
|
|
|
_converse.connection.IQ_stanzas,
|
2019-05-20 12:38:33 +02:00
|
|
|
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
|
2018-10-02 17:01:39 +02:00
|
|
|
).pop());
|
2019-05-20 12:38:33 +02:00
|
|
|
}).then(stanza => {
|
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
|
2018-09-12 12:33:28 +02:00
|
|
|
`<query xmlns="jabber:iq:register">`+
|
2018-10-02 17:01:39 +02:00
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
2018-09-12 12:33:28 +02:00
|
|
|
`<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#register</value></field>`+
|
|
|
|
`<field var="muc#register_roomnick"><value>romeo</value></field>`+
|
|
|
|
`</x>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
2018-09-12 07:20:57 +02:00
|
|
|
done();
|
|
|
|
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
|
|
|
}));
|
|
|
|
});
|
2018-09-04 11:39:27 +02:00
|
|
|
});
|
|
|
|
}));
|