diff options
Diffstat (limited to 't/open311')
-rw-r--r-- | t/open311/getservicerequestupdates.t | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 07c3b4cdd..35be0f7b5 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -932,8 +932,6 @@ subtest 'check that external_status_code triggers auto-responses' => sub { $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"; }; @@ -991,6 +989,83 @@ foreach my $test ( { $problem->comments->delete; }; } + +my $response_template_in_progress = $bodies{2482}->response_templates->create({ + title => "Acknowledgement 1", + text => "Thank you for your report. We will provide an update within 48 hours.", + auto_response => 1, + state => "in progress" +}); + +for my $test ( + { + external_code => '090', + description => 'check numeric external status code in response template override state', + }, + { + external_code => 'futher', + description => 'check alpha external status code in response template override state', + }, +) { + subtest $test->{description} => 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>in_progress</status> + <description></description> + <updated_datetime>UPDATED_DATETIME</updated_datetime> + <external_status_code></external_status_code> + </request_update> + <request_update> + <update_id>638345</update_id> + <service_request_id>@{[ $problem->external_id ]}</service_request_id> + <status>in_progress</status> + <description></description> + <updated_datetime>UPDATED_DATETIME2</updated_datetime> + <external_status_code>@{[ $test->{external_code} ]}</external_status_code> + </request_update> + </service_requests_updates> + }; + + my $response_template = $bodies{2482}->response_templates->create({ + # the default ordering uses the title of the report so + # make sure this comes second + title => "Acknowledgement 2", + text => "Thank you for your report. We will provide an update within 24 hours.", + auto_response => 1, + external_status_code => $test->{external_code} + }); + + $problem->comments->delete; + + my $dt2 = $dt->clone->add( minutes => 1 ); + $requests_xml =~ s/UPDATED_DATETIME/$dt/; + $requests_xml =~ s/UPDATED_DATETIME2/$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, + current_open311 => $o, + current_body => $bodies{2482}, + ); + + $update->process_body; + + $problem->discard_changes; + is $problem->comments->count, 2, 'two comment after fetching updates'; + + my @comments = $problem->comments; + + is $comments[0]->text, "Thank you for your report. We will provide an update within 48 hours.", "correct external status code on first comment"; + is $comments[1]->text, "Thank you for your report. We will provide an update within 24 hours.", "correct external status code on second comment"; + $problem->comments->delete; + $response_template->delete; + }; +} + subtest 'check that first comment always updates state' => sub { my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?> <service_requests_updates> |