slack_agent_spec.rb 2.0 KB

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