|
| 1 | +import mock from '../../../tests/mock.js'; |
| 2 | +import converse from '../../../dist/converse-headless.js'; |
| 3 | + |
| 4 | +const { sizzle, stx, u } = converse.env; |
| 5 | + |
| 6 | +describe('XEP-0092 Software Version', function () { |
| 7 | + it( |
| 8 | + 'can be queried via api.version.get()', |
| 9 | + mock.initConverse(converse, ['statusInitialized'], {}, async (_converse) => { |
| 10 | + const conn = _converse.api.connection.get(); |
| 11 | + const promise = _converse.api.version.get(); |
| 12 | + |
| 13 | + const sent_iq = await u.waitUntil(() => |
| 14 | + conn.IQ_stanzas.filter((iq) => sizzle('query[xmlns="jabber:iq:version"]', iq).length).pop() |
| 15 | + ); |
| 16 | + expect(sent_iq).toEqualStanza(stx` |
| 17 | + <iq id="${sent_iq.getAttribute('id')}" to="montague.lit" type="get" xmlns="jabber:client"> |
| 18 | + <query xmlns="jabber:iq:version"/> |
| 19 | + </iq>`); |
| 20 | + |
| 21 | + const result = stx` |
| 22 | + <iq from="montague.lit" to="${_converse.jid}" id="${sent_iq.getAttribute('id')}" type="result" xmlns="jabber:client"> |
| 23 | + <query xmlns="jabber:iq:version"> |
| 24 | + <name>Prosody</name> |
| 25 | + <version>0.12.0</version> |
| 26 | + <os>Debian GNU/Linux</os> |
| 27 | + </query> |
| 28 | + </iq>`; |
| 29 | + conn._dataRecv(mock.createRequest(_converse, result)); |
| 30 | + |
| 31 | + const version = await promise; |
| 32 | + expect(version).toEqual({ name: 'Prosody', version: '0.12.0', os: 'Debian GNU/Linux' }); |
| 33 | + }) |
| 34 | + ); |
| 35 | + |
| 36 | + it( |
| 37 | + 'returns null when the entity responds with an error', |
| 38 | + mock.initConverse(converse, ['statusInitialized'], {}, async (_converse) => { |
| 39 | + const conn = _converse.api.connection.get(); |
| 40 | + const promise = _converse.api.version.get('shakespeare.lit'); |
| 41 | + |
| 42 | + const sent_iq = await u.waitUntil(() => |
| 43 | + conn.IQ_stanzas |
| 44 | + .filter((iq) => iq.getAttribute('to') === 'shakespeare.lit') |
| 45 | + .filter((iq) => sizzle('query[xmlns="jabber:iq:version"]', iq).length) |
| 46 | + .pop() |
| 47 | + ); |
| 48 | + |
| 49 | + const error = stx` |
| 50 | + <iq from="shakespeare.lit" to="${_converse.jid}" id="${sent_iq.getAttribute('id')}" type="error" xmlns="jabber:client"> |
| 51 | + <query xmlns="jabber:iq:version"/> |
| 52 | + <error type="cancel"> |
| 53 | + <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/> |
| 54 | + </error> |
| 55 | + </iq>`; |
| 56 | + conn._dataRecv(mock.createRequest(_converse, error)); |
| 57 | + |
| 58 | + expect(await promise).toBe(null); |
| 59 | + }) |
| 60 | + ); |
| 61 | +}); |
0 commit comments