-
-
Notifications
You must be signed in to change notification settings - Fork 771
/
probes.js
77 lines (63 loc) · 4.15 KB
/
probes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*global mock, converse */
const { Strophe, stx, u } = converse.env;
describe("Groupchats", function () {
describe("when muc_send_probes is true", function () {
it("sends presence probes when muc_send_probes is true",
mock.initConverse([], {'muc_send_probes': true}, async function (_converse) {
const muc_jid = 'lounge@montague.lit';
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
let stanza = stx`<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="${muc_jid}/ralphm">
<body>This message will trigger a presence probe</body>
</message>`;
_converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => view.model.messages.length);
let occupant = view.model.messages.at(0)?.occupant;
expect(occupant).toBeDefined();
expect(occupant.get('nick')).toBe('ralphm');
expect(occupant.get('affiliation')).toBeUndefined();
expect(occupant.get('role')).toBeUndefined();
const sent_stanzas = _converse.api.connection.get().sent_stanzas;
let probe = await u.waitUntil(() => sent_stanzas.filter(s => s.matches('presence[type="probe"]')).pop());
expect(Strophe.serialize(probe)).toBe(
`<presence to="${muc_jid}/ralphm" type="probe" xmlns="jabber:client">`+
`<priority>0</priority>`+
`<c hash="sha-1" node="https://conversejs.org" ver="TfHz9vOOfqIG0Z9lW5CuPaWGnrQ=" xmlns="http://jabber.org/protocol/caps"/>`+
`</presence>`);
let presence = stx`<presence xmlns="jabber:client" to="${_converse.jid}" from="${muc_jid}/ralphm">
<x xmlns="http://jabber.org/protocol/muc#user">
<item affiliation="member" jid="ralph@example.org/Conversations.ZvLu" role="participant"/>
</x>
</presence>`;
_converse.api.connection.get()._dataRecv(mock.createRequest(presence));
expect(occupant.get('affiliation')).toBe('member');
expect(occupant.get('role')).toBe('participant');
// Check that unavailable but affiliated occupants don't get destroyed
stanza = stx`<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="${muc_jid}/gonePhising">
<body>This message from an unavailable user will trigger a presence probe</body>
</message>`;
_converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
await u.waitUntil(() => view.model.messages.length === 2);
occupant = view.model.messages.at(1)?.occupant;
expect(occupant).toBeDefined();
expect(occupant.get('nick')).toBe('gonePhising');
expect(occupant.get('affiliation')).toBeUndefined();
expect(occupant.get('role')).toBeUndefined();
probe = await u.waitUntil(() => sent_stanzas.filter(s => s.matches(`presence[to="${muc_jid}/gonePhising"]`)).pop());
expect(Strophe.serialize(probe)).toBe(
`<presence to="${muc_jid}/gonePhising" type="probe" xmlns="jabber:client">`+
`<priority>0</priority>`+
`<c hash="sha-1" node="https://conversejs.org" ver="TfHz9vOOfqIG0Z9lW5CuPaWGnrQ=" xmlns="http://jabber.org/protocol/caps"/>`+
`</presence>`);
presence = stx`<presence xmlns="jabber:client" type="unavailable" to="${_converse.jid}" from="${muc_jid}/gonePhising">
<x xmlns="http://jabber.org/protocol/muc#user">
<item affiliation="member" jid="gonePhishing@example.org/d34dBEEF" role="participant"/>
</x>
</presence>`;
_converse.api.connection.get()._dataRecv(mock.createRequest(presence));
expect(view.model.occupants.length).toBe(3);
expect(occupant.get('affiliation')).toBe('member');
expect(occupant.get('role')).toBe('participant');
}));
});
});