2018-06-06 11:07:59 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define(["jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
|
|
|
"use strict";
|
2018-11-29 11:39:00 +01:00
|
|
|
const $iq = converse.env.$iq;
|
|
|
|
const Strophe = converse.env.Strophe;
|
|
|
|
const _ = converse.env._;
|
2018-05-29 12:00:23 +02:00
|
|
|
const sizzle = converse.env.sizzle;
|
|
|
|
const u = converse.env.utils;
|
2018-06-06 11:07:59 +02:00
|
|
|
|
|
|
|
describe("XEP-0357 Push Notifications", function () {
|
|
|
|
|
2018-06-07 16:25:59 +02:00
|
|
|
it("can be enabled",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(null,
|
2018-06-06 11:07:59 +02:00
|
|
|
['rosterGroupsFetched'], {
|
2018-06-11 14:17:34 +02:00
|
|
|
'push_app_servers': [{
|
2018-06-07 16:25:59 +02:00
|
|
|
'jid': 'push-5@client.example',
|
|
|
|
'node': 'yxs32uqsflafdk3iuqo'
|
|
|
|
}]
|
2018-11-29 11:39:00 +01:00
|
|
|
}, async function (done, _converse) {
|
2018-06-06 11:07:59 +02:00
|
|
|
|
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
expect(_converse.session.get('push_enabled')).toBeFalsy();
|
|
|
|
|
2018-11-29 11:39:00 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-06-11 14:17:34 +02:00
|
|
|
_converse, _converse.push_app_servers[0].jid,
|
2018-06-06 11:07:59 +02:00
|
|
|
[{'category': 'pubsub', 'type':'push'}],
|
2018-11-29 11:39:00 +01:00
|
|
|
['urn:xmpp:push:0'], [], 'info');
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-06-06 11:07:59 +02:00
|
|
|
_converse,
|
|
|
|
_converse.bare_jid,
|
|
|
|
[{'category': 'account', 'type':'registered'}],
|
2018-11-29 11:39:00 +01:00
|
|
|
['urn:xmpp:push:0'], [], 'info');
|
2019-07-11 22:50:30 +02:00
|
|
|
const stanza = await u.waitUntil(() =>
|
2019-05-20 12:38:33 +02:00
|
|
|
_.filter(IQ_stanzas, iq => iq.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
|
2018-11-29 11:39:00 +01:00
|
|
|
);
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(stanza)).toEqual(
|
2018-11-29 11:39:00 +01:00
|
|
|
`<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
|
|
|
'<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+
|
|
|
|
'</iq>'
|
|
|
|
)
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest($iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'result',
|
|
|
|
'id': stanza.getAttribute('id')
|
|
|
|
})));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.session.get('push_enabled'));
|
2018-11-29 11:39:00 +01:00
|
|
|
done();
|
2018-08-09 10:41:31 +02:00
|
|
|
}));
|
|
|
|
|
2018-09-13 10:51:56 +02:00
|
|
|
it("can be enabled for a MUC domain",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(null,
|
2018-08-09 10:41:31 +02:00
|
|
|
['rosterGroupsFetched'], {
|
2018-09-13 14:22:59 +02:00
|
|
|
'enable_muc_push': true,
|
2018-08-09 10:41:31 +02:00
|
|
|
'push_app_servers': [{
|
|
|
|
'jid': 'push-5@client.example',
|
|
|
|
'node': 'yxs32uqsflafdk3iuqo'
|
|
|
|
}]
|
2018-11-29 11:39:00 +01:00
|
|
|
}, async function (done, _converse) {
|
2018-08-09 10:41:31 +02:00
|
|
|
|
2018-05-29 12:00:23 +02:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
2018-11-29 11:39:00 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-08-09 10:41:31 +02:00
|
|
|
_converse, _converse.push_app_servers[0].jid,
|
|
|
|
[{'category': 'pubsub', 'type':'push'}],
|
2018-11-29 11:39:00 +01:00
|
|
|
['urn:xmpp:push:0'], [], 'info');
|
2018-05-29 12:00:23 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
|
|
|
_converse, _converse.bare_jid, [],
|
|
|
|
['urn:xmpp:push:0']);
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
let iq = await u.waitUntil(() => _.filter(
|
2018-05-29 12:00:23 +02:00
|
|
|
IQ_stanzas,
|
|
|
|
iq => sizzle(`iq[type="set"] enable[xmlns="${Strophe.NS.PUSH}"]`, iq).length
|
|
|
|
).pop());
|
|
|
|
|
|
|
|
expect(Strophe.serialize(iq)).toBe(
|
|
|
|
`<iq id="${iq.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>`+
|
|
|
|
`</iq>`
|
|
|
|
);
|
2019-06-03 07:58:51 +02:00
|
|
|
const result = u.toStanza(`<iq type="result" id="${iq.getAttribute('id')}" to="romeo@montague.lit" />`);
|
2018-05-29 12:00:23 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(result));
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.session.get('push_enabled'));
|
2018-05-29 12:00:23 +02:00
|
|
|
expect(_converse.session.get('push_enabled').length).toBe(1);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(_.includes(_converse.session.get('push_enabled'), 'romeo@montague.lit')).toBe(true);
|
2018-05-29 12:00:23 +02:00
|
|
|
|
2019-07-03 14:18:46 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'coven@chat.shakespeare.lit', 'oldhag');
|
2018-11-29 11:39:00 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
|
|
|
_converse, 'chat.shakespeare.lit',
|
|
|
|
[{'category': 'account', 'type':'registered'}],
|
|
|
|
['urn:xmpp:push:0'], [], 'info');
|
2019-07-11 22:50:30 +02:00
|
|
|
iq = await u.waitUntil(() => _.filter(
|
2018-05-29 12:00:23 +02:00
|
|
|
IQ_stanzas,
|
|
|
|
iq => sizzle(`iq[type="set"][to="chat.shakespeare.lit"] enable[xmlns="${Strophe.NS.PUSH}"]`, iq).length
|
|
|
|
).pop());
|
|
|
|
|
|
|
|
expect(Strophe.serialize(iq)).toEqual(
|
|
|
|
`<iq id="${iq.getAttribute('id')}" to="chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
|
2018-11-29 11:39:00 +01:00
|
|
|
'<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+
|
|
|
|
'</iq>'
|
|
|
|
);
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest($iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'result',
|
2018-05-29 12:00:23 +02:00
|
|
|
'id': iq.getAttribute('id')
|
2018-11-29 11:39:00 +01:00
|
|
|
})));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _.includes(_converse.session.get('push_enabled'), 'chat.shakespeare.lit'));
|
2018-11-29 11:39:00 +01:00
|
|
|
done();
|
2018-06-06 11:07:59 +02:00
|
|
|
}));
|
|
|
|
|
2018-06-07 16:25:59 +02:00
|
|
|
it("can be disabled",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(null,
|
2018-06-07 16:25:59 +02:00
|
|
|
['rosterGroupsFetched'], {
|
2018-06-11 14:17:34 +02:00
|
|
|
'push_app_servers': [{
|
2018-06-07 16:25:59 +02:00
|
|
|
'jid': 'push-5@client.example',
|
|
|
|
'node': 'yxs32uqsflafdk3iuqo',
|
|
|
|
'disable': true
|
|
|
|
}]
|
2018-11-29 11:39:00 +01:00
|
|
|
}, async function (done, _converse) {
|
2018-06-07 16:25:59 +02:00
|
|
|
|
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
expect(_converse.session.get('push_enabled')).toBeFalsy();
|
|
|
|
|
2018-11-29 11:39:00 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-06-07 16:25:59 +02:00
|
|
|
_converse,
|
|
|
|
_converse.bare_jid,
|
|
|
|
[{'category': 'account', 'type':'registered'}],
|
2018-11-29 11:39:00 +01:00
|
|
|
['urn:xmpp:push:0'], [], 'info');
|
2019-07-11 22:50:30 +02:00
|
|
|
const stanza = await u.waitUntil(
|
2019-05-20 12:38:33 +02:00
|
|
|
() => _.filter(IQ_stanzas, iq => iq.querySelector('iq[type="set"] disable[xmlns="urn:xmpp:push:0"]')).pop()
|
2018-11-29 11:39:00 +01:00
|
|
|
);
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(stanza)).toEqual(
|
2018-11-29 11:39:00 +01:00
|
|
|
`<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
|
|
|
'<disable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+
|
|
|
|
'</iq>'
|
2018-11-29 13:22:58 +01:00
|
|
|
);
|
2018-11-29 11:39:00 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest($iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'result',
|
|
|
|
'id': stanza.getAttribute('id')
|
|
|
|
})));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.session.get('push_enabled'))
|
2018-11-29 11:39:00 +01:00
|
|
|
done();
|
2018-06-07 16:25:59 +02:00
|
|
|
}));
|
|
|
|
|
2018-06-06 11:07:59 +02:00
|
|
|
|
|
|
|
it("can require a secret token to be included",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(null,
|
2018-06-06 11:07:59 +02:00
|
|
|
['rosterGroupsFetched'], {
|
2018-06-11 14:17:34 +02:00
|
|
|
'push_app_servers': [{
|
2018-06-07 16:25:59 +02:00
|
|
|
'jid': 'push-5@client.example',
|
|
|
|
'node': 'yxs32uqsflafdk3iuqo',
|
|
|
|
'secret': 'eruio234vzxc2kla-91'
|
|
|
|
}]
|
2018-11-29 11:39:00 +01:00
|
|
|
}, async function (done, _converse) {
|
2018-06-06 11:07:59 +02:00
|
|
|
|
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
expect(_converse.session.get('push_enabled')).toBeFalsy();
|
|
|
|
|
2018-11-29 11:39:00 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-06-11 14:17:34 +02:00
|
|
|
_converse, _converse.push_app_servers[0].jid,
|
2018-06-06 11:07:59 +02:00
|
|
|
[{'category': 'pubsub', 'type':'push'}],
|
2018-11-29 11:39:00 +01:00
|
|
|
['urn:xmpp:push:0'], [], 'info');
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-06-06 11:07:59 +02:00
|
|
|
_converse,
|
|
|
|
_converse.bare_jid,
|
|
|
|
[{'category': 'account', 'type':'registered'}],
|
2018-11-29 11:39:00 +01:00
|
|
|
['urn:xmpp:push:0'], [], 'info');
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
const stanza = await u.waitUntil(
|
2019-05-20 12:38:33 +02:00
|
|
|
() => _.filter(IQ_stanzas, iq => iq.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
|
2018-11-29 11:39:00 +01:00
|
|
|
);
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(stanza)).toEqual(
|
2018-11-29 11:39:00 +01:00
|
|
|
`<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
|
|
|
'<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0">'+
|
|
|
|
'<x type="submit" xmlns="jabber:x:data">'+
|
|
|
|
'<field var="FORM_TYPE"><value>http://jabber.org/protocol/pubsub#publish-options</value></field>'+
|
|
|
|
'<field var="secret"><value>eruio234vzxc2kla-91</value></field>'+
|
|
|
|
'</x>'+
|
|
|
|
'</enable>'+
|
|
|
|
'</iq>'
|
|
|
|
)
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest($iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'result',
|
|
|
|
'id': stanza.getAttribute('id')
|
|
|
|
})));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.session.get('push_enabled'))
|
2018-11-29 11:39:00 +01:00
|
|
|
done();
|
2018-06-06 11:07:59 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
}));
|