Skip to content

Commit

Permalink
[Bromley] Hide referral update after sending.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Oct 11, 2024
1 parent efeb221 commit 125bae0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
22 changes: 12 additions & 10 deletions perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -334,26 +334,28 @@ sub _include_user_title_in_extra {
sub open311_pre_send_updates {
my ($self, $row) = @_;

$self->{bromley_original_update_text} = $row->text;

my $private_comments = $row->get_extra_metadata('private_comments');
if ($private_comments) {
my $text = $row->text . "\n\nPrivate comments: $private_comments";
$row->text($text);
}

return $self->_include_user_title_in_extra($row);
}

sub open311_post_send_updates {
my ($self, $row) = @_;
my ($self, $comment, $external_id) = @_;

$row->text($self->{bromley_original_update_text});
if (($comment->problem_state || '') eq REFERRED_TO_BROMLEY) {
if ($external_id) {
$comment->state('hidden');

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

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bromley.pm#L345

Added line #L345 was not covered by tests
}
}
}

sub open311_munge_update_params {
my ($self, $params, $comment, $body) = @_;

my $private_comments = $comment->get_extra_metadata('private_comments');
if ($private_comments) {
my $text = $params->{description} . "\n\nPrivate comments: $private_comments";
$params->{description} = $text;
}

delete $params->{update_id};
$params->{public_anonymity_required} = $comment->anonymous ? 'TRUE' : 'FALSE',
$params->{update_id_ext} = $comment->id;
Expand Down
2 changes: 1 addition & 1 deletion perllib/Open311/PostServiceRequestUpdates.pm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ sub process_update {

my $id = $o->post_service_request_update( $comment );

$cobrand->call_hook(open311_post_send_updates => $comment);
$cobrand->call_hook(open311_post_send_updates => $comment, $id);

if ( $id ) {
$comment->update( {
Expand Down
5 changes: 5 additions & 0 deletions t/cobrand/bromley.t
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ subtest 'redirecting of reports between backends' => sub {
$update->process_body;
$report->discard_changes;
is $report->comments->count, 1;
is_deeply [ map { $_->state } $report->comments->all ], ['hidden'];
is $report->whensent, undef;
is $report->get_extra_metadata('handover_notes'), 'This is a handover note';
is $report->category, 'Street Services';
Expand All @@ -816,6 +817,7 @@ subtest 'redirecting of reports between backends' => sub {
$report->update({ external_id => 'parent-guid', whensent => DateTime->now, send_method_used => 'Open311' });
$mech->post('/waste/echo', Content_Type => 'text/xml', Content => $in);
is $report->comments->count, 2, 'A new update';
is_deeply [ map { $_->state } $report->comments->order_by('id')->all ], ['hidden', 'confirmed'];
$report->discard_changes;
is $report->external_id, 12345, 'ID changed back';
is $report->state, 'in progress', 'A state change';
Expand All @@ -832,13 +834,16 @@ subtest 'redirecting of reports between backends' => sub {
is $c->param('status'), 'REFERRED_TO_LBB_STREETS';
is $c->param('service_code'), 'LBB_RRE_FROM_VEOLIA_STREETS';
is $c->param('description'), 'Outgoing notes from Echo';

is_deeply [ map { $_->state } $report->comments->order_by('id')->all ], ['hidden', 'hidden'];
};
subtest 'A report sent to Echo, redirected to Confirm' => sub {
$report->comments->delete;
$report->unset_extra_metadata('original_bromley_external_id');
$report->update({ external_id => 'original-guid' });
$mech->post('/waste/echo', Content_Type => 'text/xml', Content => $in);
is $report->comments->count, 1, 'A new update';
is_deeply [ map { $_->state } $report->comments->all ], ['hidden'];
$report->discard_changes;
is $report->whensent, undef;
is $report->external_id, 'original-guid', 'ID not changed';
Expand Down

0 comments on commit 125bae0

Please sign in to comment.