2015-07-21 23:24:05 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2017-06-19 11:08:57 +02:00
|
|
|
"jasmine",
|
2015-07-21 23:24:05 +02:00
|
|
|
"mock",
|
2017-04-05 11:01:31 +02:00
|
|
|
"test-utils"], factory);
|
2019-04-06 16:31:42 +02:00
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2015-07-21 23:24:05 +02:00
|
|
|
"use strict";
|
2019-04-06 16:31:42 +02:00
|
|
|
const Strophe = converse.env.Strophe;
|
|
|
|
const $iq = converse.env.$iq;
|
|
|
|
const _ = converse.env._;
|
2015-07-21 23:24:05 +02:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("Service Discovery", function () {
|
2017-07-21 17:38:08 +02:00
|
|
|
|
|
|
|
describe("Whenever converse.js queries a server for its features", function () {
|
2018-03-28 18:38:22 +02:00
|
|
|
|
2018-06-07 15:27:11 +02:00
|
|
|
it("stores the features it receives",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-06-07 15:27:11 +02:00
|
|
|
null, ['discoInitialized'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2019-04-06 16:31:42 +02:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
const IQ_ids = _converse.connection.IQ_ids;
|
2017-07-21 17:38:08 +02:00
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _.filter(IQ_stanzas, function (iq) {
|
2018-03-29 16:12:19 +02:00
|
|
|
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
|
2017-07-21 17:38:08 +02:00
|
|
|
}).length > 0;
|
|
|
|
}, 300).then(function () {
|
|
|
|
/* <iq type='result'
|
|
|
|
* from='plays.shakespeare.lit'
|
|
|
|
* to='romeo@montague.net/orchard'
|
|
|
|
* id='info1'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/disco#info'>
|
|
|
|
* <identity
|
2017-07-21 20:00:57 +02:00
|
|
|
* category='server'
|
|
|
|
* type='im'/>
|
|
|
|
* <identity
|
2017-07-21 17:38:08 +02:00
|
|
|
* category='conference'
|
|
|
|
* type='text'
|
|
|
|
* name='Play-Specific Chatrooms'/>
|
|
|
|
* <identity
|
|
|
|
* category='directory'
|
|
|
|
* type='chatroom'
|
|
|
|
* name='Play-Specific Chatrooms'/>
|
|
|
|
* <feature var='http://jabber.org/protocol/disco#info'/>
|
|
|
|
* <feature var='http://jabber.org/protocol/disco#items'/>
|
|
|
|
* <feature var='http://jabber.org/protocol/muc'/>
|
|
|
|
* <feature var='jabber:iq:register'/>
|
|
|
|
* <feature var='jabber:iq:search'/>
|
|
|
|
* <feature var='jabber:iq:time'/>
|
|
|
|
* <feature var='jabber:iq:version'/>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2018-04-18 17:29:51 +02:00
|
|
|
var stanza = _.find(IQ_stanzas, function (iq) {
|
2018-03-29 16:12:19 +02:00
|
|
|
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
|
2018-04-18 17:29:51 +02:00
|
|
|
});
|
2018-03-29 16:12:19 +02:00
|
|
|
var info_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
|
|
|
|
stanza = $iq({
|
2017-07-21 17:38:08 +02:00
|
|
|
'type': 'result',
|
|
|
|
'from': 'localhost',
|
|
|
|
'to': 'dummy@localhost/resource',
|
|
|
|
'id': info_IQ_id
|
|
|
|
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'})
|
2017-07-21 20:00:57 +02:00
|
|
|
.c('identity', {
|
|
|
|
'category': 'server',
|
|
|
|
'type': 'im'}).up()
|
2017-07-21 17:38:08 +02:00
|
|
|
.c('identity', {
|
|
|
|
'category': 'conference',
|
|
|
|
'type': 'text',
|
|
|
|
'name': 'Play-Specific Chatrooms'}).up()
|
|
|
|
.c('identity', {
|
|
|
|
'category': 'directory',
|
|
|
|
'type': 'chatroom',
|
|
|
|
'name': 'Play-Specific Chatrooms'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'http://jabber.org/protocol/disco#info'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'http://jabber.org/protocol/disco#items'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'jabber:iq:register'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'jabber:iq:time'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'jabber:iq:version'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
_converse.api.disco.entities.get().then(function (entities) {
|
|
|
|
expect(entities.length).toBe(2); // We have an extra entity, which is the user's JID
|
|
|
|
expect(entities.get(_converse.domain).features.length).toBe(5);
|
|
|
|
expect(entities.get(_converse.domain).identities.length).toBe(3);
|
|
|
|
expect(entities.get('localhost').features.where({'var': 'jabber:iq:version'}).length).toBe(1);
|
|
|
|
expect(entities.get('localhost').features.where({'var': 'jabber:iq:time'}).length).toBe(1);
|
|
|
|
expect(entities.get('localhost').features.where({'var': 'jabber:iq:register'}).length).toBe(1);
|
|
|
|
expect(entities.get('localhost').features.where(
|
|
|
|
{'var': 'http://jabber.org/protocol/disco#items'}).length).toBe(1);
|
|
|
|
expect(entities.get('localhost').features.where(
|
|
|
|
{'var': 'http://jabber.org/protocol/disco#info'}).length).toBe(1);
|
2017-07-21 17:38:08 +02:00
|
|
|
|
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
// Converse.js sees that the entity has a disco#items feature,
|
|
|
|
// so it will make a query for it.
|
|
|
|
return _.filter(IQ_stanzas, function (iq) {
|
|
|
|
return iq.nodeTree.querySelector('query[xmlns="http://jabber.org/protocol/disco#items"]');
|
|
|
|
}).length > 0;
|
|
|
|
}, 300).then(function () {
|
|
|
|
/* <iq type='result'
|
|
|
|
* from='catalog.shakespeare.lit'
|
|
|
|
* to='romeo@montague.net/orchard'
|
|
|
|
* id='items2'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/disco#items'>
|
|
|
|
* <item jid='people.shakespeare.lit'
|
|
|
|
* name='Directory of Characters'/>
|
|
|
|
* <item jid='plays.shakespeare.lit'
|
|
|
|
* name='Play-Specific Chatrooms'/>
|
|
|
|
* <item jid='mim.shakespeare.lit'
|
|
|
|
* name='Gateway to Marlowe IM'/>
|
|
|
|
* <item jid='words.shakespeare.lit'
|
|
|
|
* name='Shakespearean Lexicon'/>
|
|
|
|
*
|
|
|
|
* <item jid='catalog.shakespeare.lit'
|
|
|
|
* node='books'
|
|
|
|
* name='Books by and about Shakespeare'/>
|
|
|
|
* <item jid='catalog.shakespeare.lit'
|
|
|
|
* node='clothing'
|
|
|
|
* name='Wear your literary taste with pride'/>
|
|
|
|
* <item jid='catalog.shakespeare.lit'
|
|
|
|
* node='music'
|
|
|
|
* name='Music from the time of Shakespeare'/>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2018-04-18 17:29:51 +02:00
|
|
|
var stanza = _.find(IQ_stanzas, function (iq) {
|
2018-03-29 16:12:19 +02:00
|
|
|
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]');
|
2018-04-18 17:29:51 +02:00
|
|
|
});
|
2018-03-29 16:12:19 +02:00
|
|
|
var items_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
|
|
|
|
stanza = $iq({
|
|
|
|
'type': 'result',
|
|
|
|
'from': 'localhost',
|
|
|
|
'to': 'dummy@localhost/resource',
|
|
|
|
'id': items_IQ_id
|
|
|
|
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#items'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'people.shakespeare.lit',
|
|
|
|
'name': 'Directory of Characters'}).up()
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'plays.shakespeare.lit',
|
|
|
|
'name': 'Play-Specific Chatrooms'}).up()
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'words.shakespeare.lit',
|
|
|
|
'name': 'Gateway to Marlowe IM'}).up()
|
2017-07-21 17:38:08 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
.c('item', {
|
|
|
|
'jid': 'localhost',
|
|
|
|
'node': 'books',
|
|
|
|
'name': 'Books by and about Shakespeare'}).up()
|
|
|
|
.c('item', {
|
|
|
|
'node': 'localhost',
|
|
|
|
'name': 'Wear your literary taste with pride'}).up()
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'localhost',
|
|
|
|
'node': 'music',
|
|
|
|
'name': 'Music from the time of Shakespeare'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2018-09-02 15:07:14 +02:00
|
|
|
return test_utils.waitUntil(() => _converse.disco_entities);
|
|
|
|
}).then(() => {
|
|
|
|
const entities = _converse.disco_entities;
|
2018-03-29 16:12:19 +02:00
|
|
|
expect(entities.length).toBe(2); // We have an extra entity, which is the user's JID
|
|
|
|
expect(entities.get(_converse.domain).items.length).toBe(3);
|
|
|
|
expect(_.includes(entities.get(_converse.domain).items.pluck('jid'), 'people.shakespeare.lit')).toBeTruthy();
|
|
|
|
expect(_.includes(entities.get(_converse.domain).items.pluck('jid'), 'plays.shakespeare.lit')).toBeTruthy();
|
|
|
|
expect(_.includes(entities.get(_converse.domain).items.pluck('jid'), 'words.shakespeare.lit')).toBeTruthy();
|
|
|
|
expect(entities.get(_converse.domain).identities.where({'category': 'conference'}).length).toBe(1);
|
|
|
|
expect(entities.get(_converse.domain).identities.where({'category': 'directory'}).length).toBe(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-07-21 17:38:08 +02:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2016-12-19 10:32:48 +01:00
|
|
|
describe("Whenever converse.js discovers a new server feature", function () {
|
2017-07-21 12:41:16 +02:00
|
|
|
it("emits the serviceDiscovered event",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2017-07-21 12:41:16 +02:00
|
|
|
null, ['discoInitialized'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2019-03-29 21:10:45 +01:00
|
|
|
sinon.spy(_converse.api, "trigger");
|
2017-07-21 12:41:16 +02:00
|
|
|
_converse.disco_entities.get(_converse.domain).features.create({'var': Strophe.NS.MAM});
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger.called).toBe(true);
|
|
|
|
expect(_converse.api.trigger.args[0][0]).toBe('serviceDiscovered');
|
|
|
|
expect(_converse.api.trigger.args[0][1].get('var')).toBe(Strophe.NS.MAM);
|
2017-07-21 12:41:16 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2015-07-21 23:24:05 +02:00
|
|
|
}));
|