aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-03-18 14:15:51 +0000
committerStruan Donald <struan@exo.org.uk>2020-03-31 09:58:58 +0100
commit4e6b347c276d772fa31290955355d5fb8e974300 (patch)
treeaac50e9fbc212b1995685624b05b1c0d91d66da0
parentac6eb28d588eeac702f9f1a6806c6939b1d67fb3 (diff)
[Highways England] Update report sending handling.
Use normal contact email, with special override in Area 7.
-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();