Skip to content

Commit

Permalink
[National Highways] Per-area destination handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Aug 23, 2024
1 parent f573cf6 commit 17f9a78
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 17f9a78

Please sign in to comment.