Няма описание http://j1x-huginn.herokuapp.com

pushbullet_agent_spec.rb 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. require 'spec_helper'
  2. require 'models/concerns/liquid_interpolatable'
  3. describe Agents::PushbulletAgent do
  4. it_behaves_like LiquidInterpolatable
  5. before(:each) do
  6. @valid_params = {
  7. 'api_key' => 'token',
  8. 'device_id' => '124',
  9. 'body' => '{{body}}',
  10. 'title' => 'hello from huginn'
  11. }
  12. @checker = Agents::PushbulletAgent.new(:name => "somename", :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 = { :body => 'One two test' }
  18. @event.save!
  19. end
  20. describe "validating" do
  21. before do
  22. @checker.should be_valid
  23. end
  24. it "should require the api_key" do
  25. @checker.options['api_key'] = nil
  26. @checker.should_not be_valid
  27. end
  28. it "should require the device_id" do
  29. @checker.options['device_id'] = nil
  30. @checker.should_not be_valid
  31. end
  32. end
  33. describe "helpers" do
  34. it "should return the query_options" do
  35. @checker.send(:query_options, @event).should == {
  36. :body => {:title => 'hello from huginn', :body => 'One two test', :device_iden => @checker.options[:device_id], :type => 'note'},
  37. :basic_auth => {:username =>@checker.options[:api_key], :password=>''}
  38. }
  39. end
  40. end
  41. describe "#receive" do
  42. it "send a message to the hipchat" do
  43. stub_request(:post, "https://token:@api.pushbullet.com/api/pushes").
  44. with(:body => "device_iden=124&title=hello%20from%20huginn&body=One%20two%20test&type=note").
  45. to_return(:status => 200, :body => "ok", :headers => {})
  46. dont_allow(@checker).error
  47. @checker.receive([@event])
  48. end
  49. it "should log resquests which return an error" do
  50. stub_request(:post, "https://token:@api.pushbullet.com/api/pushes").
  51. with(:body => "device_iden=124&title=hello%20from%20huginn&body=One%20two%20test&type=note").
  52. to_return(:status => 200, :body => "error", :headers => {})
  53. mock(@checker).error("error")
  54. @checker.receive([@event])
  55. end
  56. end
  57. describe "#working?" do
  58. it "should not be working until the first event was received" do
  59. @checker.should_not be_working
  60. @checker.last_receive_at = Time.now
  61. @checker.should be_working
  62. end
  63. end
  64. end