Skip to content

Commit

Permalink
Subscriptions: Add remaining tests. Fixes #17.
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydwatkin committed Jun 22, 2013
1 parent 3320a37 commit 2f79428
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ PubSub.prototype.getSubscriptions = function(data, callback) {
if (data.owner && !data.node)
return this._clientError(
"Can only do 'owner' for a node", data, callback
)
)

var owner = (data.owner) ? this.NS_OWNER : null
var self = this
var stanza = this._getStanza(data, 'get', 'subscriptions', owner)
Expand Down
111 changes: 107 additions & 4 deletions test/lib/pubsub.subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,122 @@ describe('Publish-Subscribe', function() {
})

it('Sends expected stanza for node owner', function(done) {
done('Not implemented')
var request = {
to: 'pubsub.shakespeare.lit',
node: 'twelfth night',
owner: true
}
xmpp.once('stanza', function(stanza) {
stanza.is('iq').should.be.true
stanza.attrs.to.should.equal(request.to)
stanza.attrs.type.should.equal('get')
stanza.attrs.id.should.exist
stanza.getChild('pubsub', pubsub.NS_OWNER).should.exist
var pubsubElement = stanza.getChild('pubsub')
pubsubElement.getChild('subscriptions').should.exist
pubsubElement.getChild('subscriptions').attrs.node
.should.equal(request.node)
done()
})
socket.emit('xmpp.pubsub.subscriptions', request)
})

it('Sends expected stanza for user subscriptions', function(done) {
done('Not implemented')
var request = {
to: 'pubsub.shakespeare.lit',
}
xmpp.once('stanza', function(stanza) {
stanza.is('iq').should.be.true
stanza.attrs.to.should.equal(request.to)
stanza.attrs.type.should.equal('get')
stanza.attrs.id.should.exist
stanza.getChild('pubsub', pubsub.NS_PUBSUB).should.exist
var pubsubElement = stanza.getChild('pubsub')
pubsubElement.getChild('subscriptions').should.exist
should.not.exist(
pubsubElement.getChild('subscriptions').attrs.node
)
done()
})
socket.emit('xmpp.pubsub.subscriptions', request)
})

it('Correct stanza for user subscriptions to node', function(done) {
var request = {
to: 'pubsub.shakespeare.lit',
node: 'twelfth night'
}
xmpp.once('stanza', function(stanza) {
stanza.is('iq').should.be.true
stanza.attrs.to.should.equal(request.to)
stanza.attrs.type.should.equal('get')
stanza.attrs.id.should.exist
stanza.getChild('pubsub', pubsub.NS_PUBSUB).should.exist
var pubsubElement = stanza.getChild('pubsub')
pubsubElement.getChild('subscriptions').should.exist
pubsubElement.getChild('subscriptions').attrs.node
.should.equal(request.node)
done()
})
socket.emit('xmpp.pubsub.subscriptions', request)
})

it('Handles error stanza response', function(done) {
done('Not implemented')
xmpp.once('stanza', function(stanza) {
manager.makeCallback(helper.getStanza('iq-error'))
})
var callback = function(error, success) {
should.not.exist(success)
error.should.eql({
type: 'cancel',
condition: 'error-condition'
})
done()
}
var request = {
to: 'pubsub.shakespeare.lit',
node: 'twelfth night'
}
socket.emit(
'xmpp.pubsub.subscriptions',
request,
callback
)

})

it('Sends a list of subscriptions', function(done) {
done('Not implemented')
xmpp.once('stanza', function(stanza) {
manager.makeCallback(helper.getStanza('subscriptions'))
})
var callback = function(error, data) {
should.not.exist(error)
data.length.should.equal(2)
data[0].node.should.equal('twelfth night')
data[0].jid.should.eql({
domain: 'example.net',
user: 'juliet'
})
data[0].subscription.should.equal('subscribed')
should.not.exist(data[0].id)
data[1].node.should.equal('a comedy of errors')
data[1].jid.should.eql({
domain: 'example.com',
user: 'romeo'
})
data[1].subscription.should.equal('subscribed')
data[1].id.should.equal('1')
done()
}
var request = {
to: 'pubsub.shakespeare.lit',
node: 'twelfth night'
}
socket.emit(
'xmpp.pubsub.subscriptions',
request,
callback
)
})

})
Expand Down
11 changes: 11 additions & 0 deletions test/resources/subscriptions
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<iq type='result'
from='pubsub.shakespeare.lit'
to='juliet@example.net/balcony'
id='1'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<subscriptions>
<subscription node='twelfth night' jid='juliet@example.net' subscription='subscribed' />
<subscription node='a comedy of errors' jid='romeo@example.com' subscription='subscribed' subid='1'/>
</subscriptions>
</pubsub>
</iq>

0 comments on commit 2f79428

Please sign in to comment.