aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-10-12 18:00:44 +0100
committerMatthew Somerville <matthew@mysociety.org>2012-10-12 18:00:50 +0100
commit9606353b3d3fb3be9e6b1d25dda154a7fdc33b10 (patch)
tree7f1dc9295198d183af63e87852e8cb60b6614512 /t/app/model
parentc4bc439991b5edbe4b177c07d7e9f99bbffb34e1 (diff)
If update alert email is to problem reporter, make it a login link.
This is so they can more easily update, especially if the update they've just received has mistakingly 'fixed' the report. This fixes #7.
Diffstat (limited to 't/app/model')
-rw-r--r--t/app/model/alert_type.t47
1 files changed, 32 insertions, 15 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;