Skip to content

Commit

Permalink
[Bromley] Include Veolia Notes in update if provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Nov 28, 2024
1 parent 99e3a97 commit 65a3a6f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
36 changes: 21 additions & 15 deletions perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ appropriately.
sub open311_get_update_munging {
my ($self, $comment, $state, $request) = @_;

# An update from Bromley with a special referral state
# An update from Bromley with a special referral state, means "resend to Echo"
if ($state eq 'referred to veolia streets') {
my $problem = $comment->problem;
# Do we want to store the old category somewhere for display?
Expand All @@ -427,24 +427,28 @@ sub open311_get_update_munging {
return;
}

# An update from Echo with resolution code 1252
# Fetch any outgoing notes on the Echo event
# If we pulled the update, we already have it, otherwise look it up
my $event = $request->{echo_event} || do {

Check warning on line 432 in perllib/FixMyStreet/Cobrand/Bromley.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bromley.pm#L432

Added line #L432 was not covered by tests
my $echo = $self->feature('echo');
$echo = Integrations::Echo->new(%$echo);
my $event = $echo->GetEvent($request->{service_request_id}); # From the event, not the report
$echo->log($event->{Data});
$event;
};
my $data = Integrations::Echo::force_arrayref($event->{Data}, 'ExtensibleDatum');
my $notes = "";
foreach (@$data) {

Check warning on line 441 in perllib/FixMyStreet/Cobrand/Bromley.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bromley.pm#L439-L441

Added lines #L439 - L441 were not covered by tests
$notes = $_->{Value} if $_->{DatatypeName} eq 'Veolia Notes';
}

# An update from Echo with resolution code 1252 means "refer to Bromley"
my $code = $comment->get_extra_metadata('external_status_code') || '';
if ($code eq '1252') {
my $problem = $comment->problem;
$problem->category(REFERRED_TO_BROMLEY); # Will be LBB_RRE_FROM_VEOLIA_STREETS
$problem->state('in progress');
$comment->problem_state('in progress');

# Fetch outgoing notes
my $echo = $self->feature('echo');
$echo = Integrations::Echo->new(%$echo);
my $event = $echo->GetEvent($request->{service_request_id}); # From the event, not the report
$echo->log($event->{Data});
my $data = Integrations::Echo::force_arrayref($event->{Data}, 'ExtensibleDatum');
my $notes = "";
foreach (@$data) {
$notes = $_->{Value} if $_->{DatatypeName} eq 'Veolia Notes';
}
$problem->set_extra_metadata(handover_notes => $notes);

if (my $original_external_id = $problem->get_extra_metadata('original_bromley_external_id')) {
Expand All @@ -453,14 +457,16 @@ sub open311_get_update_munging {
$comment->problem_state(REFERRED_TO_BROMLEY);
$comment->send_state('unprocessed');
} elsif ($self->_has_report_been_sent_to_echo($problem)) {
# Resending report from Echo to Bromley, don't need comment to be public
# Resending report from Echo to Bromley for first time, don't need comment to be public
$comment->state('hidden');
$problem->resend;
} else {
# Assume has already been sent to Bromley, no need to resend report
# Assume it has already been sent to Bromley, no need to resend report
$comment->problem_state(REFERRED_TO_BROMLEY);
$comment->send_state('unprocessed');

Check warning on line 466 in perllib/FixMyStreet/Cobrand/Bromley.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bromley.pm#L465-L466

Added lines #L465 - L466 were not covered by tests
}
} elsif ($notes) {
$comment->text($comment->text . "\n\n" .$notes);

Check warning on line 469 in perllib/FixMyStreet/Cobrand/Bromley.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bromley.pm#L469

Added line #L469 was not covered by tests
}
}

Expand Down
1 change: 1 addition & 0 deletions perllib/FixMyStreet/Roles/Cobrand/Echo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ sub waste_fetch_events {
(my $external_id = $report->external_id) =~ s/^Echo-//;
my $event = $cfg->{echo}->GetEvent($external_id);
my $request = $self->construct_waste_open311_update($cfg, $event) or next;
$request->{echo_event} = $event;

Check warning on line 750 in perllib/FixMyStreet/Roles/Cobrand/Echo.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Roles/Cobrand/Echo.pm#L750

Added line #L750 was not covered by tests

next if !$request->{status} || $request->{status} eq 'confirmed'; # Still in initial state
next unless $self->waste_check_last_update(
Expand Down
2 changes: 1 addition & 1 deletion t/cobrand/bromley.t
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ subtest 'redirecting of reports between backends' => sub {
is $report->state, 'fixed - council', 'A state change';
is $report->get_extra_metadata('external_status_code'), 67;
my $comment = FixMyStreet::DB->resultset("Comment")->search(undef, { order_by => { -desc => 'id' } })->first;
is $comment->text, 'Template text';
is $comment->text, "Template text\n\nOutgoing notes from Echo";
};

subtest "Echo then redirect it back to Confirm" => sub {
Expand Down

0 comments on commit 65a3a6f

Please sign in to comment.