slack_agent_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require 'spec_helper'
  2. describe Agents::SlackAgent do
  3. before(:each) do
  4. @valid_params = {
  5. 'auth_token' => 'token',
  6. 'team_name' => 'testteam',
  7. 'channel' => '#random',
  8. 'username' => "{{username}}",
  9. 'message' => "{{message}}"
  10. }
  11. @checker = Agents::SlackAgent.new(:name => "slacker", :options => @valid_params)
  12. @checker.user = users(:jane)
  13. @checker.save!
  14. @event = Event.new
  15. @event.agent = agents(:bob_weather_agent)
  16. @event.payload = { :channel => '#random', :message => 'Looks like its going to rain', username: "Huggin user"}
  17. @event.save!
  18. end
  19. describe "validating" do
  20. before do
  21. expect(@checker).to be_valid
  22. end
  23. it "should require a auth_token" do
  24. @checker.options['auth_token'] = nil
  25. expect(@checker).not_to be_valid
  26. end
  27. it "should require a channel" do
  28. @checker.options['channel'] = nil
  29. expect(@checker).not_to be_valid
  30. end
  31. it "should require a team_name" do
  32. @checker.options['team_name'] = 'nil'
  33. expect(@checker).to be_valid
  34. end
  35. end
  36. describe "#receive" do
  37. it "receive an event without errors" do
  38. any_instance_of(Slack::Notifier) do |obj|
  39. mock(obj).ping(@event.payload[:message],
  40. channel: @event.payload[:channel],
  41. username: @event.payload[:username]
  42. )
  43. end
  44. expect { @checker.receive([@event]) }.not_to raise_error
  45. end
  46. end
  47. describe "#working?" do
  48. it "should call received_event_without_error?" do
  49. mock(@checker).received_event_without_error?
  50. @checker.working?
  51. end
  52. end
  53. end