|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 | 3 | const test = require('ava')
|
4 |
| -const {mockClient, promise, timeout} = require('@xmpp/test') |
| 4 | +const {mockClient} = require('@xmpp/test') |
5 | 5 |
|
6 |
| -test('mandatory', async t => { |
| 6 | +function tick() { |
| 7 | + return new Promise(resolve => process.nextTick(resolve)) |
| 8 | +} |
| 9 | + |
| 10 | +test('enable - enabled', async t => { |
7 | 11 | const {entity} = mockClient()
|
8 | 12 |
|
9 | 13 | entity.mockInput(
|
10 | 14 | <features xmlns="http://etherx.jabber.org/streams">
|
11 |
| - <session xmlns="urn:ietf:params:xml:ns:xmpp-session" /> |
| 15 | + <sm xmlns="urn:xmpp:sm:3" /> |
12 | 16 | </features>
|
13 | 17 | )
|
14 | 18 |
|
15 |
| - entity.scheduleIncomingResult() |
| 19 | + entity.streamManagement.outbound = 45 |
| 20 | + |
| 21 | + t.deepEqual( |
| 22 | + await entity.catchOutgoing(), |
| 23 | + <enable xmlns="urn:xmpp:sm:3" resume="true" /> |
| 24 | + ) |
| 25 | + |
| 26 | + t.is(entity.streamManagement.outbound, 0) |
| 27 | + t.is(entity.streamManagement.enabled, false) |
| 28 | + t.is(entity.streamManagement.id, '') |
16 | 29 |
|
17 |
| - await entity.catchOutgoingSet().then(child => { |
18 |
| - t.deepEqual(child, <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />) |
19 |
| - return child |
20 |
| - }) |
| 30 | + entity.mockInput( |
| 31 | + <enabled |
| 32 | + xmlns="urn:xmpp:sm:3" |
| 33 | + id="some-long-sm-id" |
| 34 | + location="[2001:41D0:1:A49b::1]:9222" |
| 35 | + resume="true" |
| 36 | + /> |
| 37 | + ) |
21 | 38 |
|
22 |
| - await promise(entity, 'online') |
| 39 | + await tick() |
| 40 | + |
| 41 | + t.is(entity.streamManagement.id, 'some-long-sm-id') |
| 42 | + t.is(entity.streamManagement.enabled, true) |
23 | 43 | })
|
24 | 44 |
|
25 |
| -test('optional', async t => { |
| 45 | +test('enable - message - enabled', async t => { |
26 | 46 | const {entity} = mockClient()
|
27 | 47 |
|
28 | 48 | entity.mockInput(
|
29 | 49 | <features xmlns="http://etherx.jabber.org/streams">
|
30 |
| - <session xmlns="urn:ietf:params:xml:ns:xmpp-session"> |
31 |
| - <optional /> |
32 |
| - </session> |
| 50 | + <sm xmlns="urn:xmpp:sm:3" /> |
33 | 51 | </features>
|
34 | 52 | )
|
35 | 53 |
|
36 |
| - const promiseSend = promise(entity, 'send') |
| 54 | + entity.streamManagement.outbound = 45 |
| 55 | + |
| 56 | + t.deepEqual( |
| 57 | + await entity.catchOutgoing(), |
| 58 | + <enable xmlns="urn:xmpp:sm:3" resume="true" /> |
| 59 | + ) |
| 60 | + |
| 61 | + t.is(entity.streamManagement.outbound, 0) |
| 62 | + t.is(entity.streamManagement.enabled, false) |
| 63 | + t.is(entity.streamManagement.id, '') |
| 64 | + |
| 65 | + entity.mockInput(<message />) |
| 66 | + |
| 67 | + t.is(entity.streamManagement.enabled, false) |
| 68 | + t.is(entity.streamManagement.inbound, 1) |
| 69 | + |
| 70 | + entity.mockInput( |
| 71 | + <enabled |
| 72 | + xmlns="urn:xmpp:sm:3" |
| 73 | + id="some-long-sm-id" |
| 74 | + location="[2001:41D0:1:A49b::1]:9222" |
| 75 | + resume="true" |
| 76 | + /> |
| 77 | + ) |
| 78 | + |
| 79 | + await tick() |
| 80 | + |
| 81 | + t.is(entity.streamManagement.id, 'some-long-sm-id') |
| 82 | + t.is(entity.streamManagement.enabled, true) |
| 83 | +}) |
| 84 | + |
| 85 | +test('enable - failed', async t => { |
| 86 | + const {entity} = mockClient() |
| 87 | + |
| 88 | + entity.mockInput( |
| 89 | + <features xmlns="http://etherx.jabber.org/streams"> |
| 90 | + <sm xmlns="urn:xmpp:sm:3" /> |
| 91 | + </features> |
| 92 | + ) |
| 93 | + |
| 94 | + entity.streamManagement.outbound = 45 |
| 95 | + |
| 96 | + t.deepEqual( |
| 97 | + await entity.catchOutgoing(), |
| 98 | + <enable xmlns="urn:xmpp:sm:3" resume="true" /> |
| 99 | + ) |
| 100 | + |
| 101 | + t.is(entity.streamManagement.outbound, 0) |
| 102 | + entity.streamManagement.enabled = true |
| 103 | + |
| 104 | + entity.mockInput(<failed xmlns="urn:xmpp:sm:3" />) |
| 105 | + |
| 106 | + await tick() |
| 107 | + |
| 108 | + t.is(entity.streamManagement.enabled, false) |
| 109 | +}) |
| 110 | + |
| 111 | +test('resume - resumed', async t => { |
| 112 | + const {entity} = mockClient() |
| 113 | + |
| 114 | + entity.status = 'offline' |
| 115 | + entity.streamManagement.id = 'bar' |
| 116 | + |
| 117 | + entity.mockInput( |
| 118 | + <features xmlns="http://etherx.jabber.org/streams"> |
| 119 | + <sm xmlns="urn:xmpp:sm:3" /> |
| 120 | + </features> |
| 121 | + ) |
| 122 | + |
| 123 | + entity.streamManagement.outbound = 45 |
| 124 | + |
| 125 | + t.deepEqual( |
| 126 | + await entity.catchOutgoing(), |
| 127 | + <resume xmlns="urn:xmpp:sm:3" previd="bar" h="0" /> |
| 128 | + ) |
| 129 | + |
| 130 | + t.is(entity.streamManagement.enabled, false) |
| 131 | + |
| 132 | + t.is(entity.status, 'offline') |
| 133 | + |
| 134 | + entity.mockInput(<resumed xmlns="urn:xmpp:sm:3" />) |
| 135 | + |
| 136 | + await tick() |
| 137 | + |
| 138 | + t.is(entity.streamManagement.outbound, 45) |
| 139 | + t.is(entity.status, 'online') |
| 140 | +}) |
| 141 | + |
| 142 | +test('resume - failed', async t => { |
| 143 | + const {entity} = mockClient() |
| 144 | + |
| 145 | + entity.status = 'bar' |
| 146 | + entity.streamManagement.id = 'bar' |
| 147 | + entity.streamManagement.enabled = true |
| 148 | + entity.streamManagement.outbound = 45 |
| 149 | + |
| 150 | + entity.mockInput( |
| 151 | + <features xmlns="http://etherx.jabber.org/streams"> |
| 152 | + <sm xmlns="urn:xmpp:sm:3" /> |
| 153 | + </features> |
| 154 | + ) |
| 155 | + |
| 156 | + t.deepEqual( |
| 157 | + await entity.catchOutgoing(), |
| 158 | + <resume xmlns="urn:xmpp:sm:3" previd="bar" h="0" /> |
| 159 | + ) |
| 160 | + |
| 161 | + entity.mockInput(<failed xmlns="urn:xmpp:sm:3" />) |
37 | 162 |
|
38 |
| - await promise(entity, 'online') |
| 163 | + await tick() |
39 | 164 |
|
40 |
| - await timeout(promiseSend, 0).catch(err => { |
41 |
| - t.is(err.name, 'TimeoutError') |
42 |
| - }) |
| 165 | + t.is(entity.status, 'bar') |
| 166 | + t.is(entity.streamManagement.id, '') |
| 167 | + t.is(entity.streamManagement.enabled, false) |
| 168 | + t.is(entity.streamManagement.outbound, 0) |
43 | 169 | })
|
0 commit comments