quicktravel_client 1.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +14 -2
  5. data/CHANGELOG.md +34 -3
  6. data/Gemfile +0 -3
  7. data/Rakefile +0 -6
  8. data/examples/login_example.rb +1 -1
  9. data/gemfiles/rails4.gemfile +9 -0
  10. data/lib/quick_travel.rb +2 -1
  11. data/lib/quick_travel/accommodation.rb +1 -15
  12. data/lib/quick_travel/adapter.rb +98 -67
  13. data/lib/quick_travel/{adapter_exception.rb → adapter_error.rb} +1 -1
  14. data/lib/quick_travel/address.rb +2 -7
  15. data/lib/quick_travel/adjustment.rb +0 -2
  16. data/lib/quick_travel/bed_configuration.rb +0 -1
  17. data/lib/quick_travel/bed_requirement.rb +0 -1
  18. data/lib/quick_travel/booking.rb +22 -46
  19. data/lib/quick_travel/cache.rb +8 -14
  20. data/lib/quick_travel/checkout.rb +1 -1
  21. data/lib/quick_travel/client.rb +2 -4
  22. data/lib/quick_travel/client_type.rb +2 -1
  23. data/lib/quick_travel/connection_error.rb +1 -1
  24. data/lib/quick_travel/constants.rb +0 -1
  25. data/lib/quick_travel/contact.rb +0 -1
  26. data/lib/quick_travel/country.rb +0 -3
  27. data/lib/quick_travel/document.rb +0 -2
  28. data/lib/quick_travel/document_group.rb +0 -2
  29. data/lib/quick_travel/location.rb +0 -2
  30. data/lib/quick_travel/party.rb +7 -12
  31. data/lib/quick_travel/passenger.rb +0 -1
  32. data/lib/quick_travel/passenger_price_break.rb +0 -2
  33. data/lib/quick_travel/passenger_type.rb +0 -2
  34. data/lib/quick_travel/payment.rb +0 -3
  35. data/lib/quick_travel/payment_type.rb +4 -13
  36. data/lib/quick_travel/price_changes.rb +3 -0
  37. data/lib/quick_travel/price_changes/booking_price_change.rb +30 -0
  38. data/lib/quick_travel/price_changes/price_change.rb +23 -0
  39. data/lib/quick_travel/{discounts/discount_tree.rb → price_changes/price_change_tree.rb} +12 -8
  40. data/lib/quick_travel/product.rb +15 -28
  41. data/lib/quick_travel/product_type.rb +4 -16
  42. data/lib/quick_travel/property.rb +4 -20
  43. data/lib/quick_travel/property_facility.rb +0 -1
  44. data/lib/quick_travel/property_type.rb +2 -14
  45. data/lib/quick_travel/region.rb +0 -9
  46. data/lib/quick_travel/reservation.rb +0 -21
  47. data/lib/quick_travel/resource.rb +7 -28
  48. data/lib/quick_travel/room_facility.rb +0 -1
  49. data/lib/quick_travel/route.rb +9 -25
  50. data/lib/quick_travel/route_stop.rb +0 -1
  51. data/lib/quick_travel/service.rb +2 -1
  52. data/lib/quick_travel/status.rb +23 -0
  53. data/lib/quick_travel/trip.rb +0 -1
  54. data/lib/quick_travel/vehicle.rb +2 -4
  55. data/lib/quick_travel/vehicle_type.rb +0 -3
  56. data/lib/quick_travel/version.rb +1 -1
  57. data/quicktravel_client.gemspec +4 -4
  58. data/spec/booking_spec.rb +24 -0
  59. data/spec/discounts_spec.rb +69 -69
  60. data/spec/passenger_type_spec.rb +30 -0
  61. data/spec/payment_type_spec.rb +10 -0
  62. data/spec/product_spec.rb +52 -21
  63. data/spec/product_type_spec.rb +19 -0
  64. data/spec/property_spec.rb +83 -0
  65. data/spec/region_spec.rb +1 -1
  66. data/spec/reservation_spec.rb +3 -2
  67. data/spec/resource_spec.rb +31 -7
  68. data/spec/route_spec.rb +118 -0
  69. data/spec/spec_helper.rb +18 -25
  70. data/spec/status_spec.rb +9 -0
  71. data/spec/support/cassettes/booking_create.yml +39 -33
  72. data/spec/support/cassettes/booking_documents.yml +36 -30
  73. data/spec/support/cassettes/booking_price_changes.yml +66 -0
  74. data/spec/support/cassettes/booking_show.yml +38 -32
  75. data/spec/support/cassettes/booking_update.yml +74 -62
  76. data/spec/support/cassettes/booking_with_documents.yml +88 -76
  77. data/spec/support/cassettes/booking_with_nested_attributes.yml +128 -110
  78. data/spec/support/cassettes/booking_with_price_changes.yml +86 -0
  79. data/spec/support/cassettes/countries.yml +140 -0
  80. data/spec/support/cassettes/country_all.yml +36 -30
  81. data/spec/support/cassettes/create_reservation_fail.yml +32 -27
  82. data/spec/support/cassettes/create_reservation_with_booking.yml +40 -34
  83. data/spec/support/cassettes/passenger_all.yml +36 -30
  84. data/spec/support/cassettes/payment_info.yml +61 -0
  85. data/spec/support/cassettes/product_date_range_bookability.yml +61 -59
  86. data/spec/support/cassettes/product_show.yml +42 -32
  87. data/spec/support/cassettes/product_show_as_agent.yml +63 -0
  88. data/spec/support/cassettes/product_type_all.yml +53 -0
  89. data/spec/support/cassettes/property.yml +66 -0
  90. data/spec/support/cassettes/region_show.yml +36 -30
  91. data/spec/support/cassettes/reservation_with_extra_picks.yml +137 -110
  92. data/spec/support/cassettes/resource_fare_bases.yml +47 -78
  93. data/spec/support/cassettes/resource_product_type.yml +63 -0
  94. data/spec/support/cassettes/resource_show.yml +37 -31
  95. data/spec/support/cassettes/resource_with_price.yml +63 -0
  96. data/spec/support/cassettes/route_all.yml +65 -0
  97. data/spec/support/cassettes/tenant_switcher.yml +109 -0
  98. data/spec/support/coverage_loader.rb +26 -0
  99. data/spec/tenant_spec.rb +28 -0
  100. metadata +106 -115
  101. data/bootstrap/boot.rb +0 -4
  102. data/lib/quick_travel/discounts.rb +0 -3
  103. data/lib/quick_travel/discounts/booking_discount.rb +0 -18
  104. data/lib/quick_travel/discounts/discount.rb +0 -21
  105. data/spec/support/cassettes/booking_create_legacy.yml +0 -50
  106. data/spec/support/cassettes/booking_discounts.yml +0 -53
  107. data/spec/support/cassettes/booking_with_discounts.yml +0 -72
  108. data/spec/support/cassettes/region_index.yml +0 -48
