Skip to content

Commit

Permalink
Subscription configuration: Filled in tests for error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydwatkin committed Jun 22, 2013
1 parent df286eb commit ee8d190
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ PubSub.prototype.subscriptionConfigurationGet = function(data, callback) {
var stanza = this._getStanza(data, 'get', 'options')

this.manager.trackId(stanza.root().attr('id'), function(stanza) {
if (stanza.attrs.type == 'error') callback(self._parseError(stanza), null)
if (stanza.attrs.type == 'error')
return callback(self._parseError(stanza), null)
var title, description
var data = {}
if (null != (title = stanza.getChild('title')))
Expand All @@ -207,7 +208,7 @@ PubSub.prototype.subscriptionDefaultConfigurationGet = function(data, callback)

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)
var title, description
var data = {}
if (null != (title = stanza.getChild('title')))
Expand Down Expand Up @@ -238,7 +239,7 @@ PubSub.prototype.subscriptionConfigurationSet = function(data, callback) {
}
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
103 changes: 98 additions & 5 deletions test/lib/pubsub.subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,69 @@ describe('Publish-Subscribe', function() {
})

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

it('Sends expected stanza with node', function(done) {
done('Not implemented yet')
var request = {
to: 'pubsub.shakespeare.lit',
node: 'twelfth night'
}
xmpp.once('stanza', function(stanza) {
stanza.is('iq').should.equal.true
stanza.attrs.type.should.equal('get')
stanza.attrs.to.should.equal(request.to)
stanza.attrs.id.should.exist
stanza.getChild('pubsub', pubsub.NS_PUBSUB).should.exist
var element = stanza.getChild('pubsub').getChild('default')
element.should.exist
element.attrs.node.should.equal(request.node)
done()
})
socket.emit(
'xmpp.pubsub.subscription.config.default',
request,
function(){}
)
})

it('Handles error response', function(done) {
done('Not implemented yet')
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.subscription.config.default',
request,
callback
)
})

it('Returns data from successful request', function(done) {
Expand Down Expand Up @@ -530,7 +584,26 @@ describe('Publish-Subscribe', function() {
})

it('Handles error response', function(done) {
done('Not implemented yet')
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.subscription.config.get',
request,
callback
)
})

it('Returns data from successful request', function(done) {
Expand Down Expand Up @@ -641,7 +714,27 @@ describe('Publish-Subscribe', function() {
})

it('Handles error response stanza', function(done) {
done('Not implemented yet')
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',
form: []
}
socket.emit(
'xmpp.pubsub.subscription.config.set',
request,
callback
)
})

it('Returns true for succesful set', function(done) {
Expand Down

0 comments on commit ee8d190

Please sign in to comment.