aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model
diff options
context:
space:
mode:
Diffstat (limited to 't/app/model')
-rw-r--r--t/app/model/alert_type.t47
-rw-r--r--t/app/model/problem.t55
2 files changed, 83 insertions, 19 deletions
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index 7df4c44c0..c592e9d3f 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -22,6 +22,10 @@ my $user2 =
->find_or_create( { email => 'commenter@example.com', name => 'Commenter' } );
ok $user2, "created comment user";
+my $user3 =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'bystander@example.com', name => 'Bystander' } );
+ok $user3, "created bystander";
my $dt = DateTime->new(
year => 2011,
@@ -96,6 +100,16 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
}
);
+my $alert3 = FixMyStreet::App->model('DB::Alert')->find_or_create(
+ {
+ user => $user3,
+ parameter => $report_id,
+ alert_type => 'new_updates',
+ whensubscribed => $dt->ymd . ' ' . $dt->hms,
+ confirmed => 1,
+ }
+);
+
for my $test (
{
state => 'closed',
@@ -115,7 +129,7 @@ for my $test (
my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
{
- alert_id => $alert->id,
+ alert_id => [ $alert->id, $alert3->id ],
parameter => $comment->id,
}
)->delete;
@@ -125,18 +139,25 @@ for my $test (
FixMyStreet::App->model('DB::AlertType')->email_alerts();
- $mech->email_count_is( 1 );
- my $email = $mech->get_email;
+ $mech->email_count_is( 2 );
+ my @emails = $mech->get_email;
my $msg = $test->{msg};
- my $body = $email->body;
-
- like $body, qr/$msg/, 'email says problem is ' . $test->{state};
- like $body, qr{report/$report_id}, 'contains problem url';
- like $body, qr/This is some update text/, 'contains update text';
- unlike $body, qr/This is other update text/, 'does not contains other update text';
+ for my $email (@emails) {
+ my $body = $email->body;
+ my $to = $email->header('To');
+
+ like $body, qr/$msg/, 'email says problem is ' . $test->{state};
+ if ($to eq $user->email) {
+ like $body, qr{/M/}, 'contains problem login url';
+ } elsif ($to eq $user3->email) {
+ like $body, qr{/report/$report_id}, 'contains problem url';
+ }
+ like $body, qr/This is some update text/, 'contains update text';
+ unlike $body, qr/This is other update text/, 'does not contains other update text';
- my $comments = $body =~ s/(------)//gs;
- is $comments, 1, 'only 1 update';
+ my $comments = $body =~ s/(------)//gs;
+ is $comments, 1, 'only 1 update';
+ }
};
}
@@ -166,7 +187,6 @@ subtest "correct text for title after URL" => sub {
)->delete;
FixMyStreet::App->model('DB::AlertType')->email_alerts();
- $mech->email_count_is( 1 );
my $email = $mech->get_email;
(my $title = $report->title) =~ s/ /\\s+/;
my $body = $email->body;
@@ -300,7 +320,6 @@ foreach my $test (
FixMyStreet::App->model('DB::AlertType')->email_alerts();
- $mech->email_count_is( 1 );
my $email = $mech->get_email;
my $body = $email->body;
@@ -406,7 +425,6 @@ subtest "check alerts from cobrand send main site url for alerts for different c
FixMyStreet::App->model('DB::AlertType')->email_alerts();
- $mech->email_count_is( 1 );
my $email = $mech->get_email;
my $body = $email->body;
@@ -444,7 +462,6 @@ subtest "check local alerts from cobrand send main site url for alerts for diffe
FixMyStreet::App->model('DB::AlertType')->email_alerts();
- $mech->email_count_is( 1 );
my $email = $mech->get_email;
my $body = $email->body;
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index c3913b79e..040790184 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -511,6 +511,10 @@ foreach my $test ( {
},
) {
subtest $test->{ desc } => sub {
+ if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) {
+ plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand';
+ }
+
$mech->clear_emails_ok;
FixMyStreet::App->model('DB::Problem')->search(
@@ -519,10 +523,6 @@ foreach my $test ( {
}
)->update( { whensent => \'ms_current_timestamp()' } );
- if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) {
- plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand';
- }
-
$problem->discard_changes;
$problem->update( {
council => $test->{ council },
@@ -568,6 +568,53 @@ foreach my $test ( {
};
}
+subtest 'check can turn on report sent email alerts' => sub {
+ eval 'use Test::MockModule; 1' or
+ plan skip_all => 'Skipping tests that rely on Test::MockModule';
+
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
+
+ $problem->discard_changes;
+ $problem->update( {
+ council => 2651,
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ category => 'potholes',
+ name => 'Test User',
+ cobrand => 'fixmystreet',
+ } );
+
+ my $m = new Test::MockModule(
+ 'FixMyStreet::Cobrand::FixMyStreet' );
+ $m->mock( report_sent_confirmation_email => 1 );
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+
+ $mech->email_count_is( 2 );
+ my @emails = $mech->get_email;
+ my $email = $emails[0];
+
+ like $email->header('To'),qr/City of Edinburgh Council/, 'to line looks correct';
+ is $email->header('From'), '"Test User" <system_user@example.com>', '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, qr/Dear City of Edinburgh Council/, 'Salutation looks correct';
+
+ $problem->discard_changes;
+ ok defined( $problem->whensent ), 'whensent set';
+
+ $email = $emails[1];
+ like $email->header('Subject'), qr/Problem Report Sent/, 'report sent email title correct';
+ like $email->body, qr/Your report about/, 'report sent body correct';
+};
+
$problem->comments->delete;
$problem->delete;
$user->delete;