diff options
author | Struan Donald <struan@exo.org.uk> | 2019-04-09 13:00:50 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2019-04-09 13:00:50 +0100 |
commit | aabed59c3822f6053e131d28e2b66ea363ca215e (patch) | |
tree | 726684a68e03b5f81bbf8fb763caa020443f04ac /t/open311 | |
parent | 06809a5c80c4c04f0a4cbae398bae8609038dfed (diff) |
[Open311] handle bad FixMyStreet id in updates
If an update has a fixmystreet id in it check that it looks like an
integer and if not issue a warning and skip the update.
Diffstat (limited to 't/open311')
-rw-r--r-- | t/open311/getservicerequestupdates.t | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 055c5ea5f..573e23cfc 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -4,6 +4,7 @@ use FixMyStreet::Test; use Test::Output; use CGI::Simple; use LWP::Protocol::PSGI; +use Test::Warn; use t::Mock::Static; use_ok( 'Open311' ); @@ -1091,6 +1092,40 @@ subtest 'check matching on fixmystreet_id overrides service_request_id' => sub { is $comments[0]->external_id, 638344, "correct first comment added"; is $comments[1]->external_id, 638356, "correct second comment added"; }; + +subtest 'check bad fixmystreet_id is handled' => 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>8888888888888</service_request_id> + <fixmystreet_id>123456 654321</fixmystreet_id> + <status>open</status> + <description>This is a note</description> + <updated_datetime>UPDATED_DATETIME</updated_datetime> + </request_update> + </service_requests_updates> + }; + + $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, + ); + + warning_like { + $update->update_comments( $o, $bodies{2482} ) + } + qr/skipping bad fixmystreet id in updates for Bromley: \[123456 654321\], external id is 8888888888888/, + "warning emitted for bad fixmystreet id"; + + $problem->discard_changes; + is $problem->comments->count, 0, 'no comments after fetching updates'; +}; done_testing(); sub setup_xml { |