Skip to content

Commit

Permalink
Ensure cut_off_date is respected if is_two_tier is set
Browse files Browse the repository at this point in the history
  • Loading branch information
davea committed Sep 16, 2024
1 parent 4d06ea9 commit 167ba69
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
13 changes: 12 additions & 1 deletion perllib/FixMyStreet/Cobrand/UKCouncils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,18 @@ sub problems_on_map_restriction {
my ($self, $rs) = @_;
# If we're a two-tier council show all problems on the map and not just
# those for this cobrand's council to reduce duplicate reports.
return $self->is_two_tier ? $rs : $self->problems_restriction($rs);
# (but still respect the cut-off date)
if ($self->is_two_tier) {
if (my $date = $self->cut_off_date) {
my $table = ref $rs eq 'FixMyStreet::DB::ResultSet::Nearby' ? 'problem' : 'me';
$rs = $rs->search({
"$table.created" => { '>=', $date }
});
}
return $rs;
} else {
return $self->problems_restriction($rs);
}
}

sub updates_restriction {
Expand Down
30 changes: 29 additions & 1 deletion t/cobrand/surrey.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ $mech->create_contact_ok(body_id => $surrey->id, category => 'Potholes', email =
latitude => 51.293415, longitude => -0.441269, areas => '2242',
});

my $guildford = $mech->create_body_ok(2452, 'Guildford Borough Council');
$mech->create_contact_ok(body_id => $guildford->id, category => 'Flytipping', email => '[email protected]');

my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'surrey' ],
Expand Down Expand Up @@ -63,7 +66,32 @@ FixMyStreet::override_config {
$mech->get_ok("/dashboard?export=1");
$mech->content_contains('website,surrey,,2', 'CSV Subscriber number is 2 from pre-generated csv');
$mech->log_out_ok;
}
};

subtest 'Old reports are not shown on Surrey cobrand' => sub {
note 'A newly created report is shown on Surrey cobrand';
my $json = $mech->get_ok_json('/around?ajax=1&bbox=-0.45869262976076,51.28481314324,-0.42367370886232,51.302390882532');
is_deeply($json->{pins}, [
[ "51.293415", "-0.441269", "yellow", 1, "Pothole Test 1 for 1", "", 'false' ],
], 'Problem is initially included in Surrey cobrand');

note 'Making the report predate the cut-off excludes it from Surrey cobrand';
my $dt = DateTime->new(year => 2024, month => 9, day => 1, hour => 12);
$report->update({
created => $dt,
confirmed => $dt,
});
$json = $mech->get_ok_json('/around?ajax=1&bbox=-0.45869262976076,51.28481314324,-0.42367370886232,51.302390882532');
is_deeply($json->{pins}, [], 'Problem is now excluded from Surrey cobrand');

note 'Borough reports are excluded from Surrey cobrand if old enough too.';
$report->update({
bodies_str => $guildford->id,
category => 'Flytipping',
});
$json = $mech->get_ok_json('/around?ajax=1&bbox=-0.45869262976076,51.28481314324,-0.42367370886232,51.302390882532');
is_deeply($json->{pins}, [], 'Borough problem is excluded from Surrey cobrand');
};
};


Expand Down

0 comments on commit 167ba69

Please sign in to comment.