aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-06-12 16:27:56 +0100
committerMatthew Somerville <matthew@mysociety.org>2019-06-12 17:28:53 +0100
commitd9f2c5e76590d56e30a7e5fbaaa388e4addc46a3 (patch)
tree9b37d8d3892a58a678af1fa497474fed37784225
parente5b62794b376fd24a6010f14c0f1db146783b8a0 (diff)
[Bexley] Also send email for lighting reports.
-rw-r--r--perllib/FixMyStreet/Cobrand/Bexley.pm35
-rw-r--r--t/cobrand/bexley.t18
2 files changed, 44 insertions, 9 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm
index d398bb670..8720f42d8 100644
--- a/perllib/FixMyStreet/Cobrand/Bexley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bexley.pm
@@ -85,17 +85,34 @@ sub open311_post_send {
# Check Open311 was successful
return unless $row->external_id;
- return unless $row->category eq 'Abandoned and untaxed vehicles'
- || $row->category eq 'Dead animal';
-
- my $mb = FixMyStreet->config('STAGING_SITE') ? 'digital-team' : 'P1sfromContactCentre';
- my $e = join('@', $mb, $self->admin_user_domain);
- my $sender = FixMyStreet::SendReport::Email->new( to => [ [ $e, 'Bexley P1 email' ] ] );
-
if ($row->category eq 'Abandoned and untaxed vehicles') {
- my ($burnt) = grep { $_->{name} eq 'burnt' } @{$row->get_extra_fields};
- return unless $burnt && $burnt->{value} eq 'Yes';
+ my $burnt = $row->get_extra_field_value('burnt') || '';
+ return unless $burnt eq 'Yes';
+ }
+
+ my @lighting = (
+ 'Lamp post',
+ 'Light in multi-storey car park',
+ 'Light in outside car park',
+ 'Light in park or open space',
+ 'Traffic bollard',
+ 'Traffic sign light',
+ 'Underpass light',
+ 'Zebra crossing light',
+ );
+ my %lighting = map { $_ => 1 } @lighting;
+
+ my $emails = $self->feature('open311_email') || return;
+ my ($e, $n);
+ if ($row->category eq 'Abandoned and untaxed vehicles' || $row->category eq 'Dead animal') {
+ $e = $emails->{p1};
+ $n = 'Bexley P1 email';
+ } elsif ($lighting{$row->category}) {
+ $e = $emails->{lighting};
+ $n = 'FixMyStreet Bexley Street Lighting';
}
+ return unless $e;
+ my $sender = FixMyStreet::SendReport::Email->new( to => [ [ $e, $n ] ] );
$self->open311_config($row); # Populate NSGRef again if needed
diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t
index 2f74ac03a..f6ec1014d 100644
--- a/t/cobrand/bexley.t
+++ b/t/cobrand/bexley.t
@@ -30,11 +30,13 @@ my $mech = FixMyStreet::TestMech->new;
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");
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'bexley' ],
MAPIT_URL => 'http://mapit.uk/',
STAGING_FLAGS => { send_reports => 1, skip_checks => 0 },
+ COBRAND_FEATURES => { open311_email => { bexley => { p1 => 'p1@bexley', lighting => 'thirdparty@notbexley.example.com' } } },
}, sub {
subtest 'cobrand displays council name' => sub {
@@ -65,6 +67,22 @@ FixMyStreet::override_config {
my $email = $mech->get_email;
like $email->header('To'), qr/"Bexley P1 email".*bexley/;
like $mech->get_text_body_from_email($email), qr/NSG Ref: Road ID/;
+ $mech->clear_emails_ok;
+ };
+
+ ($report) = $mech->create_problems_for_body(1, $body->id, 'Lamp', {
+ category => 'Lamp post', cobrand => 'bexley',
+ latitude => 51.408484, longitude => 0.074653,
+ });
+
+ subtest 'Correct email sent' => sub {
+ my $test_data = FixMyStreet::Script::Reports::send();
+ my $req = $test_data->{test_req_used};
+ my $c = CGI::Simple->new($req->content);
+ is $c->param('service_code'), 'LAMP';
+
+ my $email = $mech->get_email;
+ like $email->header('To'), qr/thirdparty/;
};
};