Keine Beschreibung http://j1x-huginn.herokuapp.com

aftership_agent_spec.rb 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'rails_helper'
  2. describe Agents::AftershipAgent do
  3. before do
  4. @opts = {
  5. "api_key" => '800deeaf-e285-9d62-bc90-j999c1973cc9',
  6. "get" => 'trackings',
  7. "slug" => 'usps',
  8. "tracking_number" => "9361289684090010005054"
  9. }
  10. @checker = Agents::AftershipAgent.new(:name => "tectonic", :options => @opts)
  11. @checker.user = users(:bob)
  12. @checker.save!
  13. end
  14. describe '#helpers' do
  15. it "should return the correct request header" do
  16. expect(@checker.send(:request_options)).to eq({:headers => {"aftership-api-key" => '800deeaf-e285-9d62-bc90-j999c1973cc9', "Content-Type"=>"application/json"}})
  17. end
  18. it "should generate the correct events url" do
  19. expect(@checker.send(:event_url)).to eq("https://api.aftership.com/v4/trackings")
  20. end
  21. it "should generate the correct single or checkpoint tracking url" do
  22. expect(@checker.send(:single_or_checkpoint_tracking_url)).to eq("https://api.aftership.com/v4/trackings/usps/9361289684090010005054")
  23. end
  24. end
  25. describe "#that checker should be valid" do
  26. it "should check that the aftership object is valid" do
  27. expect(@checker).to be_valid
  28. end
  29. it "should require credentials" do
  30. @checker.options['api_key'] = nil
  31. expect(@checker).not_to be_valid
  32. end
  33. end
  34. describe "get request must exist" do
  35. it "should check that validation added if get does not exist" do
  36. opts = @opts.tap { |o| o.delete('get') }
  37. @checker = Agents::AftershipAgent.new(:name => "tectonic", :options => opts)
  38. @checker.user = users(:bob)
  39. expect(@checker.save).to eq false
  40. expect(@checker.errors.full_messages.first).to eq("You need to specify a get request")
  41. end
  42. end
  43. describe '#check'
  44. end