aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm16
-rw-r--r--perllib/Open311.pm22
-rw-r--r--t/open311.t122
3 files changed, 139 insertions, 21 deletions
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index 17492624d..fe99e3043 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -30,6 +30,10 @@ sub send {
foreach my $council ( keys %{ $self->councils } ) {
my $conf = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first;
+ my $always_send_latlong = 1;
+
+ my $basic_desc = 0;
+
# Extra bromley fields
if ( $row->council =~ /2482/ ) {
@@ -44,6 +48,10 @@ sub send {
push @$extra, { name => 'requested_datetime', value => DateTime::Format::W3CDTF->format_datetime($row->confirmed_local->set_nanosecond(0)) };
push @$extra, { name => 'email', value => $row->user->email };
$row->extra( $extra );
+
+ $always_send_latlong = 0;
+
+ $basic_desc = 1;
}
# FIXME: we've already looked this up before
@@ -54,9 +62,11 @@ sub send {
} );
my $open311 = Open311->new(
- jurisdiction => $conf->jurisdiction,
- endpoint => $conf->endpoint,
- api_key => $conf->api_key,
+ jurisdiction => $conf->jurisdiction,
+ endpoint => $conf->endpoint,
+ api_key => $conf->api_key,
+ always_send_latlong => $always_send_latlong,
+ basic_description => $basic_desc,
);
# non standard west berks end points
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index d97b61f90..b380409cf 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -20,6 +20,8 @@ has debug => ( is => 'ro', isa => 'Bool', default => 0 );
has debug_details => ( is => 'rw', 'isa' => 'Str', default => '' );
has success => ( is => 'rw', 'isa' => 'Bool', default => 0 );
has error => ( is => 'rw', 'isa' => 'Str', default => '' );
+has always_send_latlong => ( is => 'ro', isa => 'Bool', default => 1 );
+has basic_description => ( is => 'ro', isa => 'Bool', default => 0 );
before [
qw/get_service_list get_service_meta_info get_service_requests get_service_request_updates
@@ -81,15 +83,18 @@ sub _populate_service_request_params {
my $extra = shift;
my $service_code = shift;
- my $description = $self->_generate_service_request_description(
- $problem, $extra
- );
+ my $description;
+ if ( $self->basic_description ) {
+ $description = $problem->detail;
+ } else {
+ $description = $self->_generate_service_request_description(
+ $problem, $extra
+ );
+ }
my ( $firstname, $lastname ) = ( $problem->user->name =~ /(\w+)\s+(.+)/ );
my $params = {
- lat => $problem->latitude,
- long => $problem->longitude,
email => $problem->user->email,
description => $description,
service_code => $service_code,
@@ -97,6 +102,13 @@ sub _populate_service_request_params {
last_name => $lastname || '',
};
+ if ( $problem->used_map || $self->always_send_latlong ) {
+ $params->{lat} = $problem->latitude;
+ $params->{long} = $problem->longitude;
+ } else {
+ $params->{address} = $problem->postcode;
+ }
+
if ( $problem->user->phone ) {
$params->{ phone } = $problem->user->phone;
}
diff --git a/t/open311.t b/t/open311.t
index a507241a7..d6a5ef6f6 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -91,10 +91,32 @@ EOT
is $c->param('last_name'), 'User', 'correct last name';
is $c->param('lat'), 1, 'latitide correct';
is $c->param('long'), 2, 'longitude correct';
- is $c->param('description'), $description, 'descritpion correct';
+ is $c->param('description'), $description, 'description correct';
is $c->param('service_code'), 'pothole', 'service code correct';
};
+subtest 'posting service request with basic_description' => sub {
+ my $extra = {
+ url => 'http://example.com/report/1',
+ };
+
+ my $results = make_service_req(
+ $problem,
+ $extra,
+ $problem->category,
+ '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>',
+ { basic_description => 1 },
+ );
+
+ is $results->{ res }, 248, 'got request id';
+
+ my $req = $o->test_req_used;
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+
+ is $c->param('description'), $problem->detail, 'description correct';
+};
+
for my $test (
{
desc => 'extra values in service request',
@@ -299,6 +321,58 @@ for my $test (
};
}
+for my $test (
+ {
+ desc => 'use lat long forces lat long even if map not used',
+ use_latlong => 1,
+ postcode => 'EH99 1SP',
+ used_map => 0,
+ includes_latlong => 1,
+ },
+ {
+ desc => 'no use lat long and no map sends address instead of lat long',
+ use_latlong => 0,
+ postcode => 'EH99 1SP',
+ used_map => 0,
+ includes_latlong => 0,
+ },
+ {
+ desc => 'no use lat long but used map sends lat long',
+ use_latlong => 0,
+ postcode => 'EH99 1SP',
+ used_map => 1,
+ includes_latlong => 1,
+ }
+) {
+ subtest $test->{desc} => sub {
+ my $extra = { url => 'http://example.com/report/1', };
+ $problem->used_map( $test->{used_map} );
+ $problem->postcode( $test->{postcode} );
+
+ my $results = make_service_req(
+ $problem,
+ $extra,
+ $problem->category,
+ '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>',
+ { always_send_latlong => $test->{use_latlong} },
+ );
+
+ is $results->{ res }, 248, 'got request id';
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+
+ if ( $test->{includes_latlong} ) {
+ ok $c->param('lat'), 'has latitude';
+ ok $c->param('long'), 'has longitude';
+ is $c->param('address'), undef, 'no address';
+ } else {
+ is $c->param('lat'), undef, 'no latitude';
+ is $c->param('long'), undef, 'no latitude';
+ is $c->param('address'), $test->{postcode}, 'has address';
+ }
+ };
+}
+
subtest 'No update id in reponse' => sub {
my $results;
warning_like {
@@ -323,27 +397,49 @@ sub make_update_req {
my $comment = shift;
my $xml = shift;
- return make_req( $comment, $xml, 'post_service_request_update', 'update.xml' );
+ return make_req(
+ {
+ object => $comment,
+ xml => $xml,
+ method => 'post_service_request_update',
+ path => 'update.xml',
+ }
+ );
}
sub make_service_req {
- my $problem = shift;
- my $extra = shift;
+ my $problem = shift;
+ my $extra = shift;
my $service_code = shift;
- my $xml = shift;
-
- return make_req( $problem, $xml, 'send_service_request', 'requests.xml', $extra, $service_code );
+ my $xml = shift;
+ my $open311_args = shift || {};
+
+ return make_req(
+ {
+ object => $problem,
+ xml => $xml,
+ method => 'send_service_request',
+ path => 'requests.xml',
+ method_args => [ $extra, $service_code ],
+ open311_conf => $open311_args,
+ }
+ );
}
sub make_req {
- my $object = shift;
- my $xml = shift;
- my $method = shift;
- my $path = shift;
- my @args = @_;
+ my $args = shift;
+
+ my $object = $args->{object};
+ my $xml = $args->{xml};
+ my $method = $args->{method};
+ my $path = $args->{path};
+ my %open311_conf = %{ $args->{open311_conf} || {} };
+ my @args = @{ $args->{method_args} || [] };
+ $open311_conf{'test_mode'} = 1;
+ $open311_conf{'end_point'} = 'http://localhost/o311';
my $o =
- Open311->new( test_mode => 1, end_point => 'http://localhost/o311' );
+ Open311->new( %open311_conf );
my $test_res = HTTP::Response->new();
$test_res->code(200);