aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model/problem.t
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-02-27 19:03:25 +0000
committerStruan Donald <struan@exo.org.uk>2012-02-27 19:03:25 +0000
commit65066d275557e16448aa99ecdfa4df62d4d79649 (patch)
treec836ad08ac5fc88f2b6339bad56c7274b931b0e8 /t/app/model/problem.t
parent21b82d30b9348c3de50f711d8b7c80bcdaf2c756 (diff)
more tests for email sending
Diffstat (limited to 't/app/model/problem.t')
-rw-r--r--t/app/model/problem.t97
1 files changed, 89 insertions, 8 deletions
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 1b80f00ea..57066edb3 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -350,7 +350,7 @@ my $mech = FixMyStreet::TestMech->new();
FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 2663,
+ area_id => 2651,
category => 'potholes',
email => 'test@example.org',
confirmed => 1,
@@ -361,10 +361,74 @@ FixMyStreet::App->model('DB::Contact')->find_or_create(
}
);
-foreach my $test ( {
+FixMyStreet::App->model('DB::Contact')->find_or_create(
+ {
+ area_id => 2226,
+ category => 'potholes',
+ email => '2226@example.org',
+ confirmed => 1,
+ deleted => 0,
+ editor => 'test',
+ whenedited => \'ms_current_timestamp()',
+ note => '',
+ }
+);
+
+FixMyStreet::App->model('DB::Contact')->find_or_create(
+ {
+ area_id => 2326,
+ category => 'potholes',
+ email => '2326@example.org',
+ confirmed => 1,
+ deleted => 0,
+ editor => 'test',
+ whenedited => \'ms_current_timestamp()',
+ note => '',
}
+);
+
+foreach my $test ( {
+ desc => 'sends an email',
+ unset_whendef => 1,
+ email_count => 1,
+ email => 'system_user@example.com',
+ name => 'Andrew Smith',
+ dear => qr'Dear City of Edinburgh Council',
+ to => qr'City of Edinburgh Council',
+ council => 2651,
+ },
+ {
+ desc => 'no email sent if no unsent problems',
+ unset_whendef => 0,
+ email_count => 0,
+ email => 'system_user@example.com',
+ name => 'Andrew Smith',
+ council => 2651,
+ },
+ {
+ desc => 'email to two tier council',
+ unset_whendef => 1,
+ email_count => 1,
+ email => 'system_user@example.com',
+ name => 'Andrew Smith',
+ to => qr'Gloucestershire County Council.*Cheltenham Borough Council',
+ dear => qr'Dear Gloucestershire County Council and Cheltenham Borough',
+ council => '2226,2326',
+ multiple => 1,
+ },
+ {
+ desc => 'email to two tier council with one missing details',
+ unset_whendef => 1,
+ email_count => 1,
+ email => 'system_user@example.com',
+ name => 'Andrew Smith',
+ to => qr'Gloucestershire County Council',
+ dear => qr'Dear Gloucestershire County Council,',
+ council => '2226|2649',
+ missing => qr'problem might be the responsibility of Fife.*Council'ms,
+ },
) {
- subtest "sending report" => sub {
+ subtest $test->{ desc } => sub {
$mech->clear_emails_ok;
FixMyStreet::App->model('DB::Problem')->search(
@@ -375,18 +439,35 @@ foreach my $test ( {
$problem->discard_changes;
$problem->update( {
- council => 2663,
+ council => $test->{ council },
state => 'confirmed',
confirmed => \'ms_current_timestamp()',
- whensent => undef,
+ whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()',
category => 'potholes',
+ name => $test->{ name },
} );
FixMyStreet::App->model('DB::Problem')->send_reports();
- $mech->email_count_is( 1 );
- my $email = $mech->get_email;
- like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
+ $mech->email_count_is( $test->{ email_count } );
+ if ( $test->{ email_count } ) {
+ my $email = $mech->get_email;
+ like $email->header('To'), $test->{ to }, 'to line looks correct';
+ is $email->header('From'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'from line looks correct';
+ like $email->header('Subject'), qr/A Title/, 'subject line looks correct';
+ like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
+ like $email->body, qr/Subject: A Title/, 'more email body checking';
+ like $email->body, $test->{ dear }, 'Salutation looks correct';
+
+ if ( $test->{multiple} ) {
+ like $email->body, qr/This email has been sent to several councils /, 'multiple council text correct';
+ } elsif ( $test->{ missing } ) {
+ like $email->body, $test->{ missing }, 'missing council information correct';
+ }
+
+ $problem->discard_changes;
+ ok defined( $problem->whensent ), 'whensent set';
+ }
};
}