aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/alert_new.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/alert_new.t')
-rw-r--r--t/app/controller/alert_new.t131
1 files changed, 123 insertions, 8 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 594d4c7a6..14cf32d7c 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -12,7 +12,7 @@ foreach my $test (
email => 'test@example.com',
type => 'area_problems',
content => 'your alert will not be activated',
- email_text => 'confirm the alert',
+ email_text => "confirms that you'd like to receive an email",
uri =>
'/alert/subscribe?type=local&rznvy=test@example.com&feed=area:1000:A_Location',
param1 => 1000
@@ -21,7 +21,7 @@ foreach my $test (
email => 'test@example.com',
type => 'council_problems',
content => 'your alert will not be activated',
- email_text => 'confirm the alert',
+ email_text => "confirms that you'd like to receive an email",
uri =>
'/alert/subscribe?type=local&rznvy=test@example.com&feed=council:1000:A_Location',
param1 => 1000,
@@ -31,7 +31,7 @@ foreach my $test (
email => 'test@example.com',
type => 'ward_problems',
content => 'your alert will not be activated',
- email_text => 'confirm the alert',
+ email_text => "confirms that you'd like to receive an email",
uri =>
'/alert/subscribe?type=local&rznvy=test@example.com&feed=ward:1000:1001:A_Location:Diff_Location',
param1 => 1000,
@@ -41,7 +41,7 @@ foreach my $test (
email => 'test@example.com',
type => 'local_problems',
content => 'your alert will not be activated',
- email_text => 'confirm the alert',
+ email_text => "confirms that you'd like to receive an email",
uri =>
'/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1',
param1 => 20.1,
@@ -51,7 +51,7 @@ foreach my $test (
email => 'test@example.com',
type => 'new_updates',
content => 'your alert will not be activated',
- email_text => 'confirm the alert',
+ email_text => "confirms that you'd like to receive an email",
uri => '/alert/subscribe?type=updates&rznvy=test@example.com&id=1',
param1 => 1,
}
@@ -450,9 +450,9 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
my @emails = $mech->get_email;
my $count;
for (@emails) {
- $count++ if $_->body =~ /The following updates have been left on this problem:/;
- $count++ if $_->body =~ /The following new problems have been reported to City of\s+Edinburgh\s+Council:/;
- $count++ if $_->body =~ /The following nearby problems have been added:/;
+ $count++ if $_->body =~ /The following updates have been left on this report:/;
+ $count++ if $_->body =~ /The following new FixMyStreet reports have been sent to City of\s+Edinburgh\s+Council:/;
+ $count++ if $_->body =~ /The following FixMyStreet reports have been made within the area you\s+specified:/;
$count++ if $_->body =~ /\s+-\s+Testing/;
}
is $count, 5, 'Three emails, with five matching lines in them';
@@ -479,6 +479,121 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
$mech->delete_user($user2);
};
+subtest "Test signature template is used from cobrand" => sub {
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
+ my $user1 = FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } );
+ ok $user1, "created test user";
+
+ my $user2 = FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } );
+ ok $user2, "created test user";
+
+ my $dt = DateTime->now()->add( days => 2);
+
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
+ my $report_time = '2011-03-01 12:00:00';
+ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
+ postcode => 'EH1 1BB',
+ bodies_str => '2651',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user1->name,
+ anonymous => 0,
+ state => 'fixed - user',
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user1->id,
+ } );
+ my $report_id = $report->id;
+ ok $report, "created test report - $report_id";
+
+ my $alert = FixMyStreet::App->model('DB::Alert')->create( {
+ parameter => $report_id,
+ alert_type => 'new_updates',
+ user => $user1,
+ cobrand => 'default',
+ } );
+ my $ret = $alert->confirm;
+ ok $ret, 'created alert for reporter';
+
+ my $update = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report_id,
+ user_id => $user2->id,
+ name => 'Other User',
+ mark_fixed => 'false',
+ text => 'This is some update text',
+ state => 'confirmed',
+ confirmed => $dt->clone->add( hours => 7 ),
+ anonymous => 'f',
+ } );
+ my $update_id = $update->id;
+ ok $update, "created test update - $update_id";
+
+
+ $mech->clear_emails_ok;
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ }, sub {
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ };
+ # TODO Note the below will fail if the db has an existing alert that matches
+ $mech->email_count_is(1);
+
+ my @emails = $mech->get_email;
+ my $email = $emails[0];
+ like $email->body, qr/All the best/, 'default signature used';
+ unlike $email->body, qr/twitter.com/, 'nothing from fixmystreet signature';
+
+ $update = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report_id,
+ user_id => $user2->id,
+ name => 'Anonymous User',
+ mark_fixed => 'true',
+ text => 'This is some more update text',
+ state => 'confirmed',
+ confirmed => $dt->clone->add( hours => 8 ),
+ anonymous => 't',
+ } );
+ $update_id = $update->id;
+ ok $update, "created test update - $update_id";
+
+ $alert->cobrand('fixmystreet');
+ $alert->update;
+
+ $mech->clear_emails_ok;
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ }, sub {
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ };
+ # TODO Note the below will fail if the db has an existing alert that matches
+ $mech->email_count_is(1);
+
+ @emails = $mech->get_email;
+ $email = $emails[0];
+ like $email->body, qr/twitter.com/, 'fixmystreet signature used';
+
+ $mech->delete_user($user1);
+ $mech->delete_user($user2);
+};
+
for my $test (
{
desc => 'check non public reports are not included in council problems alerts',