Skip to content

Commit

Permalink
Merge branch 'bexley-whitespace-ignore-duplicate-log-entries' into co…
Browse files Browse the repository at this point in the history
…mmercial-staging
  • Loading branch information
chrismytton committed Jan 7, 2025
2 parents d25fb51 + 316359b commit cbe4fcc
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ sub _in_cab_logs {
my @property_logs;
my @street_logs;
my %completed_or_attempted_collections;
my %seen_logs;

return ( \@property_logs, \@street_logs, \%completed_or_attempted_collections )
unless $cab_logs;
Expand All @@ -647,6 +648,13 @@ sub _in_cab_logs {
# Gather property-level and street-level exceptions
if ( $_->{Reason} && $_->{Reason} ne 'N/A' ) {
if ( $_->{Uprn} && $_->{Uprn} eq $property->{uprn} ) {
# Create a unique key for this log entry based on the actual event details
# using just the date portion of LogDate since multiple logs for the same
# event might have different timestamps on the same day
my $date_only = $logdate->ymd;
my $log_key = join(':', $_->{Reason}, $_->{RoundCode}, $date_only);
next if $seen_logs{$log_key}++;

push @property_logs, {
uprn => $_->{Uprn},
round => $_->{RoundCode},
Expand Down
6 changes: 6 additions & 0 deletions perllib/FixMyStreet/Cobrand/UKCouncils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ sub munge_reports_category_list {
sub munge_report_new_bodies {
my ($self, $bodies) = @_;

if ($self->{c}->action =~ /^waste/) {
my $body_id = $self->body->id;
%$bodies = map { $_->id => $_ } grep { $_->id eq $body_id } values %$bodies;
return;
}

my %bodies = map { $_->get_column('name') => 1 } values %$bodies;
if ( $bodies{'TfL'} ) {
# Presented categories vary if we're on/off a red route
Expand Down
68 changes: 68 additions & 0 deletions t/app/controller/waste_bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,74 @@ FixMyStreet::override_config {
set_fixed_time('2024-03-31T02:00:00'); # March 31st, 02:00 BST
};

subtest 'Deduplication of in-cab logs' => sub {
$whitespace_mock->mock('GetInCabLogsByUsrn', sub {
return [
# Two logs with same reason, round code and date but different times
{
LogID => 1,
Reason => 'Refuse - Not Out',
RoundCode => 'RES-R3',
LogDate => '2024-04-01T10:02:15.7',
Uprn => '10001',
Usrn => '321',
},
{
LogID => 2,
Reason => 'Refuse - Not Out',
RoundCode => 'RES-R3',
LogDate => '2024-04-01T10:05:20.1',
Uprn => '10001',
Usrn => '321',
},
# Different date, should be included
{
LogID => 3,
Reason => 'Refuse - Not Out',
RoundCode => 'RES-R3',
LogDate => '2024-04-02T10:02:15.7',
Uprn => '10001',
Usrn => '321',
},
# Different reason, should be included
{
LogID => 4,
Reason => 'Food - Not Out',
RoundCode => 'RES-R3',
LogDate => '2024-04-01T10:02:15.7',
Uprn => '10001',
Usrn => '321',
},
# Different round code, should be included
{
LogID => 5,
Reason => 'Refuse - Not Out',
RoundCode => 'RES-R4',
LogDate => '2024-04-01T10:02:15.7',
Uprn => '10001',
Usrn => '321',
},
];
});

set_fixed_time('2024-04-03T12:00:00');
$mech->get_ok('/waste/10001');
$mech->content_contains('Service status');
$mech->content_contains('Our collection teams have reported the following problems with your bins:');

# Count occurrences of each type of message
my $content = $mech->content;
my $refuse_not_out_count = () = $content =~ /Refuse - Not Out/g;
my $food_not_out_count = () = $content =~ /Food - Not Out/g;

is($refuse_not_out_count, 3, "Shows three 'Refuse - Not Out' messages (two different dates, one different round)");
is($food_not_out_count, 1, "Shows one 'Food - Not Out' message");

# Reset mock and time
default_mocks();
set_fixed_time('2024-03-31T01:00:00');
};

subtest 'Missed enquiry form for properties with no collections' => sub {
$mech->delete_problems_for_body( $body->id );

Expand Down
8 changes: 8 additions & 0 deletions t/app/controller/waste_kingston_r.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ create_contact({ category => 'Request new container', email => '1635' }, 'Waste'
{ code => 'payment', required => 0, automated => 'hidden_field' },
);

# Merton also covers Kingston because of an out-of-area park which is their responsibility
my $merton = $mech->create_body_ok(2500, 'Merton Council');
FixMyStreet::DB->resultset('BodyArea')->create({ area_id => 2480, body_id => $merton->id });
my $contact = $mech->create_contact_ok(body => $merton, category => 'Report missed collection', email => 'missed');
$contact->set_extra_metadata( type => 'waste' );
$contact->update;

my ($sent_params, $sent_data);

FixMyStreet::override_config {
Expand Down Expand Up @@ -356,6 +363,7 @@ FixMyStreet::override_config {
is $report->get_extra_field_value('uprn'), 1000000002;
is $report->detail, "Report missed Food waste\n\n2 Example Street, Kingston, KT1 1AA";
is $report->title, 'Report missed Food waste';
is $report->bodies_str, $kingston->id, 'correct bodies_str';
};
subtest 'No reporting/requesting if open request' => sub {
$mech->get_ok('/waste/12345');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cbe4fcc

Please sign in to comment.