-
Notifications
You must be signed in to change notification settings - Fork 636
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
Load users to robot.brain.users #381
Changes from 8 commits
25a8de9
81cc337
0a4ee02
c24ef28
3a3b342
14cc53b
e1737ac
7f7194b
902b00f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
should = require 'should' | ||
{Adapter, TextMessage, EnterMessage, LeaveMessage, TopicMessage, Message, CatchAllMessage, Robot, Listener} = require.main.require 'hubot' | ||
ReactionMessage = require '../src/reaction-message' | ||
SlackClient = require '../src/client' | ||
|
||
describe 'Adapter', -> | ||
it 'Should initialize with a robot', -> | ||
|
@@ -254,3 +255,70 @@ describe 'Robot.react', -> | |
@slackbot.robot.react matcher, @handleReaction | ||
listener = @slackbot.robot.listeners.shift() | ||
listener.matcher(@reactionMessage).should.be.false | ||
|
||
describe 'Users data', -> | ||
it 'Should add a user data', -> | ||
@slackbot.userChange(@stubs.user) | ||
|
||
user = @slackbot.robot.brain.data.users[@stubs.user.id] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of accesing the brain data directly, wouldn't it make more sense to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call 👍 |
||
should.equal user.id, @stubs.user.id | ||
should.equal user.name, @stubs.user.name | ||
should.equal user.real_name, @stubs.user.real_name | ||
should.equal user.email_address, @stubs.user.profile.email | ||
should.equal user.slack.misc, @stubs.user.misc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
|
||
it 'Should modify a user data', -> | ||
@slackbot.userChange(@stubs.user) | ||
|
||
user = @slackbot.robot.brain.data.users[@stubs.user.id] | ||
should.equal user.id, @stubs.user.id | ||
should.equal user.name, @stubs.user.name | ||
should.equal user.real_name, @stubs.user.real_name | ||
should.equal user.email_address, @stubs.user.profile.email | ||
should.equal user.slack.misc, @stubs.user.misc | ||
|
||
client = new SlackClient {token: 'xoxb-faketoken'}, @stubs.robot | ||
|
||
modified_user = | ||
id: @stubs.user.id | ||
name: 'modified_name' | ||
real_name: @stubs.user.real_name | ||
profile: | ||
email: @stubs.user.profile.email | ||
client: | ||
client | ||
|
||
@slackbot.userChange(modified_user) | ||
|
||
user = @slackbot.robot.brain.data.users[@stubs.user.id] | ||
should.equal user.id, @stubs.user.id | ||
should.equal user.name, modified_user.name | ||
should.equal user.real_name, @stubs.user.real_name | ||
should.equal user.email_address, @stubs.user.profile.email | ||
should.equal user.slack.misc, undefined | ||
should.equal user.slack.client, undefined | ||
|
||
it 'Should ignore user data which is undefined', -> | ||
@slackbot.userChange(undefined) | ||
users = @slackbot.robot.brain.data.users | ||
should.equal Object.keys(users).length, 0 | ||
|
||
it 'Should load users data from web api', -> | ||
@slackbot.loadUsers(null, @stubs.responseUsersList) | ||
|
||
user = @slackbot.robot.brain.data.users[@stubs.user.id] | ||
should.equal user.id, @stubs.user.id | ||
should.equal user.name, @stubs.user.name | ||
should.equal user.real_name, @stubs.user.real_name | ||
should.equal user.email_address, @stubs.user.profile.email | ||
should.equal user.slack.misc, @stubs.user.misc | ||
|
||
userperiod = @slackbot.robot.brain.data.users[@stubs.userperiod.id] | ||
should.equal userperiod.id, @stubs.userperiod.id | ||
should.equal userperiod.name, @stubs.userperiod.name | ||
should.equal userperiod.real_name, @stubs.userperiod.real_name | ||
should.equal userperiod.email_address, @stubs.userperiod.profile.email | ||
|
||
it 'Should detect wrong response from web api', -> | ||
@slackbot.loadUsers(null, @stubs.wrongResponseUsersList) | ||
should.equal @slackbot.robot.brain.data.users[@stubs.user.id], undefined |
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.
can we store
id: user.id
in here as well? if the idea that Slack-specific properties should go inside theslack
property, then this is already not working since the ID that the user will be identified with in the brain is the Slack ID.