qpx_spec.rb 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. require 'rails_helper'
  2. describe Agents::QpxAgent do
  3. before do
  4. stub_request(:post, "https://www.googleapis.com/qpxExpress/v1/trips/search?key=800deeaf-e285-9d62-bc90-j999c1973cc9").to_return(
  5. :body => File.read(Rails.root.join("spec/data_fixtures/qpx.json")),
  6. :status => 200,
  7. :headers => {"Content-Type" => "application/json"}
  8. )
  9. @opts = {
  10. 'qpx_api_key' => '800deeaf-e285-9d62-bc90-j999c1973cc9',
  11. 'adultCount' => 1,
  12. 'origin' => 'BOS',
  13. 'destination' => 'SFO',
  14. 'date' => '2016-04-11',
  15. 'childCount' => 0,
  16. 'infantInSeatCount' => 0,
  17. 'infantInLapCount'=> 0,
  18. 'seniorCount'=> 0,
  19. 'solutions'=> 3
  20. }
  21. @checker = Agents::QpxAgent.new(:name => "tectonic", :options => @opts)
  22. @checker.user = users(:bob)
  23. @checker.save!
  24. end
  25. describe '#helpers' do
  26. it "should generate the correct events url" do
  27. expect(@checker.send(:event_url)).to eq("https://www.googleapis.com/qpxExpress/v1/trips/search?key=800deeaf-e285-9d62-bc90-j999c1973cc9")
  28. end
  29. end
  30. describe "#that checker should be valid" do
  31. it "should check that the object is valid" do
  32. expect(@checker).to be_valid
  33. end
  34. it "should require credentials" do
  35. @checker.options['qpx_api_key'] = nil
  36. expect(@checker).not_to be_valid
  37. end
  38. it "should require adultCount" do
  39. @checker.options['adultCount'] = nil
  40. expect(@checker).not_to be_valid
  41. end
  42. it "should require Origin" do
  43. @checker.options['origin'] = nil
  44. expect(@checker).not_to be_valid
  45. end
  46. it "should require Destination" do
  47. @checker.options['destination'] = nil
  48. expect(@checker).not_to be_valid
  49. end
  50. it "should require Date" do
  51. @checker.options['date'] = nil
  52. expect(@checker).not_to be_valid
  53. end
  54. it "should require childCount" do
  55. @checker.options['childCount'] = nil
  56. expect(@checker).not_to be_valid
  57. end
  58. it "should require Infant In Seat Count" do
  59. @checker.options['infantInSeatCount'] = nil
  60. expect(@checker).not_to be_valid
  61. end
  62. it "should require Infant In Lab Count" do
  63. @checker.options['infantInLapCount'] = nil
  64. expect(@checker).not_to be_valid
  65. end
  66. it "should require Senior Count" do
  67. @checker.options['seniorCount'] = nil
  68. expect(@checker).not_to be_valid
  69. end
  70. it "should require Solutions" do
  71. @checker.options['solutions'] = nil
  72. expect(@checker).not_to be_valid
  73. end
  74. end
  75. describe '#check' do
  76. it "should check that initial run creates an event" do
  77. @checker.memory[:latestTicketingTime] = '2016-03-24T23:59-04:00'
  78. expect { @checker.check }.to change { Event.count }.by(1)
  79. end
  80. end
  81. end