diff options
Diffstat (limited to 't/app/model')
-rw-r--r-- | t/app/model/alert_type.t | 53 | ||||
-rw-r--r-- | t/app/model/problem.t | 159 | ||||
-rw-r--r-- | t/app/model/rabx_column.t | 23 | ||||
-rw-r--r-- | t/app/model/token.t | 46 |
4 files changed, 260 insertions, 21 deletions
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index ba48300b2..ae413978f 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -97,6 +97,7 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( alert_type => 'new_updates', whensubscribed => $dt->ymd . ' ' . $dt->hms, confirmed => 1, + cobrand => 'default', } ); @@ -107,6 +108,7 @@ my $alert3 = FixMyStreet::App->model('DB::Alert')->find_or_create( alert_type => 'new_updates', whensubscribed => $dt->ymd . ' ' . $dt->hms, confirmed => 1, + cobrand => 'default', } ); @@ -185,7 +187,11 @@ subtest "correct text for title after URL" => sub { parameter => $report->id, } )->delete; - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; my $email = $mech->get_email; (my $title = $report->title) =~ s/ /\\s+/; @@ -318,7 +324,11 @@ foreach my $test ( $report->geocode( $g ); $report->update(); - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; my $email = $mech->get_email; my $body = $email->body; @@ -423,7 +433,11 @@ subtest "check alerts from cobrand send main site url for alerts for different c } )->delete; - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; my $email = $mech->get_email; my $body = $email->body; @@ -473,7 +487,34 @@ subtest "check local alerts from cobrand send main site url for alerts for diffe like $body, qr#$expected2#, 'cobrand area report point to cobrand url'; }; -$report->comments->delete(); -$report->delete(); -done_testing(); +# Test that email alerts are sent in the right language. +subtest "correct i18n-ed summary for state of closed" => sub { + $mech->clear_emails_ok; + + $report->update( { state => 'closed' } ); + $alert->update( { lang => 'nb', cobrand => 'fiksgatami' } ); + FixMyStreet::App->model('DB::AlertSent')->search( { + alert_id => $alert->id, + parameter => $comment->id, + } )->delete; + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fiksgatami' ], + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; + + $mech->email_count_is( 1 ); + my $email = $mech->get_email; + my $body = $email->body; + my $msg = 'Denne rapporten er for tiden markert som lukket'; + like $body, qr/$msg/, 'email says problem is closed, in Norwegian'; +}; + +END { + $mech->delete_user($user) if $user; + $mech->delete_user($user2) if $user2; + $mech->delete_user($user3) if $user3; + done_testing(); +} diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 7daa653fc..fa8cf89ae 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'); @@ -464,8 +465,8 @@ foreach my $test ( { desc => 'email to two tier council', unset_whendef => 1, email_count => 1, - to => qr'Gloucestershire County Council.*Cheltenham Borough Council', - dear => qr'Dear Gloucestershire County Council and Cheltenham Borough', + to => qr'Cheltenham Borough Council.*Gloucestershire County Council', + dear => qr'Dear Cheltenham Borough Council and Gloucestershire County', body => '2226,2326', multiple => 1, }, { @@ -496,7 +497,7 @@ foreach my $test ( { dear => qr'Dear Staffordshire County Council,', body => '2240', cobrand => 'lichfielddc', - url => '', + url => 'www.', }, { %common, desc => 'directs NI correctly, 1', @@ -525,8 +526,13 @@ 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'; + my $override = { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }; + if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ ) { + $override->{ALLOWED_COBRANDS} = [ 'lichfielddc' ]; } $mech->clear_emails_ok; @@ -548,7 +554,9 @@ foreach my $test ( { cobrand => $test->{ cobrand } || 'fixmystreet', } ); - FixMyStreet::App->model('DB::Problem')->send_reports(); + FixMyStreet::override_config $override, sub { + FixMyStreet::App->model('DB::Problem')->send_reports(); + }; $mech->email_count_is( $test->{ email_count } ); if ( $test->{ email_count } ) { @@ -567,9 +575,8 @@ foreach my $test ( { } if ( $test->{url} ) { - (my $base_url = FixMyStreet->config('BASE_URL')) =~ s{http://}{}; my $id = $problem->id; - like $email->body, qr[$test->{url}$base_url/report/$id], 'URL present is correct'; + like $email->body, qr[$test->{url}fixmystreet.com/report/$id], 'URL present is correct'; } $problem->discard_changes; @@ -582,10 +589,57 @@ 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'; +subtest 'check can set mutiple emails as a single contact' => sub { + my $override = { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }; + + my $contact = { + body_id => 2651, # Edinburgh + category => 'trees', + email => '2636@example.com,2636-2@example.com', + }; + my $new_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + %$contact } ); + ok $new_contact, "created multiple email test contact"; + + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + bodies_str => $contact->{ body_id }, + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'trees', + name => 'Test User', + cobrand => 'fixmystreet', + send_fail_count => 0, + } ); + FixMyStreet::override_config $override, sub { + FixMyStreet::App->model('DB::Problem')->send_reports(); + }; + + $mech->email_count_is(1); + my $email = $mech->get_email; + is $email->header('To'), '"City of Edinburgh Council" <2636@example.com>, "City of Edinburgh Council" <2636-2@example.com>', 'To contains two email addresses'; +}; + +subtest 'check can turn on report sent email alerts' => sub { + 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 +660,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 +679,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/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(); |