From 64f97d4cf9ad64905006e504f3ffb47fb373eca9 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 Sep 2013 15:57:38 +0100 Subject: Test to check reports from abuse users not sent Reports that have been created by a user who is logged in but whose email is in the abuse table should be hidden and not sent by send_reports. --- t/app/model/problem.t | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 7daa653fc..5d02aef2b 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -630,6 +630,53 @@ subtest 'check can turn on report sent email alerts' => sub { like $email->body, qr/Your report about/, 'report sent body correct'; }; +subtest 'check reports from abuser not sent' => sub { + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + title => 'Report', + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'potholes', + send_fail_count => 0, + } ); + + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 1 ); + + $problem->discard_changes(); + ok $problem->whensent, 'Report has been sent'; + + $problem->update( { + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + } ); + + my $abuse = FixMyStreet::App->model('DB::Abuse')->create( { email => $problem->user->email } ); + + $mech->clear_emails_ok; + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 0 ); + + $problem->discard_changes(); + is $problem->state, 'hidden', 'reports from abuse user are hidden automatically'; + is $problem->whensent, undef, 'reports from abuse user are not sent'; + + ok $abuse->delete(), 'user removed from abuse table'; +}; + + $problem->comments->delete; $problem->delete; $mech->delete_user( $user ); -- cgit v1.2.3 From 30bb1746b703a12d7ec3c698eea63ac9e1183037 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 Sep 2013 15:59:27 +0100 Subject: mechanism to stop app store tests being sent In order to allow the iOS app to be tested in the app store we need to allow the user to create a report but we don't want to send it. To allow this hide reports with a specific title during send_reports --- t/app/model/problem.t | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 5d02aef2b..c9fa1a6e3 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -630,6 +630,35 @@ subtest 'check can turn on report sent email alerts' => sub { like $email->body, qr/Your report about/, 'report sent body correct'; }; + +subtest 'check iOS app store test reports not sent' => sub { + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + title => 'App store test', + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'potholes', + send_fail_count => 0, + } ); + + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 0 ); + + $problem->discard_changes(); + is $problem->state, 'hidden', 'iOS test reports are hidden automatically'; + is $problem->whensent, undef, 'iOS test reports are not sent'; +}; + subtest 'check reports from abuser not sent' => sub { $mech->clear_emails_ok; -- cgit v1.2.3 From d0d2c1d1549b4255eb3d852cc5a64319dccebd7e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 Sep 2013 17:07:08 +0100 Subject: explicitly set bodies_str for abuse and app store tests The first email count test in the abuse subtest was failing on Travis but not on my machine because the sent email alert test was running on my machine, as it has the mock module installed, and this was resetting the bodies_str to one with a confirmed contact. Setting bodies_str on both these tests stops this sort of thing happening again --- t/app/model/problem.t | 2 ++ 1 file changed, 2 insertions(+) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index c9fa1a6e3..156ad7fbb 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -642,6 +642,7 @@ subtest 'check iOS app store test reports not sent' => sub { $problem->discard_changes; $problem->update( { + bodies_str => 2651, title => 'App store test', state => 'confirmed', confirmed => \'ms_current_timestamp()', @@ -670,6 +671,7 @@ subtest 'check reports from abuser not sent' => sub { $problem->discard_changes; $problem->update( { + bodies_str => 2651, title => 'Report', state => 'confirmed', confirmed => \'ms_current_timestamp()', -- cgit v1.2.3 From aeba8e0da58b8e04fbbe0e9923fe8c784f3d54e1 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 Sep 2013 18:05:35 +0100 Subject: switch to Sub::Override from Test::MockModule This is for consistency as Sub::Override is used for another test and also so we minimise the number of modules installed just for testing --- t/app/model/problem.t | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 156ad7fbb..9138c11a8 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -9,6 +9,7 @@ use FixMyStreet; use FixMyStreet::App; use FixMyStreet::TestMech; use mySociety::Locale; +use Sub::Override; mySociety::Locale::gettext_domain('FixMyStreet'); @@ -583,9 +584,10 @@ 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'; - + my $send_confirmation_mail_override = Sub::Override->new( + "FixMyStreet::Cobrand::Default::report_sent_confirmation_email", + sub { return 1; } + ); $mech->clear_emails_ok; FixMyStreet::App->model('DB::Problem')->search( @@ -606,9 +608,6 @@ subtest 'check can turn on report sent email alerts' => sub { send_fail_count => 0, } ); - 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 ); @@ -628,6 +627,8 @@ subtest 'check can turn on report sent email alerts' => sub { $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'; + + $send_confirmation_mail_override->restore(); }; -- cgit v1.2.3