diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 13 | ||||
-rw-r--r-- | t/open311/getservicerequestupdates.t | 41 |
3 files changed, 52 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 844d8dc27..bf5d04a76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ attributes #1986 - Optionally supress blank Open311 update errors #1986 - Fetch/store external status code with Open311 updates. #2048 + - Response templates can be triggered by external status code. #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 8d05a358f..661b039b0 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -116,7 +116,7 @@ sub update_comments { problem => $p, user => $self->system_user, external_id => $request->{update_id}, - text => $self->comment_text_for_request($request, $p, $state), + text => $self->comment_text_for_request($request, $p, $state, $external_status_code), mark_fixed => 0, mark_open => 0, anonymous => 0, @@ -183,13 +183,20 @@ sub update_comments { } sub comment_text_for_request { - my ($self, $request, $problem, $state) = @_; + my ($self, $request, $problem, $state, $external_status_code) = @_; return $request->{description} if $request->{description}; + my $state_params = { + 'me.state' => $state + }; + if ($external_status_code) { + $state_params->{'me.external_status_code'} = $external_status_code; + }; + if (my $template = $problem->response_templates->search({ auto_response => 1, - 'me.state' => $state + -or => $state_params, })->first) { return $template->text; } diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 885c0c183..ec2ffb593 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -698,6 +698,47 @@ subtest 'check that external_status_code is stored correctly' => sub { }; +subtest 'check that external_status_code triggers auto-responses' => 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></description> + <updated_datetime>UPDATED_DATETIME</updated_datetime> + <external_status_code>060</external_status_code> + </request_update> + </service_requests_updates> + }; + + my $response_template = $bodies{2482}->response_templates->create({ + title => "Acknowledgement", + text => "Thank you for your report. We will provide an update within 24 hours.", + auto_response => 1, + external_status_code => "060" + }); + + $problem->comments->delete; + + $requests_xml =~ s/UPDATED_DATETIME/$dt/; + + 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, 1, 'one comment after fetching updates'; + + my $comment = $problem->comments->first; + + is $problem->comments->first->text, "Thank you for your report. We will provide an update within 24 hours.", "correct external status code on first comment"; +}; + foreach my $test ( { desc => 'check that closed and then open comment results in correct state', dt1 => $dt->clone->subtract( hours => 1 ), |