diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Westminster.pm | 30 | ||||
-rw-r--r-- | t/cobrand/bucks.t | 2 | ||||
-rw-r--r-- | t/cobrand/westminster.t | 52 | ||||
-rw-r--r-- | web/cobrands/westminster/assets.js | 4 |
5 files changed, 80 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index c245ef1c6..b59c8990b 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -273,10 +273,9 @@ see Buckinghamshire or Lincolnshire for an example. sub lookup_site_code { my $self = shift; my $row = shift; - my $buffer = shift; + my $field = shift; - my $cfg = $self->lookup_site_code_config; - $cfg->{buffer} = $buffer if $buffer; + my $cfg = $self->lookup_site_code_config($field); my ($x, $y) = $row->local_coords; my $features = $self->_fetch_features($cfg, $x, $y); diff --git a/perllib/FixMyStreet/Cobrand/Westminster.pm b/perllib/FixMyStreet/Cobrand/Westminster.pm index 76788d031..3d99e59c4 100644 --- a/perllib/FixMyStreet/Cobrand/Westminster.pm +++ b/perllib/FixMyStreet/Cobrand/Westminster.pm @@ -90,24 +90,42 @@ sub open311_config { # 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)) { + if (my $ref = $self->lookup_site_code($row, 'USRN')) { push @$extra, { name => 'USRN', value => $ref }; } } + # Some categories require a UPRN to be set, so if the field is present + # but empty then look it up. + my $fields = $row->get_extra_fields; + my ($uprn_field) = grep { $_->{name} eq 'UPRN' } @$fields; + if ( $uprn_field && !$uprn_field->{value} ) { + if (my $ref = $self->lookup_site_code($row, 'UPRN')) { + push @$extra, { name => 'UPRN', value => $ref }; + } + } + $row->set_extra_fields(@$extra); } sub lookup_site_code_config { + my ( $self, $field ) = @_; # uncoverable subroutine # uncoverable statement - { + my $layer = $field eq 'USRN' ? '40' : '25'; # 25 is UPRN + + my %cfg = ( 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 } - } + url => "https://westminster.assets/$layer/query", + property => $field, + accept_feature => sub { 1 }, + + # UPRNs are Point geometries, so make sure they're allowed by + # _nearest_feature. + ( $field eq 'UPRN' ) ? (accept_types => { Point => 1 }) : (), + ); + return \%cfg; } sub _fetch_features_url { diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t index 6732eb29c..2d42dcd81 100644 --- a/t/cobrand/bucks.t +++ b/t/cobrand/bucks.t @@ -19,7 +19,7 @@ $mech->create_contact_ok(body_id => $district->id, category => 'Graffiti', email my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Buckinghamshire'); $cobrand->mock('lookup_site_code', sub { - my ($self, $row, $buffer) = @_; + my ($self, $row) = @_; return "Road ID" if $row->latitude == 51.812244; }); diff --git a/t/cobrand/westminster.t b/t/cobrand/westminster.t index 756b9720c..2912f6ee5 100644 --- a/t/cobrand/westminster.t +++ b/t/cobrand/westminster.t @@ -7,7 +7,7 @@ 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) = @_; + my ($self, $row) = @_; return "My USRN" if $row->latitude == 51.501009; }); @@ -165,4 +165,54 @@ FixMyStreet::override_config { }; }; +my $westminster = FixMyStreet::Cobrand::Westminster->new; +subtest 'correct config returned for USRN/UPRN lookup' => sub { + my $actual = $westminster->lookup_site_code_config('USRN'); + delete $actual->{accept_feature}; # is_deeply doesn't like code + is_deeply $actual, { + buffer => 1000, + proxy_url => "https://tilma.staging.mysociety.org/resource-proxy/proxy.php", + url => "https://westminster.assets/40/query", + property => 'USRN', + }; + $actual = $westminster->lookup_site_code_config('UPRN'); + delete $actual->{accept_feature}; # is_deeply doesn't like code + is_deeply $actual, { + buffer => 1000, + proxy_url => "https://tilma.staging.mysociety.org/resource-proxy/proxy.php", + url => "https://westminster.assets/25/query", + property => 'UPRN', + accept_types => { + Point => 1 + }, + }; +}; + +subtest 'nearest UPRN returns correct point' => sub { + my $cfg = { + accept_feature => sub { 1 }, + property => 'UPRN', + accept_types => { + Point => 1, + }, + }; + my $features = [ + # A couple of incorrect geometry types to check they're ignored... + { geometry => { type => 'Polygon' } }, + { geometry => { type => 'LineString', + coordinates => [ [ 527735, 181004 ], [ 527755, 181004 ] ] }, + properties => { fid => '20100024' } }, + # And two points which are further away than the above linestring, + # the second of which is the closest to our testing point. + { geometry => { type => 'Point', + coordinates => [ 527795, 181024 ] }, + properties => { UPRN => '10012387122' } }, + { geometry => { type => 'Point', + coordinates => [ 527739, 181009 ] }, + properties => { UPRN => '10012387123' } }, + ]; + is $westminster->_nearest_feature($cfg, 527745, 180994, $features), '10012387123'; +}; + + done_testing(); diff --git a/web/cobrands/westminster/assets.js b/web/cobrands/westminster/assets.js index 639ae0c11..1e46ae192 100644 --- a/web/cobrands/westminster/assets.js +++ b/web/cobrands/westminster/assets.js @@ -128,7 +128,7 @@ fixmystreet.message_controller.register_category({ var layer_data = [ { category: [ 'Food safety/hygiene' ] }, - { category: 'Damaged, dirty, or missing bin', subcategories: [ '1', '2' ], subcategory_id: '#form_bintype' }, + { category: 'Damaged, dirty, or missing bin', subcategories: [ '1', '4' ], subcategory_id: '#form_bin_type' }, { category: 'Noise', subcategories: [ '1', '3', '4', '7', '8', '9', '10' ] }, { category: 'Smoke and odours' }, ]; @@ -299,7 +299,7 @@ $.each(layer_data, function(i, o) { }); $(function(){ - $("#problem_form").on("change.category", "#form_type, #form_featuretypecode, #form_bintype", function() { + $("#problem_form").on("change.category", "#form_type, #form_featuretypecode, #form_bin_type", function() { $(fixmystreet).trigger('report_new:category_change'); }); }); |