diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-10-11 15:23:40 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-11-13 11:58:51 +0000 |
commit | a313421307a99d6859d66eec58336157aed4d1fb (patch) | |
tree | d75aec5fe34b5c6313f3ab146c1eb86da26b95cf | |
parent | 22e2e4446feea4074e80990176d6f41344f2411a (diff) |
[Bexley] Provide Confirm parameters required.
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bexley.pm | 37 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 8 | ||||
-rw-r--r-- | t/cobrand/bexley.t | 46 |
3 files changed, 71 insertions, 20 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm index 1a303d633..eda276add 100644 --- a/perllib/FixMyStreet/Cobrand/Bexley.pm +++ b/perllib/FixMyStreet/Cobrand/Bexley.pm @@ -58,16 +58,35 @@ sub lookup_site_code_config { } sub open311_config { - my ($self, $row, $h, $params) = @_; + my ($self, $row, $h, $params, $contact) = @_; + + $params->{multi_photos} = 1; my $extra = $row->get_extra_fields; - # Reports made via the app probably won't have a NSGRef because we don't - # display the road layer. Instead we'll look up the closest asset from the - # WFS service at the point we're sending the report over Open311. - if (!$row->get_extra_field_value('NSGRef')) { - if (my $ref = $self->lookup_site_code($row)) { - push @$extra, { name => 'NSGRef', description => 'NSG Ref', value => $ref }; + if ($contact->email =~ /^Confirm/) { + push @$extra, + { name => 'report_url', description => 'Report URL', + value => $h->{url} }, + { name => 'title', description => 'Title', + value => $row->title }, + { name => 'description', description => 'Detail', + value => $row->detail }; + + if (!$row->get_extra_field_value('site_code')) { + if (my $ref = $self->lookup_site_code($row)) { + push @$extra, { name => 'site_code', value => $ref, description => 'Site code' }; + } + } + } elsif ($contact->email =~ /^Uniform/) { + } else { # Symology + # Reports made via the app probably won't have a NSGRef because we don't + # display the road layer. Instead we'll look up the closest asset from the + # WFS service at the point we're sending the report over Open311. + if (!$row->get_extra_field_value('NSGRef')) { + if (my $ref = $self->lookup_site_code($row)) { + push @$extra, { name => 'NSGRef', description => 'NSG Ref', value => $ref }; + } } } @@ -77,7 +96,7 @@ sub open311_config { sub admin_user_domain { 'bexley.gov.uk' } sub open311_post_send { - my ($self, $row, $h) = @_; + my ($self, $row, $h, $contact) = @_; # Check Open311 was successful return unless $row->external_id; @@ -122,7 +141,7 @@ sub open311_post_send { return unless @to; my $sender = FixMyStreet::SendReport::Email->new( to => \@to ); - $self->open311_config($row); # Populate NSGRef again if needed + $self->open311_config($row, $h, {}, $contact); # Populate NSGRef again if needed my $extra_data = join "; ", map { "$_->{description}: $_->{value}" } @{$row->get_extra_fields}; $h->{additional_information} = $extra_data; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index fcb6f7298..c4532e3b3 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -34,11 +34,11 @@ sub send { fixmystreet_body => $body, ); - my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged; - $cobrand->call_hook(open311_config => $row, $h, \%open311_params); - my $contact = $self->fetch_category($body, $row) or next; + my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged; + $cobrand->call_hook(open311_config => $row, $h, \%open311_params, $contact); + # Try and fill in some ones that we've been asked for, but not asked the user for my $extra = $row->get_extra_fields(); @@ -94,7 +94,7 @@ sub send { $self->error( $self->error . "\n" . $open311->error ); } - $cobrand->call_hook(open311_post_send => $row, $h); + $cobrand->call_hook(open311_post_send => $row, $h, $contact); } diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t index 480f1ce2d..3cf71798e 100644 --- a/t/cobrand/bexley.t +++ b/t/cobrand/bexley.t @@ -34,7 +34,7 @@ my $body = $mech->create_body_ok(2494, 'London Borough of Bexley', { send_method => 'Open311', api_key => 'key', 'endpoint' => 'e', 'jurisdiction' => 'j' }); $mech->create_contact_ok(body_id => $body->id, category => 'Abandoned and untaxed vehicles', email => "ABAN"); $mech->create_contact_ok(body_id => $body->id, category => 'Lamp post', email => "LAMP"); -$mech->create_contact_ok(body_id => $body->id, category => 'Parks and open spaces', email => "PARK"); +$mech->create_contact_ok(body_id => $body->id, category => 'Parks and open spaces', email => "ConfirmPARK"); $mech->create_contact_ok(body_id => $body->id, category => 'Dead animal', email => "ANIM"); my $category = $mech->create_contact_ok(body_id => $body->id, category => 'Something dangerous', email => "DANG"); $category->set_extra_metadata(group => 'Danger things'); @@ -70,13 +70,13 @@ FixMyStreet::override_config { extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } }, { category => 'Something dangerous', code => 'DANG', extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'No' } }, - { category => 'Parks and open spaces', email => 1, code => 'PARK', + { category => 'Parks and open spaces', email => 1, code => 'ConfirmPARK', extra => { 'name' => 'reportType', description => 'Type of report', 'value' => 'Wild animal' } }, - { category => 'Parks and open spaces', code => 'PARK', + { category => 'Parks and open spaces', code => 'ConfirmPARK', extra => { 'name' => 'reportType', description => 'Type of report', 'value' => 'Maintenance' } }, - { category => 'Parks and open spaces', code => 'PARK', + { category => 'Parks and open spaces', code => 'ConfirmPARK', extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } }, - { category => 'Parks and open spaces', email => 1, code => 'PARK', + { category => 'Parks and open spaces', email => 1, code => 'ConfirmPARK', extra => [ { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' }, { 'name' => 'reportType', description => 'Type of report', 'value' => 'Vandalism' }, @@ -100,7 +100,11 @@ FixMyStreet::override_config { my $req = $test_data->{test_req_used}; my $c = CGI::Simple->new($req->content); is $c->param('service_code'), $test->{code}; - is $c->param('attribute[NSGRef]'), 'Road ID'; + if ($test->{code} =~ /Confirm/) { + is $c->param('attribute[site_code]'), 'Road ID'; + } else { + is $c->param('attribute[NSGRef]'), 'Road ID'; + } if (my $t = $test->{email}) { my $email = $mech->get_email; @@ -109,7 +113,11 @@ FixMyStreet::override_config { } else { like $email->header('To'), qr/$t/; } - like $mech->get_text_body_from_email($email), qr/NSG Ref: Road ID/; + if ($test->{code} =~ /Confirm/) { + like $mech->get_text_body_from_email($email), qr/Site code: Road ID/; + } else { + like $mech->get_text_body_from_email($email), qr/NSG Ref: Road ID/; + } $mech->clear_emails_ok; } else { $mech->email_count_is(0); @@ -131,6 +139,30 @@ FixMyStreet::override_config { $mech->content_contains('"Danger things","Something dangerous"'); }; + + subtest 'testing special Open311 behaviour', sub { + my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', { + category => 'Parks and open spaces', cobrand => 'bexley', + latitude => 51.408484, longitude => 0.074653, areas => '2494', + photo => '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg,74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg', + }); + my $report = $reports[0]; + + my $test_data = FixMyStreet::Script::Reports::send(); + $report->discard_changes; + ok $report->whensent, 'Report marked as sent'; + is $report->send_method_used, 'Open311', 'Report sent via Open311'; + is $report->external_id, 248, 'Report has right external ID'; + + my $req = $test_data->{test_req_used}; + my $c = CGI::Simple->new($req->content); + is $c->param('attribute[title]'), 'Test Test 1 for ' . $body->id, 'Request had correct title'; + is_deeply [ $c->param('media_url') ], [ + 'http://bexley.example.org/photo/' . $report->id . '.0.full.jpeg?74e33622', + 'http://bexley.example.org/photo/' . $report->id . '.1.full.jpeg?74e33622', + ], 'Request had multiple photos'; + }; + }; subtest 'nearest road returns correct road' => sub { |