|
@@ -2,7 +2,8 @@
|
|
|
|
|
|
const { $iq, Strophe, sizzle, u } = converse.env;
|
|
|
|
|
|
-describe("Chatrooms", function () {
|
|
|
+describe("Groupchats", function () {
|
|
|
+ beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
|
|
|
|
|
|
describe("The auto_register_muc_nickname option", function () {
|
|
|
|
|
@@ -11,42 +12,53 @@ describe("Chatrooms", function () {
|
|
|
async function (_converse) {
|
|
|
|
|
|
const muc_jid = 'coven@chat.shakespeare.lit';
|
|
|
- const room = await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
|
|
+ await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
|
|
|
|
|
- let stanza = await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
|
|
|
- iq => sizzle(`iq[to="${muc_jid}"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
|
- ).pop());
|
|
|
+ const IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
|
|
|
+ let stanza = await u.waitUntil(() => IQ_stanzas.find(
|
|
|
+ iq => sizzle(`iq[type="get"] query[xmlns="${Strophe.NS.MUC_REGISTER}"]`, iq).length));
|
|
|
|
|
|
- expect(Strophe.serialize(stanza))
|
|
|
- .toBe(`<iq id="${stanza.getAttribute('id')}" to="${muc_jid}" `+
|
|
|
- `type="get" xmlns="jabber:client">`+
|
|
|
- `<query xmlns="jabber:iq:register"/></iq>`);
|
|
|
- const result = $iq({
|
|
|
- 'from': room.get('jid'),
|
|
|
- 'id': stanza.getAttribute('id'),
|
|
|
- 'to': _converse.bare_jid,
|
|
|
- 'type': 'result',
|
|
|
- }).c('query', {'xmlns': '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.api.connection.get()._dataRecv(mock.createRequest(result));
|
|
|
- stanza = await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
|
|
|
- iq => sizzle(`iq[to="${muc_jid}"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
|
- ).pop());
|
|
|
+ expect(stanza).toEqualStanza(
|
|
|
+ stx`<iq to="${muc_jid}"
|
|
|
+ type="get"
|
|
|
+ xmlns="jabber:client"
|
|
|
+ id="${stanza.getAttribute('id')}"><query xmlns="jabber:iq:register"/></iq>`);
|
|
|
+
|
|
|
+ _converse.api.connection.get()._dataRecv(mock.createRequest(
|
|
|
+ stx`<iq from="${muc_jid}"
|
|
|
+ id="${stanza.getAttribute('id')}"
|
|
|
+ to="${_converse.session.get('jid')}"
|
|
|
+ xmlns="jabber:client"
|
|
|
+ type="result">
|
|
|
+ <query xmlns='jabber:iq:register'>
|
|
|
+ <x xmlns='jabber:x:data' type='form'>
|
|
|
+ <field
|
|
|
+ type='hidden'
|
|
|
+ var='FORM_TYPE'>
|
|
|
+ <value>http://jabber.org/protocol/muc#register</value>
|
|
|
+ </field>
|
|
|
+ <field
|
|
|
+ label='Desired Nickname'
|
|
|
+ type='text-single'
|
|
|
+ var='muc#register_roomnick'>
|
|
|
+ <required/>
|
|
|
+ </field>
|
|
|
+ </x>
|
|
|
+ </query>
|
|
|
+ </iq>`));
|
|
|
|
|
|
- expect(Strophe.serialize(stanza)).toBe(
|
|
|
- `<iq id="${stanza.getAttribute('id')}" to="${muc_jid}" type="set" xmlns="jabber:client">`+
|
|
|
- `<query xmlns="jabber:iq:register">`+
|
|
|
- `<x type="submit" xmlns="jabber:x:data">`+
|
|
|
- `<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>`);
|
|
|
+ stanza = await u.waitUntil(() => IQ_stanzas.find(
|
|
|
+ iq => sizzle(`iq[type="set"] query[xmlns="${Strophe.NS.MUC_REGISTER}"]`, iq).length));
|
|
|
+
|
|
|
+ expect(stanza).toEqualStanza(
|
|
|
+ stx`<iq xmlns="jabber:client" to="${muc_jid}" type="set" id="${stanza.getAttribute('id')}">
|
|
|
+ <query xmlns="jabber:iq:register">
|
|
|
+ <x xmlns="jabber:x:data" type="submit">
|
|
|
+ <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>`);
|
|
|
}));
|
|
|
|
|
|
it("allows you to automatically deregister your nickname when closing a room",
|
|
@@ -59,18 +71,21 @@ describe("Chatrooms", function () {
|
|
|
let stanza = await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
|
|
|
iq => sizzle(`iq[to="${muc_jid}"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
|
).pop());
|
|
|
- let result = $iq({
|
|
|
- 'from': room.get('jid'),
|
|
|
- 'id': stanza.getAttribute('id'),
|
|
|
- 'to': _converse.bare_jid,
|
|
|
- 'type': 'result',
|
|
|
- }).c('query', {'xmlns': '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');
|
|
|
+ let result = stx`<iq from="${room.get('jid')}"
|
|
|
+ id="${stanza.getAttribute('id')}"
|
|
|
+ to="${_converse.bare_jid}"
|
|
|
+ type="result"
|
|
|
+ xmlns="jabber:client">
|
|
|
+ <query xmlns="jabber:iq:register">
|
|
|
+ <x xmlns="jabber:x:data" type="form">
|
|
|
+ <field label="Desired Nickname"
|
|
|
+ type="text-single"
|
|
|
+ var="muc#register_roomnick">
|
|
|
+ <required/>
|
|
|
+ </field>
|
|
|
+ </x>
|
|
|
+ </query>
|
|
|
+ </iq>`;
|
|
|
_converse.api.connection.get()._dataRecv(mock.createRequest(result));
|
|
|
await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
|
|
|
iq => sizzle(`iq[to="${muc_jid}"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
@@ -82,17 +97,18 @@ describe("Chatrooms", function () {
|
|
|
stanza = await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
|
|
|
iq => sizzle(`iq[to="${muc_jid}"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
|
).pop());
|
|
|
- expect(Strophe.serialize(stanza)).toBe(
|
|
|
- `<iq id="${stanza.getAttribute('id')}" to="${muc_jid}" type="set" xmlns="jabber:client">`+
|
|
|
- `<query xmlns="jabber:iq:register"><remove/></query>`+
|
|
|
- `</iq>`);
|
|
|
-
|
|
|
- result = $iq({
|
|
|
- 'from': room.get('jid'),
|
|
|
- 'id': stanza.getAttribute('id'),
|
|
|
- 'to': _converse.bare_jid,
|
|
|
- 'type': 'result',
|
|
|
- }).c('query', {'xmlns': 'jabber:iq:register'});
|
|
|
+ expect(stanza).toEqualStanza(
|
|
|
+ stx`<iq id="${stanza.getAttribute('id')}" to="${muc_jid}" type="set" xmlns="jabber:client">
|
|
|
+ <query xmlns="jabber:iq:register"><remove/></query>
|
|
|
+ </iq>`);
|
|
|
+
|
|
|
+ result = stx`<iq from="${room.get('jid')}"
|
|
|
+ id="${stanza.getAttribute('id')}"
|
|
|
+ to="${_converse.bare_jid}"
|
|
|
+ type="result"
|
|
|
+ xmlns="jabber:client">
|
|
|
+ <query xmlns="jabber:iq:register"></query>
|
|
|
+ </iq>`;
|
|
|
_converse.api.connection.get()._dataRecv(mock.createRequest(result));
|
|
|
|
|
|
}));
|