Skip to content

Commit a423488

Browse files
committed
[Confirm] Support returning defect photos when they are fetched.
1 parent ba4723e commit a423488

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

perllib/Integrations/Confirm.pm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ has defect_update_job_photo_statuses => (
181181
);
182182

183183

184+
=head2 include_photos_on_defect_fetch
185+
186+
Whether or not to include defect photos when they are fetched in get_service_requests.
187+
188+
=cut
189+
190+
has include_photos_on_defect_fetch => (
191+
is => 'lazy',
192+
default => sub { $_[0]->config->{include_photos_on_defect_fetch} }
193+
);
194+
195+
184196
=head2 external_system_number
185197
186198
A code to use to mark enquiries we submit as coming from us; with this set,
@@ -611,6 +623,7 @@ sub defects_graphql_query { # XXX factor together with jobs?
611623
}
612624
documents {
613625
url
626+
documentName
614627
}
615628
description
616629
}

perllib/Open311/Endpoint/Integration/Confirm.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,14 @@ sub _get_service_requests_for_defects {
14401440

14411441
my $description = $self->_description_for_defect($defect, $service);
14421442

1443+
my @media_urls;
1444+
if ($integ->include_photos_on_defect_fetch) {
1445+
my @defect_docs = $self->_parse_graphql_docs($defect->{documents});
1446+
my @filtered = $self->filter_photos_graphql(@defect_docs);
1447+
my @urls = map { $self->construct_photo_url_from_graphql_fetched_doc($_) } @filtered;
1448+
push @media_urls, @urls;
1449+
}
1450+
14431451
my %args = (
14441452
service => $service,
14451453
service_request_id => 'DEFECT_' . $defect_id,
@@ -1450,6 +1458,7 @@ sub _get_service_requests_for_defects {
14501458
# enquiries above
14511459
latlong => [ $defect->{northing}, $defect->{easting} ],
14521460
status => $status,
1461+
@media_urls ? ( media_url => \@media_urls ) : (),
14531462
);
14541463

14551464
my $request = $self->new_request( %args );

t/open311/endpoint/confirm_photos.t

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,57 @@ subtest "fetching of job photos for defect update via GraphQL" => sub {
224224
$integration->unmock('perform_request_graphql');
225225
};
226226

227+
228+
subtest "fetching of defect photos for defect fetch" => sub {
229+
$integration->mock(perform_request_graphql => sub {
230+
my ( $self, %args ) = @_;
231+
232+
$args{type} ||= '';
233+
$args{query} ||= '';
234+
235+
if ( $args{type} eq 'defects' ) {
236+
return {
237+
data => {
238+
defects => [
239+
{
240+
defectNumber => 1,
241+
easting => 1,
242+
northing => 1,
243+
loggedDate => '2025-01-01T00:00:00Z',
244+
targetDate => '2025-01-01T00:00:00Z',
245+
defectType => {
246+
code => "SLDA",
247+
},
248+
documents => [
249+
{
250+
url => "/ConfirmWeb/api/tenant/attachments/DEFECT/123/1",
251+
documentName => "photo.jpg"
252+
}
253+
],
254+
}
255+
]
256+
}
257+
};
258+
} elsif ( $args{type} eq 'defect_types' ) {
259+
return {
260+
data => {
261+
defectTypes => [
262+
{ code => 'SLDA', name => 'Defective Street Light' },
263+
],
264+
},
265+
};
266+
}
267+
return {};
268+
});
269+
270+
my $res = $endpoint_graphql->run_test_request(
271+
GET => '/requests.xml?start_date=2025-01-01T00:00:00Z&end_date=2025-01-01T01:00:00Z',
272+
);
273+
ok $res->is_success, 'valid request' or diag $res->content;
274+
contains_string $res->content, '<media_url>http://example.com/photos?jurisdiction_id=confirm_dummy_photos_graphql&amp;doc_url=%2Fattachments%2FDEFECT%2F123%2F1</media_url>';
275+
276+
$lwp->mock(request => \&empty_json);
277+
$integration->unmock('perform_request_graphql');
278+
};
279+
227280
done_testing;

t/open311/endpoint/confirm_photos_graphql.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ defect_service_mapping:
2424
SLDA:
2525
group: Street Lighting
2626
category: Defective Street Light
27+
28+
include_photos_on_defect_fetch: true

0 commit comments

Comments
 (0)