Skip to content

Commit

Permalink
[Bexley] Use red tag logs to signal round completion
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismytton committed May 2, 2024
1 parent 14a6294 commit 6ca9636
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
17 changes: 14 additions & 3 deletions perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ sub bin_services_for_address {
my ($property_logs, $street_logs) = $self->_in_cab_logs($property);

$property->{red_tags} = $property_logs;
$property->{service_updates} = $street_logs;
$property->{service_updates} = grep { $_->{service_update} } @$street_logs;
my %round_exceptions = map { $_->{round} => 1 } @$property_logs;
$property->{round_exceptions} = \%round_exceptions;

Expand Down Expand Up @@ -353,10 +353,20 @@ sub _in_cab_logs {
my $dt_from = $self->_subtract_working_days(WORKING_DAYS_WINDOW);
my $cab_logs;
if ( !$self->{c}->stash->{cab_logs} ) {
$cab_logs = $self->whitespace->GetInCabLogsByUprn(
my $cab_logs_uprn = $self->whitespace->GetInCabLogsByUprn(
$property->{uprn},
$dt_from->stringify,
);
my $cab_logs_usrn = $self->whitespace->GetInCabLogsByUsrn(
$cab_logs_uprn->[0]{Usrn},
$dt_from->stringify,
);
$cab_logs = [ @$cab_logs_uprn, @$cab_logs_usrn ];

# Make cab logs unique by LogID
my %seen;
@$cab_logs = grep { !$seen{ $_->{LogID} }++ } @$cab_logs;

$self->{c}->stash->{cab_logs} = $cab_logs;
} else {
$cab_logs = $self->{c}->stash->{cab_logs};
Expand All @@ -373,7 +383,7 @@ sub _in_cab_logs {

my $logdate = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S' )->parse_datetime( $_->{LogDate} );

if ( $_->{Uprn} ) {
if ( $_->{Uprn} && $_->{Uprn} eq $property->{uprn} ) {
push @property_logs, {
uprn => $_->{Uprn},
round => $_->{RoundCode},
Expand All @@ -383,6 +393,7 @@ sub _in_cab_logs {
};
} else {
push @street_logs, {
service_update => $_->{Uprn} ? 0 : 1,
round => $_->{RoundCode},
reason => $_->{Reason},
date => $logdate,
Expand Down
42 changes: 24 additions & 18 deletions t/app/controller/waste_bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ $whitespace_mock->mock(
);
$whitespace_mock->mock( 'GetInCabLogsByUprn', sub {
my ( $self, $uprn ) = @_;
return _in_cab_logs()->{$uprn};
return [ grep { $_->{Uprn} eq $uprn } @{ _in_cab_logs() } ];
});
$whitespace_mock->mock( 'GetInCabLogsByUsrn', sub {
my ( $self, $usrn ) = @_;
return _in_cab_logs();
});

my $body = $mech->create_body_ok(2494, 'London Borough of Bexley', {}, { cobrand => 'bexley' });
my $contact = $mech->create_contact_ok(
body => $body,
Expand Down Expand Up @@ -525,6 +528,7 @@ FixMyStreet::override_config {
);

my $property = {
uprn => 10001,
missed_collection_reports => {
'RES-SACK' => 1,
},
Expand Down Expand Up @@ -980,20 +984,22 @@ sub _worksheet_detail_service_items {
}

sub _in_cab_logs {
{
10001 => [
{
Reason => 'Food - Not Out',
RoundCode => 'RND-1',
LogDate => '2024-03-28T06:10:09.417',
Uprn => '10001',
},
{
Reason => 'N/A',
RoundCode => 'RND-6',
LogDate => '2024-03-28T06:10:09.417',
Uprn => '',
},
],
}
[
{
LogID => 1,
Reason => 'Food - Not Out',
RoundCode => 'RND-1',
LogDate => '2024-03-28T06:10:09.417',
Uprn => '10001',
Usrn => '321',
},
{
LogID => 2,
Reason => 'N/A',
RoundCode => 'RND-6',
LogDate => '2024-03-28T06:10:09.417',
Uprn => '',
Usrn => '321',
},
]
}

0 comments on commit 6ca9636

Please sign in to comment.