slack_agent_spec.rb 1.8 KB

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