diff options
author | Struan Donald <struan@exo.org.uk> | 2019-07-19 15:18:21 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2019-07-31 14:44:36 +0100 |
commit | d43dcaeccd714926c7dd9d00c554d16d179c21ab (patch) | |
tree | 98b540a9d08f8f113748b70b71cd703c5c81cc66 | |
parent | 924a9f155140e511a88f21a6cd0116a93fe08176 (diff) |
[open311] unset the external_status_code if blank
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.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 2 | ||||
-rw-r--r-- | t/open311/getservicerequestupdates.t | 30 |
3 files changed, 33 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a55e183..798d5ec25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 7480ba258..2489bd611 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -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 diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index d58855122..809fd3a19 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -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 { |