Skip to content

Commit

Permalink
[Confirm] Cope if enquiry JSON returns error.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Dec 11, 2024
1 parent 739c938 commit b8e093d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion perllib/Open311/Endpoint/Integration/Confirm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions t/open311/endpoint/lincolnshire.t
Original file line number Diff line number Diff line change
Expand Up @@ -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', [], '<html><body>Hmm</body></html>') 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, '<media_url></media_url>';
};

subtest "looking up of completion photos" => sub {
my $endpoint = Open311::Endpoint::Integration::UK::Dummy->new;
my $lwp = Test::MockModule->new('LWP::UserAgent');
Expand Down

0 comments on commit b8e093d

Please sign in to comment.