diff options
Diffstat (limited to 't/app/model')
-rw-r--r-- | t/app/model/problem.t | 91 | ||||
-rw-r--r-- | t/app/model/questionnaire.t | 2 | ||||
-rw-r--r-- | t/app/model/rabx_column.t | 23 | ||||
-rw-r--r-- | t/app/model/token.t | 46 |
4 files changed, 153 insertions, 9 deletions
diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 7daa653fc..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,8 +627,88 @@ 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(); +}; + + +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( { + bodies_str => 2651, + 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; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + bodies_str => 2651, + 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 ); diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t index 86af51c42..be5b433c1 100644 --- a/t/app/model/questionnaire.t +++ b/t/app/model/questionnaire.t @@ -32,8 +32,6 @@ my $problem = FixMyStreet::App->model('DB::Problem')->create( } ); -diag $problem->id; - my $mech = FixMyStreet::TestMech->new; for my $test ( diff --git a/t/app/model/rabx_column.t b/t/app/model/rabx_column.t new file mode 100644 index 000000000..607d578ce --- /dev/null +++ b/t/app/model/rabx_column.t @@ -0,0 +1,23 @@ +use strict; +use warnings; + +use Test::More; + +use_ok "FixMyStreet::DB::RABXColumn"; + +# Test that the class names are correctly normalised +my @tests = ( + ["FixMyStreet::DB::Result::Token", "Token"], + ["FixMyStreet::App::Model::DB::Token", "Token"], +); + +foreach my $test (@tests) { + my ($input, $expected) = @$test; + is( + FixMyStreet::DB::RABXColumn::_get_class_identifier($input), + $expected, + "$input -> $expected" + ); +} + +done_testing(); diff --git a/t/app/model/token.t b/t/app/model/token.t index 12945975e..637477fa3 100644 --- a/t/app/model/token.t +++ b/t/app/model/token.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 45; +use Test::More; use FixMyStreet; use FixMyStreet::App; @@ -94,3 +94,47 @@ foreach my $test_data_name ( sort keys %tests ) { undef, "token gone with m::AT"; } + + + +# Test that the inflation and deflation works as expected +{ + my $token = + $token_rs->create( { scope => 'testing', data => {} } ); + END { $token->delete() }; + + # Add in temporary check to test that the data is updated as expected. + is_deeply($token->data, {}, "data is empty"); + + # store something in it + $token->update({ data => { foo => 'bar' } }); + $token->discard_changes(); + is_deeply($token->data, { foo => 'bar' }, "data has content"); + + # change the hash stored + $token->update({ data => { baz => 'bundy' } }); + $token->discard_changes(); + is_deeply($token->data, { baz => 'bundy' }, "data has new content"); + + # change the hashref in place + { + my $data = $token->data; + $data->{baz} = 'new'; + $token->data( $data ); + $token->update(); + $token->discard_changes(); + is_deeply($token->data, { baz => 'new' }, "data has been updated"); + } + + # change the hashref in place + { + my $data = $token->data; + $data->{baz} = 'new'; + $token->update({ data => $data }); + $token->discard_changes(); + is_deeply($token->data, { baz => 'new' }, "data has been updated"); + } + +} + +done_testing(); |