Skip to content

Commit

Permalink
[open311] unset the external_status_code if blank
Browse files Browse the repository at this point in the history
If an update with a blank external_status_code is fetched then unset it
otherwise we will always a detect a change in the external_status_code
which might mean phantom updates.
  • Loading branch information
struan committed Jul 31, 2019
1 parent 924a9f1 commit d43dcae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -39,6 +39,7 @@
- Do not store display-only extra fields on new reports.
- Support receiving updates from external source.
- Improve JSON output of controller.
- unset external_status_code if blank in update

* v2.6 (3rd May 2019)
- New features:
Expand Down
2 changes: 2 additions & 0 deletions perllib/Open311/GetServiceRequestUpdates.pm
Expand Up @@ -181,6 +181,8 @@ sub process_update {
if ( $external_status_code ) {
$comment->set_extra_metadata(external_status_code => $external_status_code);
$p->set_extra_metadata(external_status_code => $external_status_code);
} else {
$p->set_extra_metadata(external_status_code => '');
}

# if the customer reference to display in the report metadata is
Expand Down
30 changes: 30 additions & 0 deletions t/open311/getservicerequestupdates.t
Expand Up @@ -874,6 +874,36 @@ subtest 'check that external_status_code is stored correctly' => sub {
is $problem->get_extra_metadata('external_status_code'), "101", "correct external status code";
$requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests_updates>
<request_update>
<update_id>638364</update_id>
<service_request_id>@{[ $problem->external_id ]}</service_request_id>
<status>open</status>
<description>This is a note</description>
<updated_datetime>UPDATED_DATETIME</updated_datetime>
<external_status_code></external_status_code>
</request_update>
</service_requests_updates>
};
$problem->comments->delete;
my $dt3 = $dt->clone->add( minutes => 1 );
$requests_xml =~ s/UPDATED_DATETIME/$dt3/;
$o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } );
$update = Open311::GetServiceRequestUpdates->new(
system_user => $user,
current_open311 => $o,
current_body => $bodies{2482},
);
$update->process_body;
$problem->discard_changes;
is $problem->get_extra_metadata('external_status_code'), '', "external status code unset";
};
subtest 'check that external_status_code triggers auto-responses' => sub {
Expand Down

0 comments on commit d43dcae

Please sign in to comment.