diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-04-02 12:13:31 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-05-28 15:36:25 +0100 |
commit | 324b881a8db33250c3fdac3752429b59929b83fa (patch) | |
tree | 419105a7aab6181516c4a89cab947733dbf28373 | |
parent | d68c2cf2d1a227c4a5f446e78290f0835a869a25 (diff) |
[Bexley] Fallback server-side road lookup.
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bexley.pm | 30 | ||||
-rw-r--r-- | t/cobrand/bexley.t | 28 |
2 files changed, 57 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm index 6b1573ced..3bb9bf417 100644 --- a/perllib/FixMyStreet/Cobrand/Bexley.pm +++ b/perllib/FixMyStreet/Cobrand/Bexley.pm @@ -51,4 +51,34 @@ sub open311_munge_update_params { $params->{service_code} = $contact->email; } +sub lookup_site_code_config { + # uncoverable function + # uncoverable statement + { + buffer => 200, # metres + url => "https://tilma.mysociety.org/mapserver/bexley", + srsname => "urn:ogc:def:crs:EPSG::27700", + typename => "Streets", + property => "NSG_REF", + accept_feature => sub { 1 } + } +} + +sub open311_config { + my ($self, $row, $h, $params) = @_; + + my $extra = $row->get_extra_fields; + + # Reports made via the app probably won't have a NSGRef because we don't + # display the road layer. Instead we'll look up the closest asset from the + # WFS service at the point we're sending the report over Open311. + if (!$row->get_extra_field_value('NSGRef')) { + if (my $ref = $self->lookup_site_code($row)) { + push @$extra, { name => 'NSGRef', description => 'NSG Ref', value => $ref }; + } + } + + $row->set_extra_fields(@$extra); +} + 1; diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t index 7f67dc1a4..10255dbea 100644 --- a/t/cobrand/bexley.t +++ b/t/cobrand/bexley.t @@ -1,7 +1,17 @@ +use CGI::Simple; +use Test::MockModule; use FixMyStreet::TestMech; +use FixMyStreet::Script::Reports; use_ok 'FixMyStreet::Cobrand::Bexley'; +my $ukc = Test::MockModule->new('FixMyStreet::Cobrand::UKCouncils'); +$ukc->mock('lookup_site_code', sub { + my ($self, $row, $buffer) = @_; + is $row->latitude, 51.408484, 'Correct latitude'; + return "Road ID"; +}); + my $cobrand = FixMyStreet::Cobrand::Bexley->new; like $cobrand->contact_email, qr/bexley/; is $cobrand->on_map_default_status, 'open'; @@ -9,11 +19,14 @@ is_deeply $cobrand->disambiguate_location->{bounds}, [ 51.408484, 0.074653, 51.5 my $mech = FixMyStreet::TestMech->new; -$mech->create_body_ok(2494, 'London Borough of Bexley'); +my $body = $mech->create_body_ok(2494, 'London Borough of Bexley', { + send_method => 'Open311', api_key => 'key', 'endpoint' => 'e', 'jurisdiction' => 'j' }); +$mech->create_contact_ok(body_id => $body->id, category => 'Abandoned and untaxed vehicles', email => "ABAN"); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'bexley' ], MAPIT_URL => 'http://mapit.uk/', + STAGING_FLAGS => { send_reports => 1, skip_checks => 0 }, }, sub { subtest 'cobrand displays council name' => sub { @@ -27,6 +40,19 @@ FixMyStreet::override_config { $mech->content_contains('Bexley'); }; + my ($report) = $mech->create_problems_for_body(1, $body->id, 'On Road', { + category => 'Abandoned and untaxed vehicles', cobrand => 'bexley', + latitude => 51.408484, longitude => 0.074653, + }); + + subtest 'Server-side NSGRef included' => sub { + my $test_data = FixMyStreet::Script::Reports::send(); + my $req = $test_data->{test_req_used}; + my $c = CGI::Simple->new($req->content); + is $c->param('service_code'), 'ABAN'; + is $c->param('attribute[NSGRef]'), 'Road ID'; + }; + }; done_testing(); |