xmpp.chapril.org-conversejs/spec/ping.js

54 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-02-19 14:02:42 +01:00
(function (root, factory) {
define(["jasmine", "mock", "test-utils"], factory);
} (this, function (jasmine, mock, test_utils) {
2016-02-19 14:02:42 +01:00
"use strict";
describe("XMPP Ping", function () {
describe("Ping and pong handlers", function () {
it("are registered when _converse.js is connected",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
2017-04-05 11:01:31 +02:00
spyOn(_converse, 'registerPingHandler').and.callThrough();
spyOn(_converse, 'registerPongHandler').and.callThrough();
_converse.emit('connected');
expect(_converse.registerPingHandler).toHaveBeenCalled();
expect(_converse.registerPongHandler).toHaveBeenCalled();
done();
}));
it("are registered when _converse.js reconnected",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
2017-04-05 11:01:31 +02:00
spyOn(_converse, 'registerPingHandler').and.callThrough();
spyOn(_converse, 'registerPongHandler').and.callThrough();
_converse.emit('reconnected');
expect(_converse.registerPingHandler).toHaveBeenCalled();
expect(_converse.registerPongHandler).toHaveBeenCalled();
done();
}));
});
2016-02-19 14:02:42 +01:00
describe("An IQ stanza", function () {
it("is sent out when _converse.js pings a server", mock.initConverse(function (_converse) {
2016-02-19 14:02:42 +01:00
var sent_stanza, IQ_id;
var sendIQ = _converse.connection.sendIQ;
2017-04-05 11:01:31 +02:00
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
2016-02-19 14:02:42 +01:00
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
_converse.ping();
2016-02-19 14:02:42 +01:00
expect(sent_stanza.toLocaleString()).toBe(
`<iq id="${IQ_id}" to="localhost" type="get" xmlns="jabber:client">`+
`<ping xmlns="urn:xmpp:ping"/>`+
`</iq>`);
}));
});
});
2016-02-19 14:02:42 +01:00
}));