-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from wayfair/add_invite
List users in a room and invite users
- Loading branch information
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,19 @@ describe 'XmppBot', -> | |
done() | ||
bot.readIq stanza | ||
|
||
it 'should parse room query iqs for users in the room', (done) -> | ||
stanza.attrs.id = 'get_users_in_room_8139nj32ma' | ||
stanza.attrs.from = '[email protected]' | ||
userItems = [ | ||
{ attrs: {name: 'mark'} }, | ||
{ attrs: {name: 'anup'} } | ||
] | ||
stanza.children = [ {children: userItems} ] | ||
bot.on "completedRequest#{stanza.attrs.id}", (usersInRoom) -> | ||
assert.deepEqual usersInRoom, (item.attrs.name for item in userItems) | ||
done() | ||
bot.readIq stanza | ||
|
||
describe '#readMessage()', -> | ||
stanza = '' | ||
bot = Bot.use() | ||
|
@@ -337,6 +350,70 @@ describe 'XmppBot', -> | |
done() | ||
bot.topic envelope, 'one', 'two' | ||
|
||
describe '#getUsersInRoom()', -> | ||
bot = Bot.use() | ||
|
||
bot.client = | ||
stub: 'xmpp client' | ||
|
||
bot.robot = | ||
name: 'bot' | ||
logger: | ||
debug: () -> | ||
|
||
bot.options = | ||
username: '[email protected]' | ||
|
||
room = | ||
jid: '[email protected]' | ||
password: false | ||
|
||
it 'should call @client.send()', (done) -> | ||
bot.client.send = (message) -> | ||
assert.equal message.attrs.from, bot.options.username | ||
assert.equal (message.attrs.id.startsWith 'get_users_in_room'), true | ||
assert.equal message.attrs.to, room.jid | ||
assert.equal message.attrs.type, 'get' | ||
assert.equal message.children[0].name, 'query' | ||
assert.equal message.children[0].attrs.xmlns, 'http://jabber.org/protocol/disco#items' | ||
done() | ||
bot.getUsersInRoom room, () -> | ||
|
||
it 'should call callback on receiving users', (done) -> | ||
users = ['mark', 'anup'] | ||
requestId = 'get_users_in_room_8139nj32ma' | ||
bot.client.send = () -> | ||
callback = (usersInRoom) -> | ||
assert.deepEqual usersInRoom, users | ||
done() | ||
bot.getUsersInRoom room, callback, requestId | ||
bot.emit "completedRequest#{requestId}", users | ||
|
||
describe '#sendInvite()', -> | ||
bot = Bot.use() | ||
|
||
bot.client = | ||
stub: 'xmpp client' | ||
|
||
bot.robot = | ||
name: 'bot' | ||
logger: | ||
debug: () -> | ||
|
||
room = | ||
jid: '[email protected]' | ||
password: false | ||
invitee = '[email protected]' | ||
reason = 'Inviting to test' | ||
|
||
it 'should call @client.send()', (done) -> | ||
bot.client.send = (message) -> | ||
assert.equal message.attrs.to, invitee | ||
assert.equal message.children[0].attrs.jid, room.jid | ||
assert.equal message.children[0].attrs.reason, reason | ||
done() | ||
bot.sendInvite room, invitee, reason | ||
|
||
describe '#error()', -> | ||
bot = Bot.use() | ||
bot.robot = | ||
|