-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List users in a room and invite users #90
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eb72872
Add functionality to send room invites
anupdhml 38168ba
Add functionality to get list of users in a room
anupdhml 1adef10
Tests for listing users in a room
anupdhml 6ca0d43
Use callback after getting user data
anupdhml 509531f
Use unique IDs to keep track of concurrent calls
anupdhml File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sneaky 😄