diff options
author | Struan Donald <struan@exo.org.uk> | 2013-01-04 15:42:33 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-01-04 15:42:33 +0000 |
commit | 8692e451268eaba507f64d3de99fdd40c7b63f80 (patch) | |
tree | f5c09b1adbb5f0212438bf6e4d8179ffdb914f5f /t/app | |
parent | bc04a16b91516bee5164921d223605911fb67e44 (diff) | |
parent | 177ad0fe42f7474296287b448b485aa452e583f3 (diff) |
Merge branch 'centro'
Conflicts:
perllib/FixMyStreet/Cobrand/Default.pm
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/report_new.t | 113 | ||||
-rw-r--r-- | t/app/model/problem.t | 47 |
2 files changed, 160 insertions, 0 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 77afb071c..d20f15922 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -1142,6 +1142,119 @@ SKIP: { $mech->delete_user($user); } +SKIP: { + skip( "Need 'seesomething' in ALLOWED_COBRANDS config", 100 ) + unless FixMyStreet::Cobrand->exists('seesomething'); + + $mech->host('seesomething.fixmystreet.com'); + $mech->clear_emails_ok; + $mech->log_out_ok; + + my $cobrand = FixMyStreet::Cobrand::SeeSomething->new(); + + my $bus_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2535, + category => 'Bus', + email => 'bus@example.com', + non_public => 1, + } ); + + for my $test ( { + desc => 'report with no user details works', + pc => 'WS1 4NH', + fields => { + detail => 'Test report details', + category => 'Bus', + subcategory => 'Smoking', + }, + email => $cobrand->anonymous_account->{email}, + }, + { + desc => 'report with user details works', + pc => 'WS1 4NH', + fields => { + detail => 'Test report details', + category => 'Bus', + subcategory => 'Smoking', + email => 'non_anon_user@example.com', + name => 'Non Anon', + }, + email => 'non_anon_user@example.com', + }, + { + desc => 'report with public category', + pc => 'WS1 4NH', + fields => { + detail => 'Test report details', + category => 'Bus', + subcategory => 'Smoking', + }, + email => $cobrand->anonymous_account->{email}, + public => 1, + } + ) { + subtest $test->{desc} => sub { + $mech->clear_emails_ok; + my $user = + FixMyStreet::App->model('DB::User')->find( { email => $test->{email} } ); + + if ( $user ) { + $user->alerts->delete; + $user->problems->delete; + $user->delete; + } + + if ( $test->{public} ) { + $bus_contact->non_public(0); + $bus_contact->update; + } else { + $bus_contact->non_public(1); + $bus_contact->update; + } + + $mech->get_ok( '/around' ); + $mech->submit_form_ok( + { + with_fields => { + pc => $test->{pc}, + }, + }, + 'submit around form', + ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + + $mech->submit_form_ok( + { + with_fields => $test->{fields}, + }, + 'Submit form details with no user details', + ); + is_deeply $mech->page_errors, [], "check there were no errors"; + + $user = + FixMyStreet::App->model('DB::User')->find( { email => $test->{email} } ); + ok $user, "user found"; + + my $report = $user->problems->first; + ok $report, "Found the report"; + + $mech->email_count_is(0); + + ok $report->confirmed, 'Report is confirmed automatically'; + + if ( $test->{public} ) { + is $mech->uri->path, '/report/' . $report->id, 'redirects to report page'; + } else { + is $mech->uri->path, '/report/new', 'stays on report/new page'; + $mech->content_contains( 'Your report has been sent', 'use report created template' ); + } + }; + } + + $bus_contact->delete; +} + $contact1->delete; $contact2->delete; $contact3->delete; diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 9aa52c3cf..63204e05c 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -540,6 +540,53 @@ 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'; + + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + council => 2651, + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'potholes', + name => 'Test User', + cobrand => 'fixmystreet', + } ); + + 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 ); + my @emails = $mech->get_email; + my $email = $emails[0]; + + like $email->header('To'),qr/City of Edinburgh Council/, 'to line looks correct'; + is $email->header('From'), '"Test User" <system_user@example.com>', 'from line looks correct'; + like $email->header('Subject'), qr/A Title/, 'subject line looks correct'; + like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report'; + like $email->body, qr/Subject: A Title/, 'more email body checking'; + like $email->body, qr/Dear City of Edinburgh Council/, 'Salutation looks correct'; + + $problem->discard_changes; + ok defined( $problem->whensent ), 'whensent set'; + + $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'; +}; + $problem->comments->delete; $problem->delete; $user->delete; |