aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/SendReport/Email/Highways.pm24
-rw-r--r--t/app/sendreport/email/highways.t12
2 files changed, 31 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email/Highways.pm b/perllib/FixMyStreet/SendReport/Email/Highways.pm
index 2a1f7b305..2bcd120d3 100644
--- a/perllib/FixMyStreet/SendReport/Email/Highways.pm
+++ b/perllib/FixMyStreet/SendReport/Email/Highways.pm
@@ -1,11 +1,25 @@
package FixMyStreet::SendReport::Email::Highways;
use Moo;
-extends 'FixMyStreet::SendReport::Email::SingleBodyOnly';
+extends 'FixMyStreet::SendReport::Email';
-has contact => (
- is => 'ro',
- default => 'Pothole'
-);
+sub build_recipient_list {
+ my ( $self, $row, $h ) = @_;
+
+ return unless @{$self->bodies} == 1;
+ my $body = $self->bodies->[0];
+
+ my $contact = $self->fetch_category($body, $row) or return;
+ my $email = $contact->email;
+ my $area_name = $row->get_extra_field_value('area_name') || '';
+ if ($area_name eq 'Area 7') {
+ my $a7email = FixMyStreet->config('COBRAND_FEATURES') || {};
+ $a7email = $a7email->{open311_email}->{highwaysengland}->{area_seven};
+ $email = $a7email if $a7email;
+ }
+
+ @{$self->to} = map { [ $_, $body->name ] } split /,/, $email;
+ return 1;
+}
1;
diff --git a/t/app/sendreport/email/highways.t b/t/app/sendreport/email/highways.t
index 452dda822..b9a71f23f 100644
--- a/t/app/sendreport/email/highways.t
+++ b/t/app/sendreport/email/highways.t
@@ -29,5 +29,17 @@ $e->add_body($highways);
is $e->build_recipient_list($row), 1, 'correct recipient list count';
is_deeply $e->to, [ [ 'highways@example.com', 'Highways England' ] ], 'correct To line';
+$row->set_extra_fields( { name => 'area_name', value => 'Area 6' } );
+is $e->build_recipient_list($row), 1, 'correct recipient list count';
+is_deeply $e->to, [ [ 'highways@example.com', 'Highways England' ] ], 'correct To line';
+
+FixMyStreet::override_config {
+ COBRAND_FEATURES => { open311_email => { highwaysengland => { area_seven => 'a7@example.com' } } }
+}, sub {
+ $row->set_extra_fields( { name => 'area_name', value => 'Area 7' } );
+ is $e->build_recipient_list($row), 1, 'correct recipient list count';
+ is_deeply $e->to, [ [ 'a7@example.com', 'Highways England' ] ], 'correct To line';
+};
+
done_testing();