diff options
author | Dave Arter <davea@mysociety.org> | 2018-03-21 17:16:49 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2018-03-28 15:31:17 +0100 |
commit | f8a5b193d2eba23e8ba78209d4b70a05fb83a944 (patch) | |
tree | 1c9c759ba5c91c7dcf30fd22e168982288f998ac /t/open311 | |
parent | ed6c2501b859a79b2284870b6f9ee2170ebf959a (diff) |
Fetch and store external_status_code in GetServiceRequestUpdates
If the Open311 endpoint provides the external_status_code field
in servicerequestupdates.xml output, it’s stored in each comment’s
extra field as well as the problem’s extra field. This will make it
possible to trigger response templates based on this value.
Diffstat (limited to 't/open311')
-rw-r--r-- | t/open311/getservicerequestupdates.t | 48 |
1 files changed, 48 insertions, 0 deletions
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 ), |