Skip to content
Permalink
Browse files

Add connection test

  • Loading branch information
legastero committed Dec 21, 2019
1 parent 8710331 commit 0095ab838ba9dd205e8d972911e8b6d6b9d504b3
Showing with 110 additions and 0 deletions.
  1. +48 −0 docs/Events.md
  2. +6 −0 src/index.ts
  3. +56 −0 test/connection.ts
@@ -472,6 +472,22 @@ ReceivedPresence

<p></p>

<h3 id="presence:error">presence:error</h3>

```
ReceivedPresence
```

<p></p>

<h3 id="probe">probe</h3>

```
ReceivedPresence
```

<p></p>

<h3 id="pubsub:affiliations">pubsub:affiliations</h3>

```
@@ -728,6 +744,22 @@ Stream

<p></p>

<h3 id="subscribe">subscribe</h3>

```
ReceivedPresence
```

<p></p>

<h3 id="subscribed">subscribed</h3>

```
ReceivedPresence
```

<p></p>

<h3 id="tune">tune</h3>

```
@@ -750,5 +782,21 @@ ReceivedPresence
{ jids: string[] }
```

<p></p>

<h3 id="unsubscribe">unsubscribe</h3>

```
ReceivedPresence
```

<p></p>

<h3 id="unsubscribed">unsubscribed</h3>

```
ReceivedPresence
```

<p></p>
</tbody></table>
@@ -56,6 +56,12 @@ export interface AgentEvents {

available: Stanzas.ReceivedPresence;
unavailable: Stanzas.ReceivedPresence;
subscribe: Stanzas.ReceivedPresence;
subscribed: Stanzas.ReceivedPresence;
unsubscribe: Stanzas.ReceivedPresence;
unsubscribed: Stanzas.ReceivedPresence;
probe: Stanzas.ReceivedPresence;
'presence:error': Stanzas.ReceivedPresence;

'session:started': string | void;
'session:prebind': string;
@@ -38,3 +38,59 @@ test('Connect using BOSH', done => {

client.connect();
});

test('End to end', done => {
expect.assertions(2);

const client1 = stanza.createClient({
jid: 'anon@anon.stanzajs.org'
});
const client2 = stanza.createClient({
jid: 'anon@anon.stanzajs.org'
});

client1.on('session:started', async () => {
const roster = await client1.getRoster();
expect(roster.items).toStrictEqual([]);
client1.sendPresence();

client2.on('session:started', async () => {
await client2.getRoster();
client2.sendPresence();
client2.subscribe(client1.jid);
});
client2.connect();
});

client1.on('available', async pres => {
if (pres.from === client1.jid) {
return;
}
await client1.ping(pres.from);

client1.sendMessage({
to: client2.jid,
body: 'test'
});
});

client1.on('subscribe', () => {
client1.acceptSubscription(client2.jid);
client1.subscribe(client2.jid);
});

client2.on('subscribe', () => {
client2.acceptSubscription(client1.jid);
});

client2.on('message', msg => {
expect(msg.body).toBe('test');

client1.disconnect();
client2.disconnect();

done();
});

client1.connect();
});

0 comments on commit 0095ab8

Please sign in to comment.
You can’t perform that action at this time.