google_flights_spec.rb 2.9 KB

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. 'preferredCabin' => 'COACH',
  16. 'childCount' => 0,
  17. 'infantInSeatCount' => 0,
  18. 'infantInLapCount'=> 0,
  19. 'seniorCount'=> 0,
  20. 'solutions'=> 3
  21. }
  22. @checker = Agents::GoogleFlightsAgent.new(:name => "tectonic", :options => @opts)
  23. @checker.user = users(:bob)
  24. @checker.save!
  25. end
  26. describe '#helpers' do
  27. it "should generate the correct events url" do
  28. expect(@checker.send(:event_url)).to eq("https://www.googleapis.com/qpxExpress/v1/trips/search?key=800deeaf-e285-9d62-bc90-j999c1973cc9")
  29. end
  30. end
  31. describe "#that checker should be valid" do
  32. it "should check that the object is valid" do
  33. expect(@checker).to be_valid
  34. end
  35. it "should require credentials" do
  36. @checker.options['qpx_api_key'] = nil
  37. expect(@checker).not_to be_valid
  38. end
  39. it "should require adultCount" do
  40. @checker.options['adultCount'] = nil
  41. expect(@checker).not_to be_valid
  42. end
  43. it "should require Origin" do
  44. @checker.options['origin'] = nil
  45. expect(@checker).not_to be_valid
  46. end
  47. it "should require Destination" do
  48. @checker.options['destination'] = nil
  49. expect(@checker).not_to be_valid
  50. end
  51. it "should require Date" do
  52. @checker.options['date'] = nil
  53. expect(@checker).not_to be_valid
  54. end
  55. it "should require childCount" do
  56. @checker.options['childCount'] = nil
  57. expect(@checker).not_to be_valid
  58. end
  59. it "should require Infant In Seat Count" do
  60. @checker.options['infantInSeatCount'] = nil
  61. expect(@checker).not_to be_valid
  62. end
  63. it "should require Infant In Lab Count" do
  64. @checker.options['infantInLapCount'] = nil
  65. expect(@checker).not_to be_valid
  66. end
  67. it "should require Senior Count" do
  68. @checker.options['seniorCount'] = nil
  69. expect(@checker).not_to be_valid
  70. end
  71. it "should require Solutions" do
  72. @checker.options['solutions'] = nil
  73. expect(@checker).not_to be_valid
  74. end
  75. it "should require Return Date" do
  76. @checker.options['roundtrip'] = true
  77. @checker.options['return_date'] = nil
  78. expect(@checker).not_to be_valid
  79. end
  80. end
  81. describe '#check' do
  82. it "should check that initial run creates an event" do
  83. @checker.memory[:latestTicketingTime] = '2016-03-24T23:59-04:00'
  84. expect { @checker.check }.to change { Event.count }.by(1)
  85. end
  86. end
  87. end