From 8332cbea911f56d1fe40867a9c452bbc1ff13648 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 4 Dec 2023 15:23:45 +0000 Subject: [PATCH] [UK] Fix All Reports pages for bike providers. --- perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 27 ++++++++++++++++++++++ t/cobrand/fixmystreet.t | 15 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index 222254027af..66d9c8c8893 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -3,6 +3,7 @@ use base 'FixMyStreet::Cobrand::UK'; use Moo; use JSON::MaybeXS; +use List::Util qw(any); with 'FixMyStreet::Roles::BoroughEmails'; use constant COUNCIL_ID_BROMLEY => 2482; @@ -607,4 +608,30 @@ sub add_extra_area_types { return \@types; } +=head2 fetch_area_children + +If we are looking at the All Reports page for one of the extra London (TfL) +bodies (the bike providers), we want the children to be the London councils, +not all the wards of London. + +=cut + +sub fetch_area_children { + my $self = shift; + my ($area_ids, $body, $all_generations) = @_; + + my $features = FixMyStreet->config('COBRAND_FEATURES') || {}; + my $bodies = $features->{categories_restriction_bodies} || {}; + $bodies = $bodies->{tfl} || []; + if ($body && any { $_ eq $body->name } @$bodies) { + my $areas = FixMyStreet::MapIt::call('areas', 'LBO'); + foreach (keys %$areas) { + $areas->{$_}->{name} =~ s/\s*(Borough|City|District|County) Council$//; + } + return $areas; + } else { + return $self->next::method(@_); + } +} + 1; diff --git a/t/cobrand/fixmystreet.t b/t/cobrand/fixmystreet.t index b6d4f3fa384..4a3554c70f4 100644 --- a/t/cobrand/fixmystreet.t +++ b/t/cobrand/fixmystreet.t @@ -20,6 +20,8 @@ $resolver->mock('address', sub { $_[1] }); my $body = $mech->create_body_ok( 2514, 'Birmingham', {}, { cobrand => 'birmingham' } ); $mech->create_body_ok( 2482, 'Bromley', {}, { cobrand => 'bromley' }); +$mech->create_body_ok(2482, 'Bike provider'); + my $contact = $mech->create_contact_ok( body_id => $body->id, category => 'Traffic lights', @@ -40,6 +42,11 @@ FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', TEST_DASHBOARD_DATA => $data, ALLOWED_COBRANDS => [ 'fixmystreet', 'birmingham' ], + COBRAND_FEATURES => { + categories_restriction_bodies => { + tfl => [ 'Bike provider' ], + } + }, }, sub { ok $mech->host('www.fixmystreet.com'); @@ -122,6 +129,14 @@ FixMyStreet::override_config { $mech->content_lacks('Where we send Birmingham'); }; + subtest 'Check All Reports page for bike bodies' => sub { + $mech->get_ok('/reports/Bike+provider'); + $mech->content_contains('Bromley'); + $mech->content_lacks('Trowbridge'); + $mech->get_ok('/reports/Bike+provider/Bromley'); + is $mech->uri->path, '/reports/Bike+provider/Bromley'; + }; + subtest 'check average fix time respects cobrand cut-off date and non-standard reports' => sub { $mech->log_in_ok('someone@birmingham.gov.uk'); my $user = FixMyStreet::DB->resultset('User')->find_or_create({ email => 'counciluser@example.org' });