File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed
Open311/Endpoint/Integration Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,18 @@ has defect_update_job_photo_statuses => (
181
181
);
182
182
183
183
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
+
184
196
=head2 external_system_number
185
197
186
198
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?
611
623
}
612
624
documents {
613
625
url
626
+ documentName
614
627
}
615
628
description
616
629
}
Original file line number Diff line number Diff line change @@ -1440,6 +1440,14 @@ sub _get_service_requests_for_defects {
1440
1440
1441
1441
my $description = $self -> _description_for_defect($defect , $service );
1442
1442
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
+
1443
1451
my %args = (
1444
1452
service => $service ,
1445
1453
service_request_id => ' DEFECT_' . $defect_id ,
@@ -1450,6 +1458,7 @@ sub _get_service_requests_for_defects {
1450
1458
# enquiries above
1451
1459
latlong => [ $defect -> {northing }, $defect -> {easting } ],
1452
1460
status => $status ,
1461
+ @media_urls ? ( media_url => \@media_urls ) : (),
1453
1462
);
1454
1463
1455
1464
my $request = $self -> new_request( %args );
Original file line number Diff line number Diff line change @@ -224,4 +224,57 @@ subtest "fetching of job photos for defect update via GraphQL" => sub {
224
224
$integration -> unmock(' perform_request_graphql' );
225
225
};
226
226
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&doc_url=%2Fattachments%2FDEFECT%2F123%2F1</media_url>' ;
275
+
276
+ $lwp -> mock(request => \&empty_json);
277
+ $integration -> unmock(' perform_request_graphql' );
278
+ };
279
+
227
280
done_testing;
Original file line number Diff line number Diff line change @@ -24,3 +24,5 @@ defect_service_mapping:
24
24
SLDA :
25
25
group : Street Lighting
26
26
category : Defective Street Light
27
+
28
+ include_photos_on_defect_fetch : true
You can’t perform that action at this time.
0 commit comments