diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-05-18 20:12:16 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-05-18 20:12:16 +0100 |
commit | 675744156c56d7b5ea5c8866fdd59a1c3cbcee1b (patch) | |
tree | 9ac7bb95f77ed5c473f9dd2a62be70959a4508b0 /t | |
parent | 61eb613ddc31943e9d6504050c0e96f91340f752 (diff) |
[UK] Stop nearest request with scientific notation
If the longitude was very close to 0, it was being sent as e.g. 1e-6
in the request to MapIt. Mock out the Bing query so that this can be
tested (the closest.t tests were previously always being skipped).
Diffstat (limited to 't')
-rw-r--r-- | t/Mock/Bing.pm | 37 | ||||
-rw-r--r-- | t/Mock/MapIt.pm | 3 | ||||
-rw-r--r-- | t/cobrand/closest.t | 31 |
3 files changed, 54 insertions, 17 deletions
diff --git a/t/Mock/Bing.pm b/t/Mock/Bing.pm new file mode 100644 index 000000000..3dfb8fbe0 --- /dev/null +++ b/t/Mock/Bing.pm @@ -0,0 +1,37 @@ +package t::Mock::Bing; + +use JSON::MaybeXS; +use Web::Simple; +use LWP::Protocol::PSGI; + +has json => ( + is => 'lazy', + default => sub { + JSON->new->pretty->allow_blessed->convert_blessed; + }, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /REST/v1/Locations/* + ?*) { + my ($self, $location, $query) = @_; + my $data = { + resourceSets => [ { + resources => [ { + name => 'Constitution Hill, London, SW1A', + address => { + addressLine => 'Constitution Hill', + locality => 'London', + } + } ], + } ], + }; + my $json = $self->json->encode($data); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, +} + +LWP::Protocol::PSGI->register(t::Mock::Bing->to_psgi_app, host => 'dev.virtualearth.net'); + +__PACKAGE__->run_if_script; diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 0b355983b..24e7a8084 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -32,6 +32,7 @@ my @PLACES = ( [ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ], [ 'WS1 4NH', 52.563074, -1.991032, 2535, 'Sandwell Borough Council', 'MTD' ], [ 'OX28 4DS', 51.784721, -1.494453 ], + [ 'E14 2DN', 51.508536, '0.000001' ], ); sub dispatch_request { @@ -112,7 +113,7 @@ sub dispatch_request { foreach (@PLACES) { if ($point eq "4326/$_->[2],$_->[1]") { return $self->output({ - postcode => { wgs84_lat => $_->[1], wgs84_lon => $_->[2], postcode => $_->[0] }, + postcode => { wgs84_lat => $_->[1], wgs84_lon => $_->[2], postcode => $_->[0], distance => 93 }, }); } } diff --git a/t/cobrand/closest.t b/t/cobrand/closest.t index 0d6a772ba..8bb2d649b 100644 --- a/t/cobrand/closest.t +++ b/t/cobrand/closest.t @@ -2,6 +2,7 @@ use strict; use warnings; use Test::More; +use t::Mock::Bing; use mySociety::Locale; use FixMyStreet::DB; @@ -31,7 +32,7 @@ my $dt = DateTime->new( my $report = FixMyStreet::DB->resultset('Problem')->find_or_create( { - postcode => 'SW1A 1AA', + postcode => 'E142DN', bodies_str => '2504', areas => ',105255,11806,11828,2247,2504,', category => 'Other', @@ -47,8 +48,8 @@ my $report = FixMyStreet::DB->resultset('Problem')->find_or_create( cobrand => 'default', cobrand_data => '', send_questionnaire => 't', - latitude => '51.5016605453401', - longitude => '-0.142497580865087', + latitude => 51.508536, + longitude => 0.000001, user_id => $user->id, } ); @@ -56,21 +57,18 @@ my $report_id = $report->id; ok $report, "created test report - $report_id"; $report->geocode( undef ); - ok !$report->geocode, 'no geocode entry for report'; -my $near = $c->find_closest($report); - -SKIP: { - if (!FixMyStreet->config('BING_MAPS_API_KEY')) { - skip 'No Bing Maps key', 0; - } - +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + BING_MAPS_API_KEY => 'test', +}, sub { + my $near = $c->find_closest($report); ok $report->geocode, 'geocode entry added to report'; ok $report->geocode->{resourceSets}, 'geocode entry looks like right sort of thing'; like $near, qr/Constitution Hill/i, 'nearest street looks right'; - like $near, qr/Nearest postcode .*: SW1A 1AA/i, 'nearest postcode looks right'; + like $near, qr/Nearest postcode .*: E14 2DN/i, 'nearest postcode looks right'; $near = $c->find_closest_address_for_rss($report); @@ -81,8 +79,9 @@ SKIP: { $near = $c->find_closest_address_for_rss($report); ok !$near, 'no closest address for RSS if not cached'; -} +}; -# all done -$mech->delete_user( $user ); -done_testing(); +END { + $mech->delete_user( $user ); + done_testing(); +} |