diff options
Diffstat (limited to 't')
-rw-r--r-- | t/Nominatim.pm | 37 | ||||
-rw-r--r-- | t/app/controller/alert.t | 10 |
2 files changed, 45 insertions, 2 deletions
diff --git a/t/Nominatim.pm b/t/Nominatim.pm new file mode 100644 index 000000000..2041b4677 --- /dev/null +++ b/t/Nominatim.pm @@ -0,0 +1,37 @@ +package t::Nominatim; + +use JSON; +use Web::Simple; + +has json => ( + is => 'lazy', + default => sub { + JSON->new->pretty->allow_blessed->convert_blessed; + }, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /search + ?q=) { + my ($self, $q) = @_; + my $response = $self->query($q); + my $json = $self->json->encode($response); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, +} + +sub query { + my ($self, $q) = @_; + if ($q eq 'high street') { + return [ + {"osm_type"=>"way","osm_id"=>"4684282","lat"=>"55.9504009","lon"=>"-3.1858425","display_name"=>"High Street, Old Town, City of Edinburgh, Scotland, EH1 1SP, United Kingdom","class"=>"highway","type"=>"tertiary","importance"=>0.55892577838734}, + {"osm_type"=>"node","osm_id"=>"27424410","lat"=>"55.8596449","lon"=>"-4.240377","display_name"=>"High Street, Collegelands, Merchant City, Glasgow, Glasgow City, Scotland, G, United Kingdom","class"=>"railway","type"=>"station","importance"=>0.53074299592768} + ]; + } + return []; +} + + + +__PACKAGE__->run_if_script; diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 9189f5e97..5bf2af428 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -1,10 +1,13 @@ use strict; use warnings; use Test::More; +use LWP::Protocol::PSGI; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; +use t::Nominatim; + # check that we can get the page $mech->get_ok('/alert'); $mech->title_like(qr/^Local RSS feeds and email alerts/); @@ -38,8 +41,11 @@ FixMyStreet::override_config { $mech->content_contains('council:2651:City_of_Edinburgh'); $mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre'); - $mech->get_ok('/alert/list?pc=High Street'); - $mech->content_contains('We found more than one match for that location'); + subtest "Test Nominatim lookup" => sub { + LWP::Protocol::PSGI->register(t::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org'); + $mech->get_ok('/alert/list?pc=High Street'); + $mech->content_contains('We found more than one match for that location'); + }; $mech->get_ok('/alert/list?pc='); $mech->content_contains('To find out what local alerts we have for you'); |