Skip to content

Commit

Permalink
[UK] Fix All Reports pages for bike providers.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Dec 4, 2023
1 parent 902abae commit 8332cbe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions perllib/FixMyStreet/Cobrand/FixMyStreet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
15 changes: 15 additions & 0 deletions t/cobrand/fixmystreet.t
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');

Expand Down Expand Up @@ -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('[email protected]');
my $user = FixMyStreet::DB->resultset('User')->find_or_create({ email => '[email protected]' });
Expand Down

0 comments on commit 8332cbe

Please sign in to comment.