diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bexley.pm | 35 | ||||
-rw-r--r-- | t/cobrand/bexley.t | 18 |
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/; }; }; |