@@ -0,0 +1,23 @@
1
+ module QuickTravel
2
+ class Status
3
+ def self.key
4
+ # NOTE: This is not pretty, but we need to use a unique key per server
5
+ @key ||= "status-check##{SecureRandom.hex}"
6
+ end
7
+
8
+ def self.check!
9
+ # Test Cache
10
+ QuickTravel::Cache.delete(key)
11
+ QuickTravel::Cache.cache(key) { 'start' }
12
+ unless QuickTravel::Cache.cache(key) == 'start'
13
+ fail RuntimeError, 'Failed to cache status-check'
14
+ end
15
+
16
+ QuickTravel::Cache.delete(key)
17
+ QuickTravel::Cache.cache(key) { nil }
18
+ unless QuickTravel::Cache.cache(key) == nil
19
+ fail RuntimeError, 'Failed to clear status-check cache'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,6 +3,5 @@ require 'quick_travel/adapter'
3
3
  module QuickTravel
4
4
  class Trip < Adapter
5
5
  self.api_base = '/api/trips'
6
- attr_accessor :route_id
7
6
  end
8
7
  end
@@ -2,16 +2,14 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class Vehicle < Adapter
5
- attr_accessor :id, :vehicle_type_id, :registration, :length, :linked_to, :vehicle_type_name, :details
6
-
7
5
  def self.create(booking_id, vehicle_types = {})
