aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2020-01-23 16:01:57 +0000
committerM Somerville <matthew-github@dracos.co.uk>2020-08-10 17:43:11 +0100
commita86acd036ad52a15ee3cf546f7f496f212be3cf5 (patch)
tree1e6fac8e309ec9c4c03b95dfef4d4b22edfd4e57
parent2b6d5e5dac59b6a8a9af89cc4a51a9c3dff7fee8 (diff)
[Oxfordshire] include asset id in open311 description
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/Oxfordshire.pm17
-rwxr-xr-xperllib/Open311/PostServiceRequestUpdates.pm2
-rw-r--r--t/cobrand/oxfordshire.t47
4 files changed, 67 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index e63d722fd..90e5895d5 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -232,6 +232,11 @@ sub open311_pre_send {
}
}
+sub open311_pre_send_updates {
+ my ($self, $row) = @_;
+ return $self->open311_pre_send($row);
+}
+
sub open311_munge_update_params {
my ($self, $params, $comment, $body) = @_;
delete $params->{update_id};
diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm
index 31db0fd4e..cf88495f8 100644
--- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm
@@ -138,6 +138,23 @@ sub open311_config_updates {
$params->{use_customer_reference} = 1;
}
+sub open311_pre_send {
+ my ($self, $row, $open311) = @_;
+
+ $self->{ox_original_detail} = $row->detail;
+
+ if (my $fid = $row->get_extra_field_value('feature_id')) {
+ my $text = $row->detail . "\n\nAsset Id: $fid\n";
+ $row->detail($text);
+ }
+}
+
+sub open311_post_send {
+ my ($self, $row, $h, $contact) = @_;
+
+ $row->detail($self->{ox_original_detail});
+}
+
sub should_skip_sending_update {
my ($self, $update ) = @_;
diff --git a/perllib/Open311/PostServiceRequestUpdates.pm b/perllib/Open311/PostServiceRequestUpdates.pm
index a31bca8f7..b9aa9ed50 100755
--- a/perllib/Open311/PostServiceRequestUpdates.pm
+++ b/perllib/Open311/PostServiceRequestUpdates.pm
@@ -126,7 +126,7 @@ sub process_update {
my $o = $self->construct_open311($body, $comment);
- $cobrand->call_hook(open311_pre_send => $comment, $o);
+ $cobrand->call_hook(open311_pre_send_updates => $comment);
my $id = $o->post_service_request_update( $comment );
diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t
index 65c6a3864..16b7e5714 100644
--- a/t/cobrand/oxfordshire.t
+++ b/t/cobrand/oxfordshire.t
@@ -1,7 +1,9 @@
use Test::MockModule;
+use CGI::Simple;
use FixMyStreet::TestMech;
use FixMyStreet::Script::Alerts;
+use FixMyStreet::Script::Reports;
my $mech = FixMyStreet::TestMech->new;
my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council');
@@ -50,6 +52,7 @@ subtest 'check /around?ajax defaults to open reports only' => sub {
my @problems = FixMyStreet::DB->resultset('Problem')->search({}, { rows => 3, order_by => 'id' })->all;
FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1, skip_checks => 1 },
ALLOWED_COBRANDS => 'oxfordshire',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
@@ -63,10 +66,10 @@ FixMyStreet::override_config {
is $mech->uri->path, '/report/' . $problem->id, 'redirects to report';
};
- subtest 'check unable to fix label' => sub {
- my $user = $mech->create_user_ok( 'user@example.com', name => 'Test User' );
- my $user2 = $mech->create_user_ok( 'user2@example.com', name => 'Test User2' );
+ my $user = $mech->create_user_ok( 'user@example.com', name => 'Test User' );
+ my $user2 = $mech->create_user_ok( 'user2@example.com', name => 'Test User2' );
+ subtest 'check unable to fix label' => sub {
my $problem = $problems[0];
$problem->state( 'unable to fix' );
$problem->update;
@@ -128,6 +131,44 @@ FixMyStreet::override_config {
is $rows[2]->[20], '', 'Report without HIAMS ref has empty ref field';
is $rows[3]->[20], '123098123', 'Older Exor report has correct ref';
};
+
+ $oxon->update({
+ send_method => 'Open311',
+ endpoint => 'endpoint',
+ api_key => 'key',
+ jurisdiction => 'home',
+ });
+ my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Gullies and Catchpits', email => 'GC' );
+ $contact->set_extra_fields( (
+ { code => 'feature_id', datatype => 'hidden', variable => 'true' },
+ ) );
+ $contact->update;
+ FixMyStreet::Script::Reports::send(); # Make sure no waiting reports
+
+ subtest 'Check special Open311 request handling', sub {
+ my ($p) = $mech->create_problems_for_body( 1, $oxon->id, 'Test', {
+ cobrand => 'oxfordshire',
+ category => 'Gullies and Catchpits',
+ user => $user,
+ latitude => 51.754926,
+ longitude => -1.256179,
+ });
+ $p->set_extra_fields({ name => 'feature_id', value => 9875432});
+ $p->update;
+
+ my $test_data = FixMyStreet::Script::Reports::send();
+
+ $p->discard_changes;
+ ok $p->whensent, 'Report marked as sent';
+ is $p->send_method_used, 'Open311', 'Report sent via Open311';
+ is $p->external_id, 248, 'Report has right external ID';
+ unlike $p->detail, qr/Asset Id:/, 'asset id not saved to report detail';
+
+ my $req = $test_data->{test_req_used};
+ my $c = CGI::Simple->new($req->content);
+ like $c->param('description'), qr/Asset Id: 9875432/, 'asset id included in body';
+ };
+
};
done_testing();