aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model
diff options
context:
space:
mode:
authorDave Whiteland <dave@mysociety.org>2012-05-29 15:57:41 +0100
committerDave Whiteland <dave@mysociety.org>2012-05-29 15:57:41 +0100
commit67da8efc720d2d0bd22bd9fe8655b7e983b35bb4 (patch)
tree38b8570647124df06c637d4b923f6010211ef328 /t/app/model
parent40b3a51d33caefa8f5fb97ce9be18ef936c7e260 (diff)
parent131ff6e9bf3626d6a8fff6ae54669d250148a63a (diff)
Merge remote branch 'origin/master' into fmb-read-only
Conflicts: bin/send-reports perllib/FixMyStreet/Cobrand/Default.pm perllib/FixMyStreet/Cobrand/FixMyStreet.pm templates/web/fixmystreet/alert/index.html templates/web/fixmystreet/around/display_location.html web/cobrands/fixmystreet/_layout.scss web/js/map-OpenLayers.js
Diffstat (limited to 't/app/model')
-rw-r--r--t/app/model/problem.t130
1 files changed, 128 insertions, 2 deletions
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 638e89200..a7415851b 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -7,6 +7,7 @@ use Test::More;
use FixMyStreet;
use FixMyStreet::App;
+use FixMyStreet::TestMech;
use mySociety::Locale;
mySociety::Locale::gettext_domain('FixMyStreet');
@@ -16,8 +17,8 @@ my $problem_rs = FixMyStreet::App->model('DB::Problem');
my $problem = $problem_rs->new(
{
postcode => 'EH99 1SP',
- latitude => 1,
- longitude => 1,
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
areas => 1,
title => '',
detail => '',
@@ -345,6 +346,131 @@ for my $test (
};
}
+my $mech = FixMyStreet::TestMech->new();
+
+FixMyStreet::App->model('DB::Contact')->find_or_create(
+ {
+ area_id => 2651,
+ category => 'potholes',
+ email => 'test@example.org',
+ confirmed => 1,
+ deleted => 0,
+ editor => 'test',
+ whenedited => \'ms_current_timestamp()',
+ note => '',
+ }
+);
+
+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 $test->{ desc } => sub {
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
+
+ $problem->discard_changes;
+ $problem->update( {
+ council => $test->{ council },
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()',
+ category => 'potholes',
+ name => $test->{ name },
+ } );
+
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+
+ $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';
+ }
+ };
+}
+
$problem->comments->delete;
$problem->delete;
$user->delete;