aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/SendReport/Email/TfL.pm23
-rw-r--r--t/app/sendreport/email/tfl.t32
2 files changed, 55 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email/TfL.pm b/perllib/FixMyStreet/SendReport/Email/TfL.pm
new file mode 100644
index 000000000..801489c62
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Email/TfL.pm
@@ -0,0 +1,23 @@
+package FixMyStreet::SendReport::Email::TfL;
+
+use Moo;
+extends 'FixMyStreet::SendReport::Email';
+
+sub build_recipient_list {
+ my ( $self, $row, $h ) = @_;
+
+ return unless @{$self->bodies} == 1;
+ my $body = $self->bodies->[0];
+
+ # We don't care what the category was, look up the Traffic lights contact
+ my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find({
+ body_id => $body->id,
+ category => 'Traffic lights',
+ });
+ return unless $contact;
+
+ @{$self->to} = map { [ $_, $body->name ] } split /,/, $contact->email;
+ return 1;
+}
+
+1;
diff --git a/t/app/sendreport/email/tfl.t b/t/app/sendreport/email/tfl.t
new file mode 100644
index 000000000..0322de551
--- /dev/null
+++ b/t/app/sendreport/email/tfl.t
@@ -0,0 +1,32 @@
+use FixMyStreet::SendReport::Email::TfL;
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $bromley = $mech->create_body_ok(2482, 'Bromley Council');
+my $tfl = $mech->create_body_ok(2482, 'TfL');
+
+$mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id, category => 'Graffiti');
+$mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id, category => 'Faulty street light');
+$mech->create_contact_ok(email => 'tfl@example.com', body_id => $tfl->id, category => 'Traffic lights');
+
+my $row = FixMyStreet::DB->resultset('Problem')->new( {
+ bodies_str => '1000',
+ category => 'Faulty street light',
+ cobrand => '',
+} );
+
+my $e = FixMyStreet::SendReport::Email::TfL->new;
+is $e->build_recipient_list($row), undef, 'no recipients if no body';
+
+$e = FixMyStreet::SendReport::Email::TfL->new;
+$e->add_body($bromley);
+is $e->build_recipient_list($row), undef, 'no recipients if category missing';
+
+$e = FixMyStreet::SendReport::Email::TfL->new;
+$e->add_body($tfl);
+is $e->build_recipient_list($row), 1, 'correct recipient list count';
+is_deeply $e->to, [ [ 'tfl@example.com', 'TfL' ] ], 'correct To line';
+
+done_testing();
+