aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm4
-rw-r--r--perllib/FixMyStreet/SendReport/Zurich.pm2
-rw-r--r--t/cobrand/zurich.t26
3 files changed, 30 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 8bf0fc93a..dc4643673 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -217,10 +217,12 @@ sub categories_summary {
}
sub send_reports {
+ my ( $rs, $site_override ) = @_;
+
# Set up site, language etc.
my ($verbose, $nomail) = CronFns::options();
my $base_url = mySociety::Config::get('BASE_URL');
- my $site = CronFns::site($base_url);
+ my $site = $site_override || CronFns::site($base_url);
my $states = [ 'confirmed', 'fixed' ];
$states = [ 'unconfirmed', 'confirmed', 'in progress', 'planned', 'closed' ] if $site eq 'zurich';
diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm
index d700dcb15..e0c95283e 100644
--- a/perllib/FixMyStreet/SendReport/Zurich.pm
+++ b/perllib/FixMyStreet/SendReport/Zurich.pm
@@ -20,7 +20,7 @@ sub build_recipient_list {
body_id => $body->id,
category => $row->category
} );
- $body_email = $contact->email if $contact->email;
+ $body_email = $contact->email if $contact && $contact->email;
}
push @{ $self->to }, [ $body_email, $body->name ];
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index c7e11e37d..a6922a00d 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -22,9 +22,11 @@ $mech->content_like( qr/zurich/i );
my $zurich = $mech->create_body_ok( 1, 'Zurich' );
my $division = $mech->create_body_ok( 2, 'Division 1' );
$division->parent( $zurich->id );
+$division->endpoint( 'division@example.org' );
$division->update;
my $subdivision = $mech->create_body_ok( 3, 'Subdivision A' );
$subdivision->parent( $division->id );
+$subdivision->endpoint( 'subdivision@example.org' );
$subdivision->update;
my @reports = $mech->create_problems_for_body( 1, 2, 'Test', {
@@ -60,6 +62,7 @@ $mech->get_ok( '/report/' . $report->id );
$mech->content_contains('Aufgenommen');
$mech->content_contains('Test Test');
$mech->content_lacks('photo/' . $report->id . '.jpeg');
+$mech->email_count_is(0);
# Photo publishing
$mech->get_ok( '/admin/report_edit/' . $report->id );
@@ -84,6 +87,12 @@ $mech->get_ok( '/report/' . $report->id );
$mech->content_contains('In Bearbeitung');
$mech->content_contains('Test Test');
+FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+my $email = $mech->get_email;
+like $email->header('Subject'), qr/Neue Meldung/, 'subject looks okay';
+like $email->header('To'), qr/subdivision\@example.org/, 'to line looks correct';
+$mech->clear_emails_ok;
+
$mech->log_out_ok;
$user = $mech->log_in_ok( 'sdm1@example.org') ;
@@ -113,6 +122,12 @@ $mech->get_ok( '/report/' . $report->id );
$mech->content_contains('In Bearbeitung');
$mech->content_contains('Test Test');
+FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+$email = $mech->get_email;
+like $email->header('Subject'), qr/Feedback/, 'subject looks okay';
+like $email->header('To'), qr/division\@example.org/, 'to line looks correct';
+$mech->clear_emails_ok;
+
$report->discard_changes;
is $report->state, 'planned', 'Report now in planned state';
@@ -123,6 +138,12 @@ $mech->get_ok( '/admin' );
$mech->content_contains( 'report_edit/' . $report->id );
$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+# User confirms their email address
+my $extra = $report->extra;
+$extra->{email_confirmed} = 1;
+$report->extra ( { %$extra } );
+$report->update;
+
$mech->get_ok( '/admin/report_edit/' . $report->id );
$mech->submit_form_ok( { with_fields => { status_update => 'FINAL UPDATE' } } );
$mech->form_with_fields( 'status_update' );
@@ -133,6 +154,11 @@ $mech->content_contains('Erledigt');
$mech->content_contains('Test Test');
$mech->content_contains('FINAL UPDATE');
+$email = $mech->get_email;
+like $email->header('To'), qr/test\@example.com/, 'to line looks correct';
+like $email->body, qr/FINAL UPDATE/, 'body looks correct';
+$mech->clear_emails_ok;
+
$mech->delete_problems_for_body( 2 );
$mech->delete_user( 'dm1@example.org' );
$mech->delete_user( 'sdm1@example.org' );