From d43dcaeccd714926c7dd9d00c554d16d179c21ab Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 19 Jul 2019 15:18:21 +0100 Subject: [PATCH] [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. --- CHANGELOG.md | 1 + perllib/Open311/GetServiceRequestUpdates.pm | 2 ++ t/open311/getservicerequestupdates.t | 30 +++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a55e183a3..798d5ec25c7 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 7480ba25889..2489bd611df 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 d58855122c5..809fd3a19a2 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{ + + + 638364 + @{[ $problem->external_id ]} + open + This is a note + UPDATED_DATETIME + + + + }; + + $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 {