Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bromley] Include notes in updates from Echo #5277

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
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,34 +427,46 @@
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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it would be good to have a comment or constant to explain what code 1252 refers to exactly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this could certainly do with more description (and on the wiki too, now the project's live). Hopefully the "redirecting of reports between backends" tests in t/cobrand/bromley.t at least show the behaviour of things bouncing back and forth.
(Basically, if a report is sent to Echo, they can refer it to Bromley by sending a '1252' update code to us)

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')) {
# Originally sent to Bromley, don't need to resend report
$problem->external_id($original_external_id);
$comment->problem_state(REFERRED_TO_BROMLEY);
$comment->send_state('unprocessed');
} else {
# Resending report, don't need comment to be public
} elsif ($self->_has_report_been_sent_to_echo($problem)) {
# Resending report from Echo to Bromley for first time, don't need comment to be public
$comment->state('hidden');
$problem->resend;
} else {
# 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 @@
(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
28 changes: 21 additions & 7 deletions t/cobrand/bromley.t
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,19 @@ subtest 'redirecting of reports between backends' => sub {

is_deeply [ map { $_->state } $report->comments->order_by('id')->all ], ['hidden', 'hidden'];
};

my $event_guid = '05a10cb2-44c9-48d9-92a2-cc6788994bae';

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' });
$report->update({ external_id => $event_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';
is $report->external_id, $event_guid, 'ID not changed';
is $report->state, 'in progress', 'A state change';
is $report->category, 'Environmental Services';
FixMyStreet::Script::Reports::send();
Expand All @@ -856,8 +859,19 @@ subtest 'redirecting of reports between backends' => sub {
is $c->param('description'), "$detail | Handover notes - Outgoing notes from Echo";
};

subtest 'A second referral update comes in, should be a normal update' => sub {
$report->update({ external_id => 'bromley-id' });
$mech->post('/waste/echo', Content_Type => 'text/xml', Content => $in);
is $report->comments->count, 2, 'A new update';
my @updates = $report->comments->order_by('id')->all;
is_deeply [ map { $_->state } @updates ], ['hidden', 'confirmed'];
is_deeply [ map { $_->problem_state } @updates ], ['in progress', 'Environmental Services'];
$report->discard_changes;
isnt $report->whensent, undef; # Got sent in last subtest
is $report->external_id, 'bromley-id', 'ID not changed';
};

subtest "comment on a closed echo report result in a resend under 'Street Services'" => sub {
my $event_guid = '05a10cb2-44c9-48d9-92a2-cc6788994bae';
my $event_id = 123;

my $echo = Test::MockModule->new('Integrations::Echo');
Expand Down Expand Up @@ -924,19 +938,19 @@ subtest 'redirecting of reports between backends' => sub {
};

subtest "Another update from Echo on this new sent report closes it again" => sub {
$report->update({ external_id => 'guid' });
my $in = $mech->echo_notify_xml('guid', 2104, 15004, 67);
$report->update({ external_id => $event_guid });
my $in = $mech->echo_notify_xml('guid', 2104, 15004, 67, 'FMS-' . $report->id);
$mech->post('/waste/echo', Content_Type => 'text/xml', Content => $in);
is $report->comments->count, 3, 'A new update';
$report->discard_changes;
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 {
my $in = $mech->echo_notify_xml('guid', 2104, 15004, 1252);
my $in = $mech->echo_notify_xml('guid', 2104, 15004, 1252, 'FMS-' . $report->id);
$mech->post('/waste/echo', Content_Type => 'text/xml', Content => $in);
is $report->comments->count, 4, 'A new update';
$report->discard_changes;
Expand Down