diff --git a/perllib/FixMyStreet/Cobrand/HighwaysEngland.pm b/perllib/FixMyStreet/Cobrand/HighwaysEngland.pm index 48468fa77b..930e40b3fb 100644 --- a/perllib/FixMyStreet/Cobrand/HighwaysEngland.pm +++ b/perllib/FixMyStreet/Cobrand/HighwaysEngland.pm @@ -5,6 +5,9 @@ use strict; use warnings; use utf8; use DateTime; +use Moo; + +with 'FixMyStreet::Roles::BoroughEmails'; sub council_name { 'National Highways' } @@ -194,6 +197,23 @@ sub _redact { return $s; } +=head2 munge_sendreport_params + +We are directing reports based upon the stored NH area name, not the usual +MapIt areas, so update the row's areas to that for BoroughEmails to handle. + +=cut + +around 'munge_sendreport_params' => sub { + my ($orig, $self, $row, $h, $params) = @_; + + my $area = $row->get_extra_field_value('area_name') || '_fallback'; + my $original_areas = $row->areas; + $row->areas($area); + $self->$orig($row, $h, $params); + $row->areas($original_areas); +}; + sub munge_report_new_bodies { my ($self, $bodies) = @_; # On the cobrand there is only the HE body diff --git a/t/cobrand/highwaysengland.t b/t/cobrand/highwaysengland.t index 8fea5a3025..c9b6ef4fe2 100644 --- a/t/cobrand/highwaysengland.t +++ b/t/cobrand/highwaysengland.t @@ -45,7 +45,7 @@ ok $r->{error}, "searching for lowecase road only generates error"; my $mech = FixMyStreet::TestMech->new; my $highways = $mech->create_body_ok(164186, 'National Highways', { send_method => 'Email::Highways' }, { cobrand => 'highwaysengland' }); -$mech->create_contact_ok(email => 'highways@example.com', body_id => $highways->id, category => 'Pothole (NH)'); +$mech->create_contact_ok(email => 'testareaemail@nh', body_id => $highways->id, category => 'Pothole (NH)'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'highwaysengland', 'fixmystreet' ], @@ -53,6 +53,14 @@ FixMyStreet::override_config { CONTACT_EMAIL => 'fixmystreet@example.org', COBRAND_FEATURES => { contact_email => { highwaysengland => 'highwaysengland@example.org' }, + borough_email_addresses => { + highwaysengland => { + 'testareaemail@nh' => [ { + 'areas' => [ 'Area 1' ], + 'email' => 'area1email@example.org', + } ], + }, + }, updates_allowed => { highwaysengland => 'open', }, @@ -87,6 +95,7 @@ FixMyStreet::override_config { FixMyStreet::Script::Reports::send(); $mech->email_count_is(1); my $email = $mech->get_email; + is $email->header('To'), '"National Highways" '; my $body = $mech->get_text_body_from_email($email); like $body, qr/Heard from: Facebook/, 'where hear included in email'; like $body, qr/Road: M1/, 'road data included in email';