From b8e093ddafe4f1b6d217cad92b6b61b5c11a44aa Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 11 Dec 2024 20:23:33 +0000 Subject: [PATCH] [Confirm] Cope if enquiry JSON returns error. --- perllib/Open311/Endpoint/Integration/Confirm.pm | 3 ++- t/open311/endpoint/lincolnshire.t | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/perllib/Open311/Endpoint/Integration/Confirm.pm b/perllib/Open311/Endpoint/Integration/Confirm.pm index 78beaf522..39a8ad6c7 100644 --- a/perllib/Open311/Endpoint/Integration/Confirm.pm +++ b/perllib/Open311/Endpoint/Integration/Confirm.pm @@ -638,7 +638,8 @@ sub photo_urls_for_update { my ($self, $enquiry_id) = @_; my $integ = $self->get_integration; - my $job_id = $integ->get_enquiry_json($enquiry_id)->{primaryJobNumber} or return; + my $enquiry = $integ->get_enquiry_json($enquiry_id) or return; + my $job_id = $enquiry->{primaryJobNumber}; my $documents = $integ->documents_for_job($job_id) or return; my @ids = map { $_->{documentNo} } grep { $self->photo_filter($_) } @$documents; diff --git a/t/open311/endpoint/lincolnshire.t b/t/open311/endpoint/lincolnshire.t index af50d3a8d..a0a50517e 100644 --- a/t/open311/endpoint/lincolnshire.t +++ b/t/open311/endpoint/lincolnshire.t @@ -55,6 +55,21 @@ $open311->mock(perform_request => sub { return {}; }); +subtest "bad look up of completion photo" => sub { + my $endpoint = Open311::Endpoint::Integration::UK::Dummy->new; + my $lwp = Test::MockModule->new('LWP::UserAgent'); + $lwp->mock(request => sub { + my ($ua, $req) = @_; + return HTTP::Response->new(200, 'OK', [], '{"access_token":"123","expires_in":3600}') if $req->uri =~ /oauth\/token/; + return HTTP::Response->new(404, 'Not found', [], 'Hmm') if $req->uri =~ /enquiries\/2020/; + }); + my $res = $endpoint->run_test_request( + GET => '/servicerequestupdates.xml?start_date=2022-10-23T00:00:00Z&end_date=2022-10-24T00:00:00Z', + ); + ok $res->is_success, 'valid request' or diag $res->content; + contains_string $res->content, ''; +}; + subtest "looking up of completion photos" => sub { my $endpoint = Open311::Endpoint::Integration::UK::Dummy->new; my $lwp = Test::MockModule->new('LWP::UserAgent');