aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm9
-rw-r--r--t/open311/getservicerequestupdates.t48
3 files changed, 58 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 407656364..844d8dc27 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
- Allow Open311 service definitions to include automated
attributes #1986
- Optionally supress blank Open311 update errors #1986
+ - Fetch/store external status code with Open311 updates. #2048
- Front end improvements:
- Improve questionnaire process. #1939 #1998
- Increase size of "sub map links" (hide pins, permalink, etc) #2003
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index f2a319f15..8d05a358f 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -110,6 +110,7 @@ sub update_comments {
if ( !$c->first ) {
my $state = $open311->map_state( $request->{status} );
+ my $external_status_code = $request->{external_status_code};
my $comment = $self->schema->resultset('Comment')->new(
{
problem => $p,
@@ -126,6 +127,14 @@ sub update_comments {
}
);
+ # Some Open311 services, e.g. Confirm via open311-adapter, provide
+ # a more fine-grained status code that we use within FMS for
+ # response templates.
+ if ( $external_status_code ) {
+ $comment->set_extra_metadata(external_status_code =>$external_status_code);
+ $p->set_extra_metadata(external_status_code =>$external_status_code);
+ }
+
$open311->add_media($request->{media_url}, $comment)
if $request->{media_url};
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index a53354685..885c0c183 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -650,6 +650,54 @@ subtest 'check that existing comments are not duplicated' => sub {
is $problem->comments->count, 2, 'if comments are deleted then they are added';
};
+subtest 'check that external_status_code is stored correctly' => sub {
+ my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
+ <service_requests_updates>
+ <request_update>
+ <update_id>638344</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>060</external_status_code>
+ </request_update>
+ <request_update>
+ <update_id>638354</update_id>
+ <service_request_id>@{[ $problem->external_id ]}</service_request_id>
+ <status>open</status>
+ <description>This is a different note</description>
+ <updated_datetime>UPDATED_DATETIME2</updated_datetime>
+ <external_status_code>101</external_status_code>
+ </request_update>
+ </service_requests_updates>
+ };
+
+ $problem->comments->delete;
+
+ my $dt2 = $dt->clone->subtract( hours => 1 );
+ $requests_xml =~ s/UPDATED_DATETIME2/$dt/;
+ $requests_xml =~ s/UPDATED_DATETIME/$dt2/;
+
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } );
+
+ my $update = Open311::GetServiceRequestUpdates->new(
+ system_user => $user,
+ );
+
+ $update->update_comments( $o, $bodies{2482} );
+
+ $problem->discard_changes;
+ is $problem->comments->count, 2, 'two comments after fetching updates';
+
+ my @comments = $problem->comments->all;
+
+ is $comments[0]->get_extra_metadata('external_status_code'), "060", "correct external status code on first comment";
+ is $comments[1]->get_extra_metadata('external_status_code'), "101", "correct external status code on second comment";
+
+ is $problem->get_extra_metadata('external_status_code'), "101", "correct external status code";
+
+};
+
foreach my $test ( {
desc => 'check that closed and then open comment results in correct state',
dt1 => $dt->clone->subtract( hours => 1 ),