diff options
author | Struan Donald <struan@exo.org.uk> | 2018-12-14 15:03:20 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2019-01-04 10:35:30 +0000 |
commit | 8ce5719937b7c589a4c5f65ed5b2ceb9637b9fcf (patch) | |
tree | 41d9189a3d7f7cc28d72c01fd64e1e19b88f07a5 | |
parent | 9e60fac91d78220c351f6cd9c96dcb09e043d99f (diff) |
[Open311] handle non_public field when fetching requests
If there is
<non_public>1</non_public>
tag in an incoming service request then set the created report to
non_public.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequests.pm | 3 | ||||
-rw-r--r-- | t/open311/getservicerequests.t | 64 |
3 files changed, 68 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a18bf405..349d0880f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Open311 improvements: - Fix bug in contact group handling. #2323 - Improve validation of fetched reports timestamps. #2327 + - Fetched reports can be marked non_public #2356 - Development improvements: - Add option to symlink full size photos. #2326 - default_to_body/report_prefill permissions to control default diff --git a/perllib/Open311/GetServiceRequests.pm b/perllib/Open311/GetServiceRequests.pm index 66f7e497d..a8f3788d5 100644 --- a/perllib/Open311/GetServiceRequests.pm +++ b/perllib/Open311/GetServiceRequests.pm @@ -160,6 +160,8 @@ sub create_problems { my $state = $open311->map_state($request->{status}); + my $non_public = $request->{non_public} ? 1 : 0; + my $problem = $self->schema->resultset('Problem')->new( { user => $self->system_user, @@ -182,6 +184,7 @@ sub create_problems { send_method_used => 'Open311', category => $contact, send_questionnaire => 0, + non_public => $non_public, } ); diff --git a/t/open311/getservicerequests.t b/t/open311/getservicerequests.t index 0f87b4d5d..93163b5b9 100644 --- a/t/open311/getservicerequests.t +++ b/t/open311/getservicerequests.t @@ -405,6 +405,70 @@ subtest "check options passed through from body" => sub { ok $props->{convert_latlong}, "convert latlong set" }; +my $non_public_xml = qq[<?xml version="1.0" encoding="utf-8"?> +<service_requests> +<request> +<service_request_id>123456</service_request_id> +<status>open</status> +<status_notes></status_notes> +<service_name>Sidewalk and Curb Issues</service_name> +<service_code>sidewalks</service_code> +<description>this is a problem</description> +<agency_responsible></agency_responsible> +<service_notice></service_notice> +<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime> +<updated_datetime>2010-04-14T06:37:38-08:00</updated_datetime> +<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime> +<lat>51.4021</lat> +<long>0.01578</long> +<non_public>1</non_public> +</request> +</service_requests> +]; + +for my $test ( + { + desc => 'non public is set', + non_public => 1, + }, + { + desc => 'non public is not set', + non_public => 0, + }, +) { + subtest $test->{desc} => sub { + (my $xml = $non_public_xml) =~ s/non_public>1/non_public>$test->{non_public}/; + + my $o = Open311->new( + jurisdiction => 'mysociety', + endpoint => 'http://example.com', + test_mode => 1, + test_get_returns => { 'requests.xml' => $xml} + ); + + my $update = Open311::GetServiceRequests->new( + system_user => $user, + start_date => $start_date, + end_date => $end_date + ); + + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $update->create_problems( $o, $body ); + }; + + my $p = FixMyStreet::DB->resultset('Problem')->search( + { external_id => 123456 } + )->first; + + ok $p, 'problem created'; + is $p->non_public, $test->{non_public}, "report non_public is set correctly"; + + $p->delete; + }; +} + sub prepare_xml { my $replacements = shift; |