aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/UKCouncils.pm30
-rw-r--r--perllib/FixMyStreet/Cobrand/Westminster.pm44
-rw-r--r--t/cobrand/westminster.t32
3 files changed, 95 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
index 794c3dec6..a95e0f997 100644
--- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm
+++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
@@ -288,17 +288,7 @@ sub _fetch_features {
my $buffer = $cfg->{buffer};
my ($w, $s, $e, $n) = ($x-$buffer, $y-$buffer, $x+$buffer, $y+$buffer);
- my $uri = URI->new($cfg->{url});
- $uri->query_form(
- REQUEST => "GetFeature",
- SERVICE => "WFS",
- SRSNAME => $cfg->{srsname},
- TYPENAME => $cfg->{typename},
- VERSION => "1.1.0",
- outputformat => "geojson",
- BBOX => "$w,$s,$e,$n"
- );
-
+ my $uri = $self->_fetch_features_url($cfg, $w, $s, $e,$n);
my $response = get($uri) or return;
my $j = JSON->new->utf8->allow_nonref;
@@ -313,6 +303,24 @@ sub _fetch_features {
return $j->{features};
}
+sub _fetch_features_url {
+ my ($self, $cfg, $w, $s, $e, $n) = @_;
+
+ my $uri = URI->new($cfg->{url});
+ $uri->query_form(
+ REQUEST => "GetFeature",
+ SERVICE => "WFS",
+ SRSNAME => $cfg->{srsname},
+ TYPENAME => $cfg->{typename},
+ VERSION => "1.1.0",
+ outputformat => "geojson",
+ BBOX => "$w,$s,$e,$n"
+ );
+
+ return $uri;
+}
+
+
sub _nearest_feature {
my ($self, $cfg, $x, $y, $features) = @_;
diff --git a/perllib/FixMyStreet/Cobrand/Westminster.pm b/perllib/FixMyStreet/Cobrand/Westminster.pm
index b26cde052..a89bc4851 100644
--- a/perllib/FixMyStreet/Cobrand/Westminster.pm
+++ b/perllib/FixMyStreet/Cobrand/Westminster.pm
@@ -4,6 +4,8 @@ use base 'FixMyStreet::Cobrand::Whitelabel';
use strict;
use warnings;
+use URI;
+
sub council_area_id { return 2504; }
sub council_area { return 'Westminster'; }
sub council_name { return 'Westminster City Council'; }
@@ -70,6 +72,48 @@ sub open311_config {
my $id = $row->user->get_extra_metadata('westminster_account_id');
# Westminster require 0 as the account ID if there's no MyWestminster ID.
$h->{account_id} = $id || '0';
+
+ my $extra = $row->get_extra_fields;
+
+ # Reports made via the app probably won't have a USRN because we don't
+ # display the road layer. Instead we'll look up the closest asset from the
+ # asset service at the point we're sending the report over Open311.
+ if (!$row->get_extra_field_value('USRN')) {
+ if (my $ref = $self->lookup_site_code($row)) {
+ push @$extra, { name => 'USRN', value => $ref };
+ }
+ }
+
+ $row->set_extra_fields(@$extra);
+}
+
+sub lookup_site_code_config {
+ # uncoverable subroutine
+ # uncoverable statement
+ {
+ buffer => 1000, # metres
+ proxy_url => "https://tilma.staging.mysociety.org/resource-proxy/proxy.php",
+ url => "https://westminster.assets/40/query",
+ property => "USRN",
+ accept_feature => sub { 1 }
+ }
+}
+
+sub _fetch_features_url {
+ my ($self, $cfg, $w, $s, $e, $n) = @_;
+
+ # Westminster's asset proxy has a slightly different calling style to
+ # a standard WFS server.
+ my $uri = URI->new($cfg->{url});
+ $uri->query_form(
+ inSR => "27700",
+ outSR => "27700",
+ f => "geojson",
+ outFields => $cfg->{property},
+ geometry => "$w,$s,$e,$n",
+ );
+
+ return $cfg->{proxy_url} . "?" . $uri->as_string;
}
1;
diff --git a/t/cobrand/westminster.t b/t/cobrand/westminster.t
index 2c79fb734..b011f03ad 100644
--- a/t/cobrand/westminster.t
+++ b/t/cobrand/westminster.t
@@ -1,7 +1,16 @@
+use CGI::Simple;
+use Test::MockModule;
use FixMyStreet::TestMech;
+use FixMyStreet::Script::Reports;
ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
+my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Westminster');
+$cobrand->mock('lookup_site_code', sub {
+ my ($self, $row, $buffer) = @_;
+ return "My USRN" if $row->latitude == 51.501009;
+});
+
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'westminster',
MAPIT_URL => 'http://mapit.uk/',
@@ -77,4 +86,27 @@ for (
};
}
+FixMyStreet::DB->resultset('Problem')->delete_all;
+my $body = $mech->create_body_ok(2504, 'Westminster City Council', {
+ send_method => 'Open311', api_key => 'key', 'endpoint' => 'e', 'jurisdiction' => 'j' });
+$mech->create_contact_ok(body_id => $body->id, category => 'Abandoned bike', email => "BIKE");
+my ($report) = $mech->create_problems_for_body(1, $body->id, 'Bike', {
+ category => "Abandoned bike", cobrand => 'westminster',
+ latitude => 51.501009, longitude => -0.141588, areas => '2504',
+});
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'westminster' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ STAGING_FLAGS => { send_reports => 1, skip_checks => 0 },
+}, sub {
+ subtest 'USRN set correctly' => 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'), 'BIKE';
+ is $c->param('attribute[USRN]'), 'My USRN';
+ };
+};
+
done_testing();