diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequests.pm | 9 | ||||
-rw-r--r-- | t/Mock/MapIt.pm | 1 | ||||
-rw-r--r-- | t/open311/getservicerequests.t | 40 |
4 files changed, 48 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 565b8cc94..16c91b885 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fetch/store external status code with Open311 updates. #2048 - Response templates can be triggered by external status code. #2048 - Cobrand hook for adding extra areas to MAPIT_WHITELIST/_TYPES. #2049 + - Enable conversion from EPSG:27700 when fetching over Open311 #2028 - Front end improvements: - Improve questionnaire process. #1939 #1998 - Increase size of "sub map links" (hide pins, permalink, etc) #2003 diff --git a/perllib/Open311/GetServiceRequests.pm b/perllib/Open311/GetServiceRequests.pm index 2a82c64a1..df96df91e 100644 --- a/perllib/Open311/GetServiceRequests.pm +++ b/perllib/Open311/GetServiceRequests.pm @@ -11,6 +11,7 @@ has start_date => ( is => 'ro', default => sub { undef } ); has end_date => ( is => 'ro', default => sub { undef } ); has verbose => ( is => 'ro', default => 0 ); has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } ); +has convert_latlong => ( is => 'rw', default => 0 ); sub fetch { my $self = shift; @@ -76,6 +77,10 @@ sub create_problems { if mySociety::Config::get('MAPIT_GENERATION'); my ($latitude, $longitude) = ( $request->{lat}, $request->{long} ); + + ($latitude, $longitude) = Utils::convert_en_to_latlon_truncated( $longitude, $latitude ) + if $self->convert_latlong; + my $all_areas = mySociety::MaPit::call( 'point', "4326/$longitude,$latitude", %params ); @@ -146,8 +151,8 @@ sub create_problems { state => $state, postcode => '', used_map => 1, - latitude => $request->{lat}, - longitude => $request->{long}, + latitude => $latitude, + longitude => $longitude, areas => ',' . $body->id . ',', bodies_str => $body->id, send_method_used => 'Open311', diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 8dd10c53d..1e94bb3e6 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -30,6 +30,7 @@ my @PLACES = ( [ '?', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ], [ 'OX20 1SZ', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ], [ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ], + [ 'BR1 3UH', 51.402096, 0.015784, 2482, 'Bromley Council', 'LBO' ], [ '?', 50.78301, -0.646929 ], [ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ], [ 'WS1 4NH', 52.563074, -1.991032, 2535, 'Sandwell Borough Council', 'MTD' ], diff --git a/t/open311/getservicerequests.t b/t/open311/getservicerequests.t index 878c178ef..6161ceac7 100644 --- a/t/open311/getservicerequests.t +++ b/t/open311/getservicerequests.t @@ -151,7 +151,6 @@ for my $test ( }; my $after_count = FixMyStreet::DB->resultset('Problem')->count; - warn $count; is $count, $after_count, "problems not created"; my $with_text = FixMyStreet::DB->resultset('Problem')->search( { @@ -258,6 +257,45 @@ for my $test ( }; } +for my $test ( + { + desc => 'convert easting/northing to lat/long', + subs => { lat => 168935, long => 540315 }, + expected => { lat => 51.402096, long => 0.015784 }, + }, +) { + subtest $test->{desc} => sub { + my $xml = prepare_xml( $test->{subs} ); + 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, + convert_latlong => 1, + ); + + 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->latitude, $test->{expected}->{lat}, 'correct latitude'; + is $p->longitude, $test->{expected}->{long}, 'correct longitude'; + + $p->delete; + }; +} + sub prepare_xml { my $replacements = shift; |