Skip to content

Commit

Permalink
All test files now passing lint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydwatkin committed Dec 20, 2013
1 parent 720a894 commit e17904f
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 263 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Expand Up @@ -5,7 +5,7 @@ module.exports = function(grunt) {
grunt.initConfig({ grunt.initConfig({
pkg: grunt.file.readJSON('package.json'), pkg: grunt.file.readJSON('package.json'),
jshint: { jshint: {
allFiles: ['gruntfile.js', 'lib/**/*.js', 'examples/**/*.js'], allFiles: ['gruntfile.js', 'lib/**/*.js', 'test/**/*.js'],
options: { options: {
jshintrc: '.jshintrc', jshintrc: '.jshintrc',
} }
Expand Down
5 changes: 4 additions & 1 deletion test/helper.js
@@ -1,3 +1,5 @@
'use strict';

var ltx = require('ltx') var ltx = require('ltx')
, fs = require('fs') , fs = require('fs')
, Event = require('events').EventEmitter , Event = require('events').EventEmitter
Expand All @@ -15,4 +17,5 @@ Eventer.prototype = new Event()
Eventer.prototype.send = function(stanza) { Eventer.prototype.send = function(stanza) {
this.emit('stanza', stanza.root()) this.emit('stanza', stanza.root())
} }
exports.Eventer = Eventer
exports.Eventer = Eventer
36 changes: 23 additions & 13 deletions test/lib/chat.js
@@ -1,9 +1,12 @@
'use strict';

var Chat = require('../../index').Chat var Chat = require('../../index').Chat
, ltx = require('ltx') , ltx = require('ltx')
, helper = require('../helper') , helper = require('../helper')
, should = require('should') , should = require('should')
, chatState = require('../../index').utils['xep-0085'] , chatState = require('../../index').utils['xep-0085']


/* jshint -W030 */
describe('Chat', function() { describe('Chat', function() {


var chat var chat
Expand Down Expand Up @@ -128,13 +131,13 @@ describe('Chat', function() {


it('https://github.com/lloydwatkin/xmpp-ftw/issues/40', function(done) { it('https://github.com/lloydwatkin/xmpp-ftw/issues/40', function(done) {
socket.once('xmpp.chat.message', function(data) { socket.once('xmpp.chat.message', function(data) {
data.should.eql({ data.should.eql({
from: { domain: 'buddycloud.org', user: 'lloyd', resource: '...' }, from: { domain: 'buddycloud.org', user: 'lloyd', resource: '...' },
content: 'hey', content: 'hey',
format: 'plain', format: 'plain',
state: 'active' state: 'active'
}) })
done() done()
}) })
chat.handle(helper.getStanza('issues/40')).should.be.true chat.handle(helper.getStanza('issues/40')).should.be.true
}) })
Expand All @@ -145,7 +148,7 @@ describe('Chat', function() {


it('Sends error message if \'to\' parameter missing', function(done) { it('Sends error message if \'to\' parameter missing', function(done) {
socket.once('xmpp.error.client', function(data) { socket.once('xmpp.error.client', function(data) {
data.description.should.equal("Missing 'to' key") data.description.should.equal('Missing \'to\' key')
data.type.should.equal('modify') data.type.should.equal('modify')
data.condition.should.equal('client-error') data.condition.should.equal('client-error')
data.request.should.eql({}) data.request.should.eql({})
Expand Down Expand Up @@ -184,7 +187,7 @@ describe('Chat', function() {
var to = 'romeo@montague.net/orchard' var to = 'romeo@montague.net/orchard'
var content = 'This will <strong>fail' var content = 'This will <strong>fail'
socket.once('xmpp.error.client', function(data) { socket.once('xmpp.error.client', function(data) {
data.description.should.equal("Can not parse XHTML message") data.description.should.equal('Can not parse XHTML message')
data.type.should.equal('modify') data.type.should.equal('modify')
data.condition.should.equal('client-error') data.condition.should.equal('client-error')
data.request.to.should.equal(to) data.request.to.should.equal(to)
Expand All @@ -193,7 +196,9 @@ describe('Chat', function() {
done() done()
}) })
chat.sendMessage({ chat.sendMessage({
to: to, content: content, format: chat.XHTML to: to,
content: content,
format: chat.XHTML
}) })
}) })


Expand All @@ -216,7 +221,9 @@ describe('Chat', function() {
done() done()
}) })
chat.sendMessage({ chat.sendMessage({
to: to, content: content, format: chat.XHTML to: to,
content: content,
format: chat.XHTML
}) })
}) })


Expand All @@ -239,7 +246,9 @@ describe('Chat', function() {
done() done()
}) })
chat.sendMessage({ chat.sendMessage({
to: to, content: content, format: chat.XHTML to: to,
content: content,
format: chat.XHTML
}) })
}) })


Expand All @@ -252,7 +261,8 @@ describe('Chat', function() {
done() done()
}) })
chat.sendMessage({ chat.sendMessage({
to: to, state: state to: to,
state: state
}) })
}) })


Expand Down
78 changes: 42 additions & 36 deletions test/lib/presence.js
@@ -1,8 +1,11 @@
'use strict';

var should = require('should') var should = require('should')
, Presence = require('../../index').Presence , Presence = require('../../index').Presence
, ltx = require('ltx') , ltx = require('ltx')
, helper = require('../helper') , helper = require('../helper')


/* jshint -W030 */
describe('Presence', function() { describe('Presence', function() {


var presence, socket, xmpp, manager var presence, socket, xmpp, manager
Expand Down Expand Up @@ -95,9 +98,9 @@ describe('Presence', function() {
data.status.should.equal('say hello to me') data.status.should.equal('say hello to me')
data.priority.should.equal('10') data.priority.should.equal('10')
data.show.should.equal('chat') data.show.should.equal('chat')
done() done()
}) })
presence.handle(helper.getStanza('presence/presence-reply')) presence.handle(helper.getStanza('presence/presence-reply'))
}) })
}) })


