Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[National Highways] Per-area destination handling. #5134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions perllib/FixMyStreet/Cobrand/HighwaysEngland.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use strict;
use warnings;
use utf8;
use DateTime;
use Moo;

with 'FixMyStreet::Roles::BoroughEmails';

sub council_name { 'National Highways' }

Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion t/cobrand/highwaysengland.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,22 @@ 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 => '[email protected]', 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' ],
MAPIT_URL => 'http://mapit.uk/',
CONTACT_EMAIL => '[email protected]',
COBRAND_FEATURES => {
contact_email => { highwaysengland => '[email protected]' },
borough_email_addresses => {
highwaysengland => {
'testareaemail@nh' => [ {
'areas' => [ 'Area 1' ],
'email' => '[email protected]',
} ],
},
},
updates_allowed => {
highwaysengland => 'open',
},
Expand Down Expand Up @@ -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" <[email protected]>';
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';
Expand Down
Loading