diff options
| author | Teddy Wing | 2018-03-12 15:25:50 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-03-14 16:38:40 +0100 | 
| commit | 33c2dad6ba2483a4c71d7248979bf9d82a65f234 (patch) | |
| tree | 20a119ff082c2bc58b190d1394dea73e2526a4e7 /spec/lib/tom_tom | |
| parent | e558625cd5e3cad60757a537320eb15f1c045cd0 (diff) | |
| download | chouette-core-33c2dad6ba2483a4c71d7248979bf9d82a65f234.tar.bz2 | |
TomTom::Batch: Extract code to `#extract_costs_to_way_costs!`
Extract some code from `#batch` to allow us to test the part that takes
distance and time values from the response JSON and put fill them into
`WayCost`s.
In order for the test to work, had to add an `#==` method to `WayCost`
and make `distance` and `time` accessors.
The JSON file fixture is a copy of a response from the TomTom `/batch`
API. The file is pretty big. I'm not sure if maybe I should condense it
for the sake of test performance.
Refs #6095
Diffstat (limited to 'spec/lib/tom_tom')
| -rw-r--r-- | spec/lib/tom_tom/batch_spec.rb | 27 | 
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/lib/tom_tom/batch_spec.rb b/spec/lib/tom_tom/batch_spec.rb index eed8848f0..c3ab46a4b 100644 --- a/spec/lib/tom_tom/batch_spec.rb +++ b/spec/lib/tom_tom/batch_spec.rb @@ -1,6 +1,33 @@  RSpec.describe TomTom::Batch do    let(:batch) { TomTom::Batch.new(nil) } +  describe "#extract_costs_to_way_costs" do +    it "puts distance & time costs in way_costs" do +      way_costs = [ +        WayCost.new( +          departure: Geokit::LatLng.new(48.85086, 2.36143), +          arrival: Geokit::LatLng.new(47.91231, 1.87606) +        ), +        WayCost.new( +          departure: Geokit::LatLng.new(47.91231, 1.87606), +          arrival: Geokit::LatLng.new(52.50867, 13.42879) +        ) +      ] + +      expected_way_costs = way_costs.deep_dup +      expected_way_costs[0].distance = 117947 +      expected_way_costs[0].time = 7969 +      expected_way_costs[1].distance = 1114379 +      expected_way_costs[1].time = 71010 + +      batch_response = JSON.parse(read_fixture('tom_tom_batch.json')) + +      expect( +        batch.extract_costs_to_way_costs!(way_costs, batch_response) +      ).to match_array(expected_way_costs) +    end +  end +    describe "#convert_way_costs" do      it "turns WayCost points into a collection of colon-separated strings" do        way_costs = [  | 
