|
1 | 1 | /* global converse */
|
2 | 2 | import mock from '../../../tests/mock.js';
|
3 | 3 |
|
4 |
| -const { stx, Strophe } = converse.env; |
| 4 | +const { stx, Strophe, u } = converse.env; |
5 | 5 |
|
6 | 6 | describe('pubsub subscribe/unsubscribe API', function () {
|
7 | 7 | beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
|
@@ -75,4 +75,49 @@ describe('pubsub subscribe/unsubscribe API', function () {
|
75 | 75 | </iq>`);
|
76 | 76 | })
|
77 | 77 | );
|
| 78 | + |
| 79 | + it( |
| 80 | + 'sends correct IQ for create', |
| 81 | + mock.initConverse([], {}, async function (_converse) { |
| 82 | + await mock.waitForRoster(_converse, 'current', 0); |
| 83 | + const { api, state } = _converse; |
| 84 | + const own_jid = state.session.get('jid'); |
| 85 | + const sent = api.connection.get().sent_stanzas; |
| 86 | + const service = 'pubsub.example.org'; |
| 87 | + const node = 'newnode'; |
| 88 | + const config = { access_model: 'open', max_items: '10' }; |
| 89 | + const createPromise = api.pubsub.create(service, node, config); |
| 90 | + const stanza = await u.waitUntil(() => sent.filter((iq) => iq.querySelector('pubsub create')).pop()); |
| 91 | + expect(stanza).toEqualStanza(stx` |
| 92 | + <iq type="set" |
| 93 | + from="${own_jid}" |
| 94 | + to="${service}" |
| 95 | + xmlns="jabber:client" |
| 96 | + id="${stanza.getAttribute('id')}"> |
| 97 | + <pubsub xmlns="${Strophe.NS.PUBSUB}"> |
| 98 | + <create node="${node}"/> |
| 99 | + <configure> |
| 100 | + <x xmlns="${Strophe.NS.XFORM}" type="submit"> |
| 101 | + <field var="FORM_TYPE" type="hidden"> |
| 102 | + <value>${Strophe.NS.PUBSUB}#nodeconfig</value> |
| 103 | + </field> |
| 104 | + <field var="pubsub#access_model"><value>${config.access_model}</value></field> |
| 105 | + <field var="pubsub#max_items"><value>${config.max_items}</value></field> |
| 106 | + </x> |
| 107 | + </configure> |
| 108 | + </pubsub> |
| 109 | + </iq>`); |
| 110 | + |
| 111 | + _converse.api.connection.get()._dataRecv( |
| 112 | + mock.createRequest(stx` |
| 113 | + <iq type="result" |
| 114 | + xmlns="jabber:client" |
| 115 | + from="${service}" |
| 116 | + to="${_converse.bare_jid}" |
| 117 | + id="${stanza.getAttribute('id')}"/> |
| 118 | + `) |
| 119 | + ); |
| 120 | + await createPromise; |
| 121 | + }) |
| 122 | + ); |
78 | 123 | });
|
0 commit comments