Skip to content

Commit

Permalink
Added tests for node purge. Fixes #15.
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydwatkin committed Jun 23, 2013
1 parent 4338df0 commit 2fa7521
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ PubSub.prototype.purgeNode = function(data, callback) {
var stanza = this._getStanza(data, 'set', 'purge')
this.manager.trackId(stanza.root().attr('id'), function(stanza) {
if (stanza.attrs.type == 'error')
callback(self._parseError(stanza), null)
return callback(self._parseError(stanza), null)
callback(null, true)
})
this.client.send(stanza)
Expand Down
87 changes: 87 additions & 0 deletions test/lib/pubsub.items.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,5 +592,92 @@ describe('Publish-Subscribe', function() {

describe('Purging a node', function() {

it('Errors if missing \'to\' key', function(done) {
var request = {}
xmpp.once('stanza', function() {
done('Unexpected outgoing stanza')
})
var callback = function(error, success) {
should.not.exist(success)
error.type.should.equal('modify')
error.condition.should.equal('client-error')
error.description.should.equal("Missing 'to' key")
error.request.should.eql(request)
xmpp.removeAllListeners('stanza')
done()
}
socket.emit('xmpp.pubsub.purge', request, callback)
})

it('Errors if missing \'node\' key', function(done) {
var request = { to: 'pubsub.shakespeare.lit' }
xmpp.once('stanza', function() {
done('Unexpected outgoing stanza')
})
var callback = function(error, success) {
should.not.exist(success)
error.type.should.equal('modify')
error.condition.should.equal('client-error')
error.description.should.equal("Missing 'node' key")
error.request.should.eql(request)
xmpp.removeAllListeners('stanza')
done()
}
socket.emit('xmpp.pubsub.purge', request, callback)
})

it('Sends expected stanza', 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('set')
var purge = stanza.getChild('pubsub', pubsub.NS_PUBSUB)
.getChild('purge')
purge.should.exist
purge.attrs.node.should.equal(request.node)
done()
})
socket.emit('xmpp.pubsub.purge', request, function() {})
})

it('Handles error response', function(done) {
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.purge', request, callback)
})

it('Returns true for successful response', function(done) {
xmpp.once('stanza', function(stanza) {
manager.makeCallback(helper.getStanza('iq-result'))
})
var callback = function(error, success) {
should.not.exist(error)
success.should.be.true
done()
}
var request = {
to: 'pubsub.shakespeare.lit',
node: 'twelfth night'
}
socket.emit('xmpp.pubsub.purge', request, callback)
})

})
})

0 comments on commit 2fa7521

Please sign in to comment.