8
6
  options = { booking_id: booking_id, vehicle_types: vehicle_types }
9
7
  response = post_and_validate("#{Booking.front_office_base}/#{booking_id}/vehicles.json", options)
10
- fail AdapterException.new(response) unless response.key?('booking_id')
8
+ fail AdapterError.new(response) unless response.key?('booking_id')
11
9
  end
12
10
 
13
11
  def vehicle_type
14
- VehicleType.all.detect { |vt| vt.id == vehicle_type_id }
12
+ VehicleType.find(vehicle_type_id)
15
13
  end
16
14
  end
17
15
  end
@@ -2,9 +2,6 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class VehicleType < Adapter
5
- attr_accessor :id, :name, :position, :code, :default_weight, :description, :detail_prompt, :double_length, :fixed_length, :fixed_weight
6
- attr_accessor :has_cargo, :default, :maximum_length, :minimum_length, :trailer
7
-
8
5
  self.api_base = '/vehicle_types'
9
6
  self.lookup = true
10
7
  end
@@ -1,3 +1,3 @@
1
1
  module QuickTravel
2
- VERSION = '1.1.2'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -16,10 +16,9 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ['lib']
18
18
 
19
- spec.add_dependency 'httparty', '0.13.5'
19
+ spec.add_dependency 'httparty'
20
20
  spec.add_dependency 'geokit', '~> 1.8.3' # used in address model
21
21
  spec.add_dependency 'activesupport', '>= 2.0.0'
22
- spec.add_dependency 'money_extensions'
23
22
  spec.add_dependency 'facets'
24
23
  spec.add_dependency 'money', '>= 3.0', '< 6.0' # 6.0 starts to deprecate/split
25
24
 
@@ -31,7 +30,8 @@ Gem::Specification.new do |spec|
31
30
  spec.add_development_dependency 'simplecov-rcov'
32
31
  spec.add_development_dependency 'coveralls'
33
32
  spec.add_development_dependency 'stamp' # Used to send appropriate dates to API's
34
- spec.add_development_dependency 'vcr', '2.9.3'
35
- spec.add_development_dependency 'fakeweb'
33
+ spec.add_development_dependency 'vcr'
34
+ spec.add_development_dependency 'webmock'
36
35
  spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'travis'
37
37
  end
data/spec/booking_spec.rb CHANGED
@@ -77,11 +77,35 @@ end
77
77
 
78
78
  describe QuickTravel::Booking do
79
79
  let(:booking) { QuickTravel::Booking.find(1) }
80
+
80
81
  it 'should have booking documents' do
81
82
  VCR.use_cassette('booking_with_documents') do
82
83
  expect(booking.documents.size).to eq 1
83
84
  end
84
85
  end
86
+
87
+ it 'should not have associated client objects' do
88
+ VCR.use_cassette('booking_with_documents') do
89
+ expect(booking.client).to be nil
90
+ expect(booking.client_party).to be nil
91
+ expect(booking.client_contact).to be nil
92
+ expect(booking.client_address).to be nil
93
+ end
94
+ end
95
+
96
+ let(:accom_product_type_id) { 2 }
97
+
98
+ it '#include_reservation_of?' do
99
+ VCR.use_cassette('booking_with_documents') do
100
+ expect(booking.include_reservation_of?(accom_product_type_id)).to be true
101
+ end
102
+ end
103
+
104
+ it '#includes_resource_class?' do
105
+ VCR.use_cassette('booking_with_documents') do
106
+ expect(booking.includes_resource_class?('Accommodation')).to be true
107
+ end
108
+ end
85
109
  end
86
110
 
87
111
  describe QuickTravel::Booking do
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
  require 'quick_travel/reservation'
