quicktravel_client 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +13 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +18 -0
  7. data/Gemfile +5 -0
  8. data/LICENSE +22 -0
  9. data/README.md +17 -0
  10. data/Rakefile +18 -0
  11. data/bootstrap/boot.rb +4 -0
  12. data/examples/example_config.rb +4 -0
  13. data/examples/login_example.rb +25 -0
  14. data/lib/extensions.rb +12 -0
  15. data/lib/quick_travel/accommodation.rb +72 -0
  16. data/lib/quick_travel/adapter.rb +283 -0
  17. data/lib/quick_travel/adapter_exception.rb +20 -0
  18. data/lib/quick_travel/address.rb +27 -0
  19. data/lib/quick_travel/adjustment.rb +8 -0
  20. data/lib/quick_travel/background_check.rb +9 -0
  21. data/lib/quick_travel/bed_configuration.rb +7 -0
  22. data/lib/quick_travel/bed_requirement.rb +7 -0
  23. data/lib/quick_travel/booking.rb +370 -0
  24. data/lib/quick_travel/cache.rb +38 -0
  25. data/lib/quick_travel/client.rb +8 -0
  26. data/lib/quick_travel/client_type.rb +6 -0
  27. data/lib/quick_travel/config.rb +26 -0
  28. data/lib/quick_travel/connection_error.rb +9 -0
  29. data/lib/quick_travel/constants.rb +16 -0
  30. data/lib/quick_travel/contact.rb +5 -0
  31. data/lib/quick_travel/country.rb +11 -0
  32. data/lib/quick_travel/credit_card.rb +12 -0
  33. data/lib/quick_travel/discounts/booking_discount.rb +18 -0
  34. data/lib/quick_travel/discounts/discount.rb +21 -0
  35. data/lib/quick_travel/discounts/discount_tree.rb +35 -0
  36. data/lib/quick_travel/discounts.rb +3 -0
  37. data/lib/quick_travel/document.rb +20 -0
  38. data/lib/quick_travel/document_group.rb +14 -0
  39. data/lib/quick_travel/encrypt.rb +13 -0
  40. data/lib/quick_travel/graphic.rb +18 -0
  41. data/lib/quick_travel/init_from_hash.rb +16 -0
  42. data/lib/quick_travel/location.rb +14 -0
  43. data/lib/quick_travel/mock.rb +41 -0
  44. data/lib/quick_travel/party.rb +49 -0
  45. data/lib/quick_travel/passenger.rb +7 -0
  46. data/lib/quick_travel/passenger_price_break.rb +8 -0
  47. data/lib/quick_travel/passenger_type.rb +21 -0
  48. data/lib/quick_travel/payment.rb +41 -0
  49. data/lib/quick_travel/payment_type.rb +37 -0
  50. data/lib/quick_travel/price.rb +14 -0
  51. data/lib/quick_travel/product.rb +165 -0
  52. data/lib/quick_travel/product_configuration.rb +134 -0
  53. data/lib/quick_travel/product_passenger_search_criteria.rb +28 -0
  54. data/lib/quick_travel/product_type.rb +28 -0
  55. data/lib/quick_travel/property.rb +99 -0
  56. data/lib/quick_travel/property_facility.rb +7 -0
  57. data/lib/quick_travel/property_type.rb +20 -0
  58. data/lib/quick_travel/region.rb +21 -0
  59. data/lib/quick_travel/reservation.rb +110 -0
  60. data/lib/quick_travel/resource.rb +50 -0
  61. data/lib/quick_travel/room_facility.rb +7 -0
  62. data/lib/quick_travel/route.rb +81 -0
  63. data/lib/quick_travel/route_stop.rb +7 -0
  64. data/lib/quick_travel/search.rb +14 -0
  65. data/lib/quick_travel/service.rb +5 -0
  66. data/lib/quick_travel/trip.rb +8 -0
  67. data/lib/quick_travel/vehicle.rb +17 -0
  68. data/lib/quick_travel/vehicle_type.rb +11 -0
  69. data/lib/quick_travel/version.rb +3 -0
  70. data/lib/quick_travel.rb +59 -0
  71. data/lib/quicktravel_client.rb +1 -0
  72. data/quicktravel_client.gemspec +37 -0
  73. data/spec/booking_spec.rb +107 -0
  74. data/spec/country_spec.rb +18 -0
  75. data/spec/credit_card_spec.rb +11 -0
  76. data/spec/discounts_spec.rb +121 -0
  77. data/spec/passenger_type_spec.rb +32 -0
  78. data/spec/payment_type_spec.rb +18 -0
  79. data/spec/product_spec.rb +82 -0
  80. data/spec/region_spec.rb +29 -0
  81. data/spec/reservation_spec.rb +50 -0
  82. data/spec/resource_spec.rb +22 -0
  83. data/spec/spec_helper.rb +77 -0
  84. data/spec/support/cassettes/booking_create.yml +50 -0
  85. data/spec/support/cassettes/booking_create_legacy.yml +50 -0
  86. data/spec/support/cassettes/booking_discounts.yml +53 -0
  87. data/spec/support/cassettes/booking_documents.yml +48 -0
  88. data/spec/support/cassettes/booking_show.yml +49 -0
  89. data/spec/support/cassettes/booking_update.yml +94 -0
  90. data/spec/support/cassettes/booking_with_discounts.yml +72 -0
  91. data/spec/support/cassettes/booking_with_documents.yml +117 -0
  92. data/spec/support/cassettes/booking_with_nested_attributes.yml +187 -0
  93. data/spec/support/cassettes/country_all.yml +127 -0
  94. data/spec/support/cassettes/create_reservation_fail.yml +47 -0
  95. data/spec/support/cassettes/create_reservation_with_booking.yml +53 -0
  96. data/spec/support/cassettes/passenger_all.yml +48 -0
  97. data/spec/support/cassettes/product_date_range_bookability.yml +118 -0
  98. data/spec/support/cassettes/product_show.yml +52 -0
  99. data/spec/support/cassettes/region_index.yml +48 -0
  100. data/spec/support/cassettes/region_show.yml +48 -0
  101. data/spec/support/cassettes/reservation_with_extra_picks.yml +165 -0
  102. data/spec/support/cassettes/resource_fare_bases.yml +97 -0
  103. data/spec/support/cassettes/resource_show.yml +50 -0
  104. metadata +421 -0