Expand Down Expand Up @@ -152,7 +155,7 @@ describe('Presence', function() {
socket.once('xmpp.error.client', function(data) { socket.once('xmpp.error.client', function(data) {
data.type.should.equal('modify') data.type.should.equal('modify')
data.condition.should.equal('client-error') data.condition.should.equal('client-error')
data.description.should.equal("Missing 'to' key") data.description.should.equal('Missing \'to\' key')
data.request.should.eql({}) data.request.should.eql({})
xmpp.removeAllListeners('stanza') xmpp.removeAllListeners('stanza')
done() done()
Expand All @@ -161,16 +164,17 @@ describe('Presence', function() {
}) })


it('Can send subscribe stanza', function(done) { it('Can send subscribe stanza', function(done) {
var to = 'juliet@example.com/balcony' var to = 'juliet@example.com/balcony'
xmpp.once('stanza', function(stanza) { xmpp.once('stanza', function(stanza) {
stanza.is('presence').should.be.true stanza.is('presence').should.be.true
stanza.attrs.to.should.equal(to) stanza.attrs.to.should.equal(to)
stanza.attrs.type.should.equal('subscribe') stanza.attrs.type.should.equal('subscribe')
stanza.attrs.from.should.equal(manager.jid) stanza.attrs.from.should.equal(manager.jid)
done() done()
}) })
socket.emit('xmpp.presence.subscribe', { to: to }) socket.emit('xmpp.presence.subscribe', { to: to })
}) }
)
}) })


describe('Subscribed stanzas', function() { describe('Subscribed stanzas', function() {
Expand All @@ -182,7 +186,7 @@ describe('Presence', function() {
socket.once('xmpp.error.client', function(data) { socket.once('xmpp.error.client', function(data) {
data.type.should.equal('modify') data.type.should.equal('modify')
data.condition.should.equal('client-error') data.condition.should.equal('client-error')
data.description.should.equal("Missing 'to' key") data.description.should.equal('Missing \'to\' key')
data.request.should.eql({}) data.request.should.eql({})
xmpp.removeAllListeners('stanza') xmpp.removeAllListeners('stanza')
done() done()
Expand All @@ -191,16 +195,17 @@ describe('Presence', function() {
}) })


it('Can send subscribed stanza', function(done) { it('Can send subscribed stanza', function(done) {
var to = 'juliet@example.com/balcony' var to = 'juliet@example.com/balcony'
xmpp.once('stanza', function(stanza) { xmpp.once('stanza', function(stanza) {
stanza.is('presence').should.be.true stanza.is('presence').should.be.true
stanza.attrs.to.should.equal(to) stanza.attrs.to.should.equal(to)
stanza.attrs.type.should.equal('subscribed') stanza.attrs.type.should.equal('subscribed')
stanza.attrs.from.should.equal(manager.jid) stanza.attrs.from.should.equal(manager.jid)
done() done()
}) })
socket.emit('xmpp.presence.subscribed', { to: to }) socket.emit('xmpp.presence.subscribed', { to: to })
}) }
)
}) })


describe('Unsubscribed stanzas', function() { describe('Unsubscribed stanzas', function() {
Expand All @@ -212,7 +217,7 @@ describe('Presence', function() {
socket.once('xmpp.error.client', function(data) { socket.once('xmpp.error.client', function(data) {
data.type.should.equal('modify') data.type.should.equal('modify')
data.condition.should.equal('client-error') data.condition.should.equal('client-error')
data.description.should.equal("Missing 'to' key") data.description.should.equal('Missing \'to\' key')
data.request.should.eql({}) data.request.should.eql({})
xmpp.removeAllListeners('stanza') xmpp.removeAllListeners('stanza')
done() done()
Expand All @@ -221,16 +226,17 @@ describe('Presence', function() {
}) })


it('Can send unsubscribed stanza', function(done) { it('Can send unsubscribed stanza', function(done) {
var to = 'juliet@example.com/balcony' var to = 'juliet@example.com/balcony'
xmpp.once('stanza', function(stanza) { xmpp.once('stanza', function(stanza) {
stanza.is('presence').should.be.true stanza.is('presence').should.be.true
stanza.attrs.to.should.equal(to) stanza.attrs.to.should.equal(to)
stanza.attrs.type.should.equal('unsubscribed') stanza.attrs.type.should.equal('unsubscribed')
stanza.attrs.from.should.equal(manager.jid) stanza.attrs.from.should.equal(manager.jid)
done() done()
}) })
socket.emit('xmpp.presence.unsubscribed', { to: to }) socket.emit('xmpp.presence.unsubscribed', { to: to })
}) }
)
}) })


it('Presence request errors when missing \'to\'', function(done) { it('Presence request errors when missing \'to\'', function(done) {
Expand All @@ -240,7 +246,7 @@ describe('Presence', function() {
socket.once('xmpp.error.client', function(data) { socket.once('xmpp.error.client', function(data) {
data.type.should.equal('modify') data.type.should.equal('modify')
data.condition.should.equal('client-error') data.condition.should.equal('client-error')
data.description.should.equal("Missing 'to' key") data.description.should.equal('Missing \'to\' key')
data.request.should.eql({}) data.request.should.eql({})
xmpp.removeAllListeners('stanza') xmpp.removeAllListeners('stanza')
done() done()
Expand Down

0 comments on commit e17904f

Please sign in to comment.