Skip to content

Commit

Permalink
Tests added for deleteing a node item. Fixes #10.
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydwatkin committed Jun 23, 2013
1 parent efad6ef commit 4338df0
Show file tree
Hide file tree
Showing 2 changed files with 122 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 @@ -282,7 +282,7 @@ PubSub.prototype.deleteItem = function(data, callback) {
stanza.c('item', { id: data.id })
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
121 changes: 121 additions & 0 deletions test/lib/pubsub.items.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,127 @@ describe('Publish-Subscribe', function() {

describe('Deleting node items', function() {

it('Errors if no \'to\' key provided', 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.item.delete', request, callback)
})

it('Errors if no \'node\' key provided', 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.item.delete', request, callback)
})

it('Errors if missing item id', function(done) {
var request = {
to: 'pubsub.shakespeare.lit',
node: 'twelfth night'
}
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 'id' key")
error.request.should.eql(request)
xmpp.removeAllListeners('stanza')
done()
}
socket.emit('xmpp.pubsub.item.delete', request, callback)
})

it('Sends expected stanza', function(done) {
var request = {
to: 'pubsub.shakespeare.lit',
node: 'twelfth night',
id: 'item-1'
}
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 retract = stanza.getChild('pubsub', pubsub.NS_PUBSUB)
.getChild('retract')
retract.should.exist
retract.attrs.node.should.equal(request.node)
retract.children.length.should.equal(1)
retract.getChild('item').attrs.id.should.equal(request.id)
done()
})
socket.emit('xmpp.pubsub.item.delete', request, function() {})

})

it('Handles error stanza', 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',
id: 'item-1'
}
socket.emit(
'xmpp.pubsub.item.delete',
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',
id: 'item-1'
}
socket.emit(
'xmpp.pubsub.item.delete',
request,
callback
)
})

})

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

0 comments on commit 4338df0

Please sign in to comment.