@@ -0,0 +1,7 @@
1
+ require 'quick_travel/adapter'
2
+
3
+ module QuickTravel
4
+ class PropertyFacility < Adapter
5
+ attr_accessor :id, :property_id, :category_id, :created_at, :name, :position, :property_facility_id, :updated_at
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ require 'quick_travel/adapter'
2
+ require 'quick_travel/cache'
3
+
4
+ module QuickTravel
5
+ class PropertyType < Adapter
6
+ include Cache
7
+
8
+ attr_accessor :id, :name, :position
9
+
10
+ def self.first(_id = nil)
11
+ generic_first('/property_types.json')
12
+ end
13
+
14
+ def self.all
15
+ QuickTravel::Cache.cache 'all_property_types' do
16
+ self.find_all!('/property_types.json')
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'quick_travel/adapter'
2
+ require 'quick_travel/cache'
3
+
4
+ module QuickTravel
5
+ class Region < Adapter
6
+ include Cache
7
+
8
+ attr_accessor :id, :name, :location_ids
9
+
10
+ self.api_base = '/regions'
11
+ self.lookup = true
12
+
13
+ def self.first
14
+ generic_first '/regions.json'
15
+ end
16
+
17
+ def locations
18
+ Location.all.select { |l| location_ids.include?(l.id) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,110 @@
1
+ require 'quick_travel/adapter'
2
+ require 'quick_travel/adjustment'
3
+ require 'quick_travel/resource'
4
+
5
+ module QuickTravel
6
+ class Reservation < Adapter
7
+ attr_accessor :id, :booking_id,
8
+ :gross_in_cents, :commission_in_cents, :cost_in_cents, :pre_adjusted_gross_in_cents,
9
+ :pre_adjusted_gross_including_packaged_item_in_cents, :gross_including_packaged_item_in_cents, :price_rules,
10
+ :first_travel_date, :last_travel_date, :checkout_date, :created_at, :start_time, :end_time,
11
+ :resource_id, :resource_class_name, :product_type_id, :product_type_name,
12
+ :bed_configuration_id, :inventory_type, :quantity,
13
+ :comment, :selection_name,
14
+ :service_ids,
15
+ :vehicle_splits, :passenger_splits,
16
+ :adjustments_attributes,
17
+ :inverse_reservation_id,
18
+ :from_route_stop_attributes, :to_route_stop_attributes,
19
+ :route_id, :trip_id, :route_path, :pick_up_information, :drop_off_information,
20
+ :complete, :enough_time_before_travel_to_edit
21
+
22
+ money :gross, :commission, :cost, :pre_adjusted_gross, :gross_including_packaged_item, :pre_adjusted_gross_including_packaged_item
23
+
24
+ def self.create(options)
25
+ json = post_and_validate('/api/reservations.json', options, expect: :json)
26
+ new(json)
27
+ end
28
+
29
+ def self.destroy(id)
30
+ delete_and_validate("/api/reservations/#{id}.json")
31
+ end
32
+
33
+ def adjustments
34
+ @adjustments_attributes.map { |adjustment| Adjustment.new(adjustment) }
35
+ end
36
+
37
+ def resource
38
+ @resource ||= QuickTravel::Resource.find(resource_id) if resource_id
39
+ end
40
+
41
+ def start_date_time
42
+ start_time.to_time.on(first_travel_date) if start_time
43
+ end
44
+
45
+ def end_date_time
46
+ end_time.to_time.on(last_travel_date) if end_time
47
+ end
48
+
49
+ def to_route_stop
50
+ QuickTravel::RouteStop.new(@to_route_stop_attributes) if @to_route_stop_attributes
51
+ end
52
+
53
+ def from_route_stop
54
+ QuickTravel::RouteStop.new(@from_route_stop_attributes) if @from_route_stop_attributes
55
+ end
56
+
57
+ # it send API request for Resource show. and cache the data.
58
+ # i think now this method is not required because now booking show api call have display_text for every reservation
59
+ def details
60
+ if @_resource.blank?
61
+ @_resource = Resource.find(@resource_id) unless @resource_id.blank?
62
+ end
63
+ @_resource
64
+ end
65
+
66
+ def sub_reservations
67
+ @sub_reservations ||= Array(@sub_reservations_attributes).map do |attributes|
68
+ Reservation.new(attributes)
69
+ end
70
+ end
71
+
72
+ def passengers_count_string(booking)
73
+ passengers_count(booking).join(', ')
74
+ end
75
+
76
+ def passengers_count(booking)
77
+ passenger_type_count = {}
78
+ if passenger_splits.present?
79
+ passenger_splits.each do |p|
80
+ passenger = booking.find_passenger_by_id(p['consumer_id'])
81
+
82
+ if passenger.present?
83
+ passenger_type_count[passenger.passenger_type_id] ||= 0
84
+ passenger_type_count[passenger.passenger_type_id] += 1
85
+ end
86
+ end
87
+ end
88
+ PassengerType.passenger_counts(passenger_type_count)
89
+ end
90
+
91
+ def vehicle_count_string(booking)
92
+ vehicles_count(booking).to_sentence
93
+ end
94
+
95
+ def vehicles_count(booking)
96
+ vehicle_splits.map do|v|
97
+ vehicle = booking.find_vehicle_by_id(v['consumer_id'])
98
+ "#{vehicle.length}m #{vehicle.vehicle_type.name}"
99
+ end
100
+ end
101
+
102
+ def duration
103
+ (last_travel_date - first_travel_date + 1).to_i
104
+ end
105
+
106
+ def adjusted?
107
+ pre_adjusted_gross_including_packaged_item != gross_including_packaged_item
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,50 @@
1
+ require 'quick_travel/adapter'
2
+ require 'quick_travel/bed_requirement'
3
+ require 'quick_travel/passenger_price_break'
4
+ require 'quick_travel/product_type'
5
+ require 'quick_travel/cache'
6
+
7
+ module QuickTravel
8
+ class Resource < Adapter
9
+ include QuickTravel::Cache
10
+ attr_accessor :id,
11
+ :code,
12
+ :name,
13
+ :current_description,
14
+ :images,
15
+ :category,
16
+ :property_name,
17
+ :product_type_id,
18
+ :package_options,
19
+ :bed_requirements,
20
+ :client_type_ids,
21
+ :restrict_to_client_types,
22
+ :type
23
+ self.api_base = '/resources'
24
+
25
+ def sub_resources
26
+ Resource.find_all!('/resources.json', parent_resource_id: @id)
27
+ end
28
+
29
+ def product_type
30
+ QuickTravel::ProductType.all.detect { |pt| pt.id == product_type_id }
31
+ end
32
+
33
+ # this method is also duplicated in accommodation class. because now its room facilities are now also available in property show api call
34
+ def room_facilities
35
+ if @_room_facilities.blank?
36
+ @_room_facilities = []
37
+ @room_facilities.each do |item|
38
+ @_room_facilities << RoomFacility.new(item['room_facility'])
39
+ end
40
+ end
41
+ @_room_facilities
42
+ end
43
+
44
+ def bed_requirements
45
+ @_bed_requirements ||= Array.wrap(@bed_requirements).map do |bed_requirement|
46
+ BedRequirement.new(bed_requirement)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ require 'quick_travel/adapter'
2
+
3
+ module QuickTravel
4
+ class RoomFacility < Adapter
5
+ attr_accessor :id, :accommodation_id, :category_id, :created_at, :name, :position, :room_facility_id, :updated_at
6
+ end
7
+ end
@@ -0,0 +1,81 @@
1
+ module QuickTravel
2
+ class Route < Adapter
3
+ attr_accessor :id, :name, :path, :position, :product_type_id, :reverse_id, :route_stops
4
+
5
+ # First route for product_type_id
6
+ def self.first(product_type_id)
7
+ generic_first("/product_types/#{product_type_id}/routes.json")
8
+ end
9
+
10
+ # find_by_id -- but the API only does lookup by product_type_id
11
+ def self.find_by_route_id_and_product_type_id(route_id, product_type_id)
12
+ all_by_route_ids_and_product_type_id([route_id.to_i], product_type_id).first
13
+ end
14
+
15
+ # Return routes that match the given ids and product_type_id
16
+ #
17
+ # Initializes with path set
18
+ def self.all_by_route_ids_and_product_type_id(route_ids, product_type_id)
19
+ all(product_type_id).select do|route|
20
+ route_ids.include?(route.id.to_i)
21
+ end
22
+ end
23
+
24
+ # All routes for a given product type
25
+ def self.all(product_type_id)
26
+ cache_key = "trip_routes_#{product_type_id}"
27
+ routes = QuickTravel::Cache.cache_store.read(cache_key)
28
+
29
+ if routes.blank? || !routes.first.instance_of?(Route) # this is hack for development env. Lazy loading is main issue with it.
30
+ routes = self.find_all!("/product_types/#{product_type_id}/routes.json")
31
+ QuickTravel::Cache.cache_store.write(
32
+ cache_key,
33
+ routes,
34
+ expires_in: 1440.minutes # expires_in will only work with something like Rails.cache
35
+ )
36
+ end
37
+
38
+ routes
39
+ end
40
+
41
+ def self.find(routes_list, route_id)
42
+ routes_list.detect do|route|
43
+ route.id.to_i == route_id.to_i
44
+ end
45
+ end
46
+
47
+ def route_stops
48
+ @_stops ||= @route_stops.map { |item| RouteStop.new(item) }
49
+ end
50
+
51
+ def get_return_route_stop!(forward_stop)
52
+ if forward_stop.blank?
53
+ fail AdapterException, 'Selected pick up/drop off stops have not been set up for the selected route.'
54
+ end
55
+
56
+ reverse_stop = get_reverse_route!.route_stops.detect { |route_stop| route_stop.name == forward_stop.name }
57
+
58
+ if reverse_stop.blank?
59
+ fail AdapterException, 'Selected pick up/drop off stops have not been setup on the reverse route.'
60
+ end
61
+ reverse_stop
62
+ end
63
+
64
+ def get_reverse_route!
65
+ if reverse_id.blank?
66
+ fail AdapterException, 'Reverse has not been setup for the selected route.'
67
+ end
68
+
69
+ reverse_route = Route.find_by_route_id_and_product_type_id(reverse_id, product_type_id)
70
+ if reverse_route.blank?
71
+ fail AdapterException, 'Reverse does not exist for the selected route.'
72
+ end
73
+
74
+ reverse_route
75
+ end
76
+
77
+ def find_route_stop_by_id(route_stop_id)
78
+ route_stops.detect { |route_stop| route_stop.id.to_i == route_stop_id.to_i }
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,7 @@
1
+ require 'quick_travel/adapter'
2
+
3
+ module QuickTravel
4
+ class RouteStop < Adapter
5
+ attr_accessor :id, :name, :address, :code, :position, :route_id
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'quick_travel/init_from_hash'
2
+
3
+ module QuickTravel
4
+ class Search
5
+ attr_accessor :property_type_id, :property_name, :product, :last_travel_date, :location_id
6
+ attr_accessor :category # type of search
7
+ attr_accessor :way # used for one_way or two_way in "getting there search"
8
+ attr_accessor :route_id # for getting there search
9
+ attr_accessor :number_of_rooms # required for accommodation search
10
+ attr_accessor :forward_connection_date, :backward_connection_date
11
+
12
+ include QuickTravel::InitFromHash
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module QuickTravel
2
+ class Service < Adapter
3
+ attr_accessor :id, :capacity, :booked, :weight, :max_weight, :unit_name, :deck_services
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'quick_travel/adapter'
2
+
3
+ module QuickTravel
4
+ class Trip < Adapter
5
+ self.api_base = '/api/trips'
6
+ attr_accessor :route_id
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ require 'quick_travel/adapter'
2
+
3
+ module QuickTravel
4
+ class Vehicle < Adapter
5
+ attr_accessor :id, :vehicle_type_id, :registration, :length, :linked_to, :vehicle_type_name, :details
6
+
7
+ def self.create(booking_id, vehicle_types = {})
8
+ options = { booking_id: booking_id, vehicle_types: vehicle_types }
9
+ response = post_and_validate("#{Booking.front_office_base}/#{booking_id}/vehicles.json", options)
10
+ fail AdapterException.new(response) unless response.key?('booking_id')
11
+ end
12
+
13
+ def vehicle_type
14
+ VehicleType.all.detect { |vt| vt.id == vehicle_type_id }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ require 'quick_travel/adapter'
2
+
3
+ module QuickTravel
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
+ self.api_base = '/vehicle_types'
9
+ self.lookup = true
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module QuickTravel
2
+ VERSION = '1.0.2'
3
+ end
@@ -0,0 +1,59 @@
1
+ # QuickTravel
2
+ #
3
+ module QuickTravel
4
+ VERSION = '0.0.2'
5
+
6
+ require 'active_support' # for .try, etc.
7
+
8
+ require 'quick_travel/cache'
9
+ require 'quick_travel/config'
10
+ require 'quick_travel/adapter'
11
+ require 'quick_travel/adapter_exception'
12
+ require 'quick_travel/connection_error'
13
+
14
+ # Don't include this guy: pull the pieces into the classes that use it, or ref
15
+ require 'quick_travel/constants'
16
+
17
+ require 'quick_travel/product'
18
+ require 'quick_travel/product_configuration'
19
+ require 'quick_travel/search'
20
+
21
+ # QuickTravel models
22
+ require 'quick_travel/graphic'
23
+ require 'quick_travel/accommodation'
24
+ require 'quick_travel/adapter'
25
+ require 'quick_travel/address'
26
+ require 'quick_travel/bed_configuration'
27
+ require 'quick_travel/booking'
28
+ require 'quick_travel/client'
29
+ require 'quick_travel/client_type'
30
+ require 'quick_travel/contact'
31
+ require 'quick_travel/country'
32
+ require 'quick_travel/document'
33
+ require 'quick_travel/document_group'
34
+ require 'quick_travel/location'
35
+ require 'quick_travel/party'
36
+ require 'quick_travel/passenger'
37
+ require 'quick_travel/passenger_type'
38
+ require 'quick_travel/payment'
39
+ require 'quick_travel/background_check'
40
+ require 'quick_travel/payment_type'
41
+ require 'quick_travel/product_type'
42
+ require 'quick_travel/property'
43
+ require 'quick_travel/property_facility'
44
+ require 'quick_travel/property_type'
45
+ require 'quick_travel/route'
46
+ require 'quick_travel/region'
47
+ require 'quick_travel/reservation'
48
+ require 'quick_travel/resource'
49
+ require 'quick_travel/room_facility'
50
+ require 'quick_travel/route_stop'
51
+ require 'quick_travel/service'
52
+ require 'quick_travel/trip'
53
+ require 'quick_travel/vehicle'
54
+ require 'quick_travel/vehicle_type'
55
+
56
+ require 'quick_travel/product_passenger_search_criteria'
57
+ require 'money'
58
+ require 'extensions'
59
+ end
@@ -0,0 +1 @@
1
+ require 'quick_travel'
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'quick_travel/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'quicktravel_client'
7
+ spec.version = QuickTravel::VERSION
8
+ spec.authors = ['Michael Noack', 'Adam Davies', 'Alessandro Berardi']
9
+ spec.email = 'support@travellink.com.au'
10
+ spec.description = 'For integrating with QuickTravel API'
11
+ spec.summary = 'Booking process using QuickTravel API'
12
+ spec.homepage = 'https://bitbucket.org/team-sealink/quicktravel_client'
13
+
14
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'httparty'
20
+ spec.add_dependency 'geokit', '~> 1.8.3' # used in address model
21
+ spec.add_dependency 'activesupport', '>= 2.0.0'
22
+ spec.add_dependency 'money_extensions'
23
+ spec.add_dependency 'facets'
24
+ spec.add_dependency 'money', '>= 3.0', '< 6.0' # 6.0 starts to deprecate/split
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.7'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rspec-its'
30
+ spec.add_development_dependency 'simplecov'
31
+ spec.add_development_dependency 'simplecov-rcov'
32
+ spec.add_development_dependency 'coveralls'
33
+ spec.add_development_dependency 'stamp' # Used to send appropriate dates to API's
34
+ spec.add_development_dependency 'vcr'
35
+ spec.add_development_dependency 'fakeweb'
36
+ spec.add_development_dependency 'rubocop'
37
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+ require 'quick_travel/booking'
3
+ require 'quick_travel/document'
4
+
5
+ describe QuickTravel::Booking do
6
+ before(:each) do
7
+ @booking = QuickTravel::Booking.new(gross_in_cents: 500)
8
+ end
9
+
10
+ it 'should show me the money' do
11
+ expect(@booking.gross).to be_an_instance_of Money
12
+ expect(@booking.gross).to eq 5.to_money
13
+ expect(@booking.gross_in_cents).to eq 500
14
+ end
15
+ end
16
+
17
+ describe QuickTravel::Booking, '#on_account_payment_type' do
18
+ subject(:booking) { QuickTravel::Booking.new }
19
+ before { allow(booking).to receive(:payment_types) { payment_types } }
20
+ let(:reference) { double(code: 'on_account_with_reference') }
21
+ let(:on_account) { double(code: 'on_account_without_reference') }
22
+ let(:cash) { double(code: 'Cash') }
23
+
24
+ context 'when no on account types are applicable' do
25
+ let(:payment_types) { [cash] }
26
+ its(:on_account_payment_type) { should be nil }
27
+ end
28
+
29
+ context 'when only reference required' do
30
+ let(:payment_types) { [cash, reference] }
31
+ its(:on_account_payment_type) { should eq reference }
32
+ end
33
+
34
+ context 'when both on account and reference required' do
35
+ let(:payment_types) { [cash, reference, on_account] }
36
+ its(:on_account_payment_type) { should be on_account }
37
+ end
38
+ end
39
+
40
+ describe QuickTravel::Booking do
41
+ before(:each) do
42
+ VCR.use_cassette('booking_create') do
43
+ QuickTravel.config.version = 4
44
+ @booking = QuickTravel::Booking.create
45
+ end
46
+ end
47
+
48
+ it 'should find a first instance of booking with given booking.id from QuickTravel' do
49
+ VCR.use_cassette('booking_show') do
50
+ b = QuickTravel::Booking.find(@booking.id)
51
+ expect(b).to be_an_instance_of QuickTravel::Booking
52
+ expect(b.id).to eq @booking.id
53
+ end
54
+ end
55
+
56
+ it 'should be able to return its assigned reservations' do
57
+ VCR.use_cassette('booking_show') do
58
+ b = QuickTravel::Booking.find(@booking.id)
59
+ expect(b.reservations).to be_an_instance_of Array
60
+ expect(b.reservations.size).to eq 0
61
+ end
62
+ end
63
+
64
+ it 'should be able to update the booking' do
65
+ VCR.use_cassette('booking_update') do
66
+ response = @booking.update(customer_contact_name: 'John')
67
+ expect(response.class).to eq QuickTravel::Booking
68
+ end
69
+ end
70
+
71
+ it 'should not have booking documents' do
72
+ VCR.use_cassette('booking_documents') do
73
+ expect(@booking.documents.size).to eq 0
74
+ end
75
+ end
76
+ end
77
+
78
+ describe QuickTravel::Booking do
79
+ let(:booking) { QuickTravel::Booking.find(1) }
80
+ it 'should have booking documents' do
81
+ VCR.use_cassette('booking_with_documents') do
82
+ expect(booking.documents.size).to eq 1
83
+ end
84
+ end
85
+ end
86
+
87
+ describe QuickTravel::Booking do
88
+ let(:booking) { QuickTravel::Booking.find(1) }
89
+ subject(:consumer) { booking.passengers.first }
90
+ it 'should updated nested attributes' do
91
+ updated_booking = nil
92
+ VCR.use_cassette('booking_with_nested_attributes') do
93
+ expect(booking.customer_contact_name).to be nil
94
+ expect(consumer.id).to eq 1
95
+ expect(consumer.title).to be nil
96
+ expect(consumer.first_name).to be nil
97
+ updated_booking = booking.update_with_nested_attributes!(
98
+ customer_contact_name: 'New Name',
99
+ consumers: [{id: 1, title: 'Mr', first_name: 'New', last_name: 'Name'}]
100
+ )
101
+ end
102
+ updated_consumer = updated_booking.passengers.first
103
+ expect(updated_booking.customer_contact_name).to eq 'New Name'
104
+ expect(updated_consumer.title).to eq 'Mr'
105
+ expect(updated_consumer.first_name).to eq 'New'
106
+ end
107
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'quick_travel/country'
3
+
4
+ describe QuickTravel::Country do
5
+ before do
6
+ VCR.use_cassette('country_all') do
7
+ @countries = QuickTravel::Country.all
8
+ end
9
+ end
10
+
11
+ it 'should fetch all countries' do
12
+ expect(@countries).to_not be_empty
13
+ au = @countries.detect { |c| c.iso_3166_code == 'AU' }
14
+ expect(au.name).to eq 'Australia'
15
+ au.id
16
+ expect(QuickTravel::Country.find(au.id).name).to eq 'Australia'
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'quick_travel/credit_card'
3
+
4
+ describe QuickTravel::CreditCard do
5
+ it 'determine the correct payment type for credit card number' do
6
+ expect(QuickTravel::CreditCard.type_from_number('4000123456780123')).to eq 'visa'
7
+ expect(QuickTravel::CreditCard.type_from_number('5400123456780123')).to eq 'master'
8
+ expect(QuickTravel::CreditCard.type_from_number('3600123456780123')).to eq 'diners_club'
9
+ expect(QuickTravel::CreditCard.type_from_number('3400123456780123')).to eq 'american_express'
10
+ end
11
+ end