3
3
  require 'quick_travel/booking'
4
4
 
5
- describe 'Booking discounts' do
5
+ describe 'Booking price_changes' do
6
6
  let(:booking) do
7
- VCR.use_cassette('booking_with_discounts') do
7
+ VCR.use_cassette('booking_with_price_changes') do
8
8
  QuickTravel::Booking.find_by_reference('222223')
9
9
  end
10
10
  end
@@ -13,109 +13,109 @@ describe 'Booking discounts' do
13
13
  QuickTravel.config.version = 4
14
14
  end
15
15
 
16
- context 'when the booking has a discount' do
17
- let(:reservation) { booking.reservations.first }
18
- let(:extra_pick_without_discount) { reservation.sub_reservations.first }
19
- let(:extra_pick_with_discount) { reservation.sub_reservations.second }
16
+ context 'when the booking has a price_change' do
17
+ let(:reservation) { booking.reservations.first }
18
+ let(:extra_pick_without_price_change) { reservation.sub_reservations.first }
19
+ let(:extra_pick_with_price_change) { reservation.sub_reservations.second }
20
20
 
21
- let(:discount) do
22
- VCR.use_cassette('booking_discounts') do
23
- booking.discount
21
+ let(:price_change) do
22
+ VCR.use_cassette('booking_price_changes') do
23
+ booking.price_change
24
24
  end
25
25
  end
26
26
 
27
- specify { expect(discount.target.type).to eq 'Booking' }
28
- specify { expect(discount.target.id).to eq booking.id }
29
- specify { expect(discount.original_price).to eq 640.00 }
30
- specify { expect(discount.discounted_price).to eq 380.00 }
31
- specify { expect(discount.discount).to eq(-260.00) }
27
+ specify { expect(price_change.target.type).to eq 'Booking' }
28
+ specify { expect(price_change.target.id).to eq booking.id }
29
+ specify { expect(price_change.original_price).to eq 640.00 }
30
+ specify { expect(price_change.changed_price).to eq 380.00 }
31
+ specify { expect(price_change.price_change).to eq(-260.00) }
32
32
  specify do
33
- expect(discount.reservation_discounts.count).to(
33
+ expect(price_change.reservation_price_changes.count).to(
34
34
  eq booking.reservations.count)
35
35
  end
36
36
 
37
- context 'the discount applied on the top level reservation' do
38
- let(:discount) do
39
- VCR.use_cassette('booking_discounts') do
40
- booking.discount_on(reservation)
37
+ context 'the price_change applied on the top level reservation' do
38
+ let(:price_change) do
39
+ VCR.use_cassette('booking_price_changes') do
40
+ booking.price_change_on(reservation)
41
41
  end
42
42
  end
43
43
 
44
- specify { expect(discount.target.type).to eq 'Reservation' }
45
- specify { expect(discount.target.id).to eq reservation.id }
46
- specify { expect(discount.original_price).to eq 400.00 }
47
- specify { expect(discount.discounted_price).to eq 200.00 }
48
- specify { expect(discount.discount).to eq(-200) }
44
+ specify { expect(price_change.target.type).to eq 'Reservation' }
45
+ specify { expect(price_change.target.id).to eq reservation.id }
46
+ specify { expect(price_change.original_price).to eq 400.00 }
47
+ specify { expect(price_change.changed_price).to eq 200.00 }
48
+ specify { expect(price_change.price_change).to eq(-200) }
49
49
  end
50
50
 
51
- context 'the total discount applied on the top level reservation' do
52
- subject(:discount) do
53
- VCR.use_cassette('booking_discounts') do
54
- booking.total_discount_on(reservation)
51
+ context 'the total price_change applied on the top level reservation' do
52
+ subject(:price_change) do
53
+ VCR.use_cassette('booking_price_changes') do
54
+ booking.total_price_change_on(reservation)
55
55
  end
56
56
  end
57
57
 
58
- specify { expect(discount.target.type).to eq 'Reservation' }
59
- specify { expect(discount.target.id).to eq reservation.id }
60
- specify { expect(discount.original_price).to eq 640.00 }
61
- specify { expect(discount.discounted_price).to eq 380.00 }
62
- specify { expect(discount.discount).to eq(-260.00) }
58
+ specify { expect(price_change.target.type).to eq 'Reservation' }
59
+ specify { expect(price_change.target.id).to eq reservation.id }
60
+ specify { expect(price_change.original_price).to eq 640.00 }
61
+ specify { expect(price_change.changed_price).to eq 380.00 }
62
+ specify { expect(price_change.price_change).to eq(-260.00) }
63
63
  end
64
64
 
65
- context 'the discount applied on the first extra pick' do
66
- let(:discount) do
67
- VCR.use_cassette('booking_discounts') do
68
- booking.discount_on(extra_pick_without_discount)
65
+ context 'the price_change applied on the first extra pick' do
66
+ let(:price_change) do
67
+ VCR.use_cassette('booking_price_changes') do
68
+ booking.price_change_on(extra_pick_without_price_change)
69
69
  end
70
70
  end
71
71
 
72
- specify { expect(discount.target.type).to eq 'Reservation' }
73
- specify { expect(discount.target.id).to eq extra_pick_without_discount.id }
74
- specify { expect(discount.original_price).to eq 120 }
75
- specify { expect(discount.discounted_price).to eq 120 }
76
- specify { expect(discount.discount).to eq 0 }
72
+ specify { expect(price_change.target.type).to eq 'Reservation' }
73
+ specify { expect(price_change.target.id).to eq extra_pick_without_price_change.id }
74
+ specify { expect(price_change.original_price).to eq 120 }
75
+ specify { expect(price_change.changed_price).to eq 120 }
76
+ specify { expect(price_change.price_change).to eq 0 }
77
77
  end
78
78
 
79
- context 'the total discount applied on the first extra pick' do
80
- let(:discount) do
81
- VCR.use_cassette('booking_discounts') do
82
- booking.total_discount_on(extra_pick_without_discount)
79
+ context 'the total price_change applied on the first extra pick' do
80
+ let(:price_change) do
81
+ VCR.use_cassette('booking_price_changes') do
82
+ booking.total_price_change_on(extra_pick_without_price_change)
83
83
  end
84
84
  end
85
85
 
86
- specify { expect(discount.target.type).to eq 'Reservation' }
87
- specify { expect(discount.target.id).to eq extra_pick_without_discount.id }
88
- specify { expect(discount.original_price).to eq 120 }
89
- specify { expect(discount.discounted_price).to eq 120 }
90
- specify { expect(discount.discount).to eq 0 }
86
+ specify { expect(price_change.target.type).to eq 'Reservation' }
87
+ specify { expect(price_change.target.id).to eq extra_pick_without_price_change.id }
88
+ specify { expect(price_change.original_price).to eq 120 }
89
+ specify { expect(price_change.changed_price).to eq 120 }
90
+ specify { expect(price_change.price_change).to eq 0 }
91
91
  end
92
92
 
93
- context 'the discount applied on second extra pick' do
94
- let(:discount) do
95
- VCR.use_cassette('booking_discounts') do
96
- booking.discount_on(extra_pick_with_discount)
93
+ context 'the price_change applied on second extra pick' do
94
+ let(:price_change) do
95
+ VCR.use_cassette('booking_price_changes') do
96
+ booking.price_change_on(extra_pick_with_price_change)
97
97
  end
98
98
  end
99
99
 
100
- specify { expect(discount.target.type).to eq 'Reservation' }
101
- specify { expect(discount.target.id).to eq extra_pick_with_discount.id }
102
- specify { expect(discount.original_price).to eq 120.00 }
103
- specify { expect(discount.discounted_price).to eq 60.00 }
104
- specify { expect(discount.discount).to eq(-60.00) }
100
+ specify { expect(price_change.target.type).to eq 'Reservation' }
101
+ specify { expect(price_change.target.id).to eq extra_pick_with_price_change.id }
102
+ specify { expect(price_change.original_price).to eq 120.00 }
103
+ specify { expect(price_change.changed_price).to eq 60.00 }
104
+ specify { expect(price_change.price_change).to eq(-60.00) }
105
105
  end
106
106
 
107
- context 'the total discount applied on second extra pick' do
108
- let(:discount) do
109
- VCR.use_cassette('booking_discounts') do
110
- booking.total_discount_on(extra_pick_with_discount)
107
+ context 'the total price_change applied on second extra pick' do
108
+ let(:price_change) do
109
+ VCR.use_cassette('booking_price_changes') do
110
+ booking.total_price_change_on(extra_pick_with_price_change)
111
111
  end
112
112
  end
113
113
 
114
- specify { expect(discount.target.type).to eq 'Reservation' }
115
- specify { expect(discount.target.id).to eq extra_pick_with_discount.id }
116
- specify { expect(discount.original_price).to eq 120.00 }
117
- specify { expect(discount.discounted_price).to eq 60.00 }
118
- specify { expect(discount.discount).to eq(-60.00) }
114
+ specify { expect(price_change.target.type).to eq 'Reservation' }
115
+ specify { expect(price_change.target.id).to eq extra_pick_with_price_change.id }
116
+ specify { expect(price_change.original_price).to eq 120.00 }
117
+ specify { expect(price_change.changed_price).to eq 60.00 }
118
+ specify { expect(price_change.price_change).to eq(-60.00) }
119
119
  end
120
120
  end
121
121
  end
@@ -29,4 +29,34 @@ describe QuickTravel::PassengerType do
29
29
  it { should eq ['2 Adults'] }
30
30
  end
31
31
  end
32
+
33
+ context 'caching of collection' do
34
+ subject(:all) do
35
+ VCR.use_cassette('passenger_all') { QuickTravel::PassengerType.all }
36
+ end
37
+
38
+ let(:api) { double }
39
+
40
+ before do
41
+ stub_const('QuickTravel::Api', api)
42
+ allow(api).to receive(:call_and_validate) { [{id: 1}, {id: 2}] }
43
+ end
44
+
45
+ context 'when called the first time' do
46
+ before do
47
+ QuickTravel::Cache.cache_store.clear
48
+ all
49
+ end
50
+
51
+ specify { expect(api).to have_received(:call_and_validate).once }
52
+
53
+ context 'when called again' do
54
+ before do
55
+ QuickTravel::PassengerType.all
56
+ end
57
+
58
+ specify { expect(api).to have_received(:call_and_validate).once } # not called again
59
+ end
60
+ end
61
+ end
32
62
  end
@@ -15,4 +15,14 @@ describe QuickTravel::PaymentType do
15
15
  let(:brand) { 'American Express' }
16
16
  its(:code) { should eq 'american_express' }
17
17
  end
18
+
19
+ context 'payment info' do
20
+ it 'should fetch payment info' do
21
+ VCR.use_cassette 'payment_info' do
22
+ expect(QuickTravel::PaymentType.information).to eq(
23
+ 'poli_pay' => { 'login' => 'S1234567' }
24
+ )
25
+ end
26
+ end
27
+ end
18
28
  end
data/spec/product_spec.rb CHANGED
@@ -2,9 +2,18 @@ require 'spec_helper'
2
2
  require 'quick_travel/product'
3
3
 
4
4
  describe QuickTravel::Product do
5
+ let(:today) { '2016-03-01'.to_date }
6
+ let(:options) {
7
+ {
8
+ first_travel_date: today,
9
+ passenger_type_numbers: {'1' => 1},
10
+ rack_price_requested: true,
11
+ date_range: {start_date: today, end_date: today + 1}
12
+ }
13
+ }
14
+
5
15
  before do
6
16
  VCR.use_cassette('product_show') do
7
- today = '2016-03-01'.to_date
8
17
  @product = QuickTravel::Product.find(6, # Executive Room
9
18
  first_travel_date: today,
10
19
  passenger_type_numbers: { '1' => 1 },
@@ -15,32 +24,52 @@ describe QuickTravel::Product do
15
24
 
16
25
  it 'should create a useful product object' do
17
26
  expect(@product.pricing_details.minimum_price).to eq 400.to_money
18
- # @product.pricing_details_for_rack_rate.should_not be_present # TODO: Record new VCRs with new QT code
27
+ expect(@product.pricing_details_for_rack_rate).to_not be_present
28
+ end
29
+
30
+ it 'should return a rack minimum price when requested due to agent being logged in' do
31
+ VCR.use_cassette('product_show_as_agent') do
32
+ @product = QuickTravel::Product.find(6, options)
33
+ end
34
+
35
+ expect(@product.pricing_details_for_rack_rate).to be_present
36
+ end
37
+
38
+ it 'should ensure id is passed in correctly before calling' do
39
+ expect {
40
+ QuickTravel::Product.find(nil, options)
41
+ }.to raise_error(
42
+ ArgumentError,
43
+ 'id must be an integer'
44
+ )
19
45
  end
20
46
 
21
- # TODO: Record new VCRs with new QT code
22
- # it 'should return a rack minimum price when requested due to agent being logged in' do
23
- # VCR.use_cassette('product_show_as_agent') do
24
- # today = '2013-02-14'.to_date
25
- # @product = QuickTravel::Product.find(195,
26
- # first_travel_date: today,
27
- # passenger_type_numbers: {'1' => 1},
28
- # rack_price_requested: true,
29
- # date_range: {start_date: today, end_date: today + 1}
30
- # )
31
- # end
32
- #
33
- # @product.pricing_details_for_rack_rate.should be_present
34
- # end
47
+ it 'shouldnt allow other strings' do
48
+ expect {
49
+ QuickTravel::Product.find('six', options)
50
+ }.to raise_error(
51
+ ArgumentError,
52
+ 'id must be an integer'
53
+ )
54
+ end
55
+
56
+ it 'should allow string integers' do
57
+ expect {
58
+ VCR.use_cassette('product_show_as_agent') do
59
+ QuickTravel::Product.find('6', options)
60
+ end
61
+ }.not_to raise_error
62
+ end
35
63
  end
36
64
 
37
65
  describe QuickTravel::Product do
66
+ let(:today) { '2016-03-01'.to_date }
67
+
38
68
  before do
39
69
  VCR.use_cassette('product_date_range_bookability') do
40
- @today = '2016-03-01'.to_date
41
70
  @products = QuickTravel::Product.fetch_and_arrange_by_resource_id_and_date(
42
71
  [3, 4, 6],
43
- travel_date: @today,
72
+ travel_date: today,
44
73
  duration: 7,
45
74
  default_pax_type_numbers: { '1' => 1 },
46
75
  passenger_type_numbers: { '1' => 2, '2' => 1 }
@@ -48,8 +77,10 @@ describe QuickTravel::Product do
48
77
  end
49
78
  end
50
79
 
80
+ let(:expected_price) { 250.to_money }
81
+
51
82
  context 'accommodation product today' do
52
- subject(:product) { @products[6][@today.to_s] }
83
+ subject(:product) { @products[6][today.to_s] }
53
84
  it { should be_an_instance_of QuickTravel::Product }
54
85
 
55
86
  context 'pricing details' do
@@ -59,13 +90,13 @@ describe QuickTravel::Product do
59
90
  context 'price per pax type' do
60
91
  let(:price_if_no_breakdown) { pricing_details.price_per_pax_type[0] }
61
92
  it 'should breakdown prices even if just a total' do
62
- expect(price_if_no_breakdown).to eq 300.to_money
93
+ expect(price_if_no_breakdown).to eq expected_price
63
94
  end
64
95
  end
65
96
 
66
97
  context 'minimum price' do
67
98
  subject(:minimum_price) { pricing_details.minimum_price }
68
- it { should eq 300.to_money } # $200 for 2 pax, $100 for extra passenger
99
+ it { should eq expected_price } # $200 for 2 pax, $50 for extra passenger
69
100
  end
70
101
 
71
102
  context 'adjustments' do