google_flights_spec.rb 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. require 'rails_helper'
  2. describe Agents::GoogleFlightsAgent 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::GoogleFlightsAgent.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. it "should require Return Date" do
  75. @checker.options['roundtrip'] = true
  76. @checker.options['return_date'] = nil
  77. expect(@checker).not_to be_valid
  78. end
  79. end
  80. describe '#check' do
  81. it "should check that initial run creates an event" do
  82. @checker.memory[:latestTicketingTime] = '2016-03-24T23:59-04:00'
  83. expect { @checker.check }.to change { Event.count }.by(1)
  84. end
  85. end
  86. end