From 808f4d7c18f2c3a1b776900820e604d896072499 Mon Sep 17 00:00:00 2001 From: M Somerville Date: Tue, 10 Nov 2020 14:53:48 +0000 Subject: [Highways England] Added test for config reading. --- perllib/FixMyStreet/SendReport/Email/Highways.pm | 7 ++++++- t/app/sendreport/email/highways.t | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/perllib/FixMyStreet/SendReport/Email/Highways.pm b/perllib/FixMyStreet/SendReport/Email/Highways.pm index 918ac896d..3ace07b6a 100644 --- a/perllib/FixMyStreet/SendReport/Email/Highways.pm +++ b/perllib/FixMyStreet/SendReport/Email/Highways.pm @@ -12,8 +12,13 @@ sub build_recipient_list { my $contact = $self->fetch_category($body, $row) or return; my $email = $contact->email; my $area_name = $row->get_extra_field_value('area_name') || ''; + + # config is read-only, so must step through one-by-one to prevent + # vivification my $area_email = FixMyStreet->config('COBRAND_FEATURES') || {}; - $area_email = $area_email->{open311_email}->{highwaysengland}->{$area_name}; + $area_email = $area_email->{open311_email} || {}; + $area_email = $area_email->{highwaysengland} || {}; + $area_email = $area_email->{$area_name}; $email = $area_email if $area_email; @{$self->to} = map { [ $_, $body->name ] } split /,/, $email; diff --git a/t/app/sendreport/email/highways.t b/t/app/sendreport/email/highways.t index 22913a7e6..6f6c65eb5 100644 --- a/t/app/sendreport/email/highways.t +++ b/t/app/sendreport/email/highways.t @@ -33,6 +33,14 @@ $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 => {} +}, 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, [ [ 'highways@example.com', 'Highways England' ] ], 'correct To line'; +}; + FixMyStreet::override_config { COBRAND_FEATURES => { open311_email => { highwaysengland => { 'Area 7' => 'a7@example.com' } } } }, sub { -- cgit v1.2.3