diff options
Diffstat (limited to 't/app/controller/report_new.t')
-rw-r--r-- | t/app/controller/report_new.t | 219 |
1 files changed, 142 insertions, 77 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 67e899102..bd0001be8 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -2,7 +2,6 @@ use strict; use utf8; # sign in error message has – in it use warnings; use Test::More; -use utf8; use FixMyStreet::TestMech; use FixMyStreet::App; @@ -35,15 +34,8 @@ subtest "test that bare requests to /report/new get redirected" => sub { "pc correctly transferred"; }; -my %contact_params = ( - confirmed => 1, - deleted => 0, - editor => 'Test', - whenedited => \'current_timestamp', - note => 'Created for test', -); - my %body_ids; +my @bodies; for my $body ( { area_id => 2651, name => 'City of Edinburgh Council' }, { area_id => 2226, name => 'Gloucestershire County Council' }, @@ -56,62 +48,51 @@ for my $body ( { area_id => 2333, name => 'Hart Council', id => 2333 }, ) { my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name}, id => $body->{id}); + push @bodies, $body_obj; $body_ids{$body->{area_id}} = $body_obj->id; } # Let's make some contacts to send things to! -FixMyStreet::App->model('DB::Contact')->search( { - email => { 'like', '%example.com' }, -} )->delete; -my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +my $contact1 = $mech->create_contact_ok( body_id => $body_ids{2651}, # Edinburgh category => 'Street lighting', email => 'highways@example.com', -} ); -my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact2 = $mech->create_contact_ok( body_id => $body_ids{2226}, # Gloucestershire category => 'Potholes', email => 'potholes@example.com', -} ); -my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact3 = $mech->create_contact_ok( body_id => $body_ids{2326}, # Cheltenham category => 'Trees', email => 'trees@example.com', -} ); -my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact4 = $mech->create_contact_ok( body_id => $body_ids{2482}, # Bromley category => 'Trees', email => 'trees@example.com', -} ); -my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact5 = $mech->create_contact_ok( body_id => $body_ids{2651}, # Edinburgh category => 'Trees', email => 'trees@example.com', -} ); -my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact6 = $mech->create_contact_ok( body_id => $body_ids{2333}, # Hart category => 'Trees', email => 'trees@example.com', -} ); -my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact7 = $mech->create_contact_ok( body_id => $body_ids{2227}, # Hampshire category => 'Street lighting', email => 'highways@example.com', -} ); -ok $contact1, "created test contact 1"; -ok $contact2, "created test contact 2"; -ok $contact3, "created test contact 3"; -ok $contact4, "created test contact 4"; -ok $contact5, "created test contact 5"; -ok $contact6, "created test contact 6"; -ok $contact7, "created test contact 7"; +); +my $contact8 = $mech->create_contact_ok( + body_id => $body_ids{2504}, + category => 'Street lighting', + email => 'highways@example.com' +); # test that the various bit of form get filled in and errors correctly # generated. @@ -481,7 +462,7 @@ foreach my $test ( }; # check that we got the errors expected - is_deeply $mech->page_errors, $test->{errors}, "check errors"; + is_deeply [ sort @{$mech->page_errors} ], [ sort @{$test->{errors}} ], "check errors"; # check that fields have changed as expected my $new_values = { @@ -750,8 +731,7 @@ subtest "test report creation for a user who is signing in as they report" => su my $report = $user->problems->first; ok $report, "Found the report"; - # check that we got redirected to /report/ - is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + $mech->content_contains('Thank you for reporting this issue'); # Check the report has been assigned appropriately is $report->bodies_str, $body_ids{2651}; @@ -852,8 +832,7 @@ foreach my $test ( # Check the report has been assigned appropriately is $report->bodies_str, $body_ids{$test->{council}}; - # check that we got redirected to /report/ - is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + $mech->content_contains('Thank you for reporting this issue'); # check that no emails have been sent $mech->email_count_is(0); @@ -1020,7 +999,7 @@ for my $test ( host => 'www.fixmystreet.com', postcode => 'EH99 1SP', fms_extra_title => '', - extra => undef, + extra => [], user_title => undef, }, { @@ -1148,7 +1127,7 @@ for my $test ( my $report = $user->problems->first; ok $report, "Found the report"; - my $extras = $report->extra; + my $extras = $report->get_extra_fields; is $user->title, $test->{'user_title'}, 'user title correct'; is_deeply $extras, $test->{extra}, 'extra contains correct values'; @@ -1227,18 +1206,18 @@ subtest "test Hart" => sub { button => 'submit_register', }, { - desc => 'confirm redirect for cobrand council in two tier cobrand redirects to cobrand site', + desc => 'confirmation page for cobrand council in two tier cobrand links to cobrand site', category => 'Trees', council => 2333, national => 0, - redirect => 1, + confirm => 1, }, { - desc => 'confirm redirect for non cobrand council in two tier cobrand redirect to national site', + desc => 'confirmation page for non cobrand council in two tier cobrand links to national site', category => 'Street Lighting', council => 2227, national => 1, - redirect => 1, + confirm => 1, }, ) { subtest $test->{ desc } => sub { @@ -1247,7 +1226,7 @@ subtest "test Hart" => sub { $mech->clear_emails_ok; $mech->log_out_ok; - my $user = $mech->log_in_ok($test_email) if $test->{redirect}; + my $user = $mech->log_in_ok($test_email) if $test->{confirm}; FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'hart', 'fixmystreet' ], @@ -1258,13 +1237,13 @@ subtest "test Hart" => sub { $mech->content_contains( "Hart Council" ); $mech->submit_form_ok( { with_fields => { pc => 'GU51 4AE' } }, "submit location" ); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); - my %optional_fields = $test->{redirect} ? () : + my %optional_fields = $test->{confirm} ? () : ( email => $test_email, phone => '07903 123 456' ); # we do this as otherwise test::www::mechanize::catalyst # goes to the value set in ->host above irregardless and # that is a 404. It works but it is not pleasant. - $mech->clear_host if $test->{redirect} && $test->{national}; + $mech->clear_host if $test->{confirm} && $test->{national}; $mech->submit_form_ok( { button => $test->{button}, @@ -1295,11 +1274,11 @@ subtest "test Hart" => sub { # Check the report has been assigned appropriately is $report->bodies_str, $body_ids{$test->{council}}; - if ( $test->{redirect} ) { - is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + if ( $test->{confirm} ) { + is $mech->uri->path, "/report/new"; my $base = 'www.fixmystreet.com'; $base = "hart.fixmystreet.com" unless $test->{national}; - is $mech->uri->host, $base, 'redirected to correct site'; + $mech->content_contains("$base/report/" . $report->id, "links to correct site"); } else { # receive token my $email = $mech->get_email; @@ -1358,13 +1337,12 @@ subtest "test SeeSomething" => sub { my $cobrand = FixMyStreet::Cobrand::SeeSomething->new(); my $body_ss = $mech->create_body_ok(2535, 'Sandwell Borough Council', id => 2535); - my $bus_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, + my $bus_contact = $mech->create_contact_ok( body_id => $body_ss->id, category => 'Bus', email => 'bus@example.com', non_public => 1, - } ); + ); for my $test ( { desc => 'report with no user details works', @@ -1454,12 +1432,8 @@ subtest "test SeeSomething" => sub { 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' ); - } + is $mech->uri->path, '/report/new', 'stays on report/new page'; + $mech->content_contains( 'Your report has been sent', 'use report created template' ); $user->alerts->delete; $user->problems->delete; @@ -1488,6 +1462,104 @@ subtest "categories from deleted bodies shouldn't be visible for new reports" => }; }; +subtest "unresponsive body handling works" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + # Test body-level send method + my $old_send = $contact1->body->send_method; + $contact1->body->update( { send_method => 'Refused' } ); + $mech->get_ok('/report/new/ajax?latitude=55.9&longitude=-3.2'); # Edinburgh + my $body_id = $contact1->body->id; + ok $mech->content_like( qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id} ); + + my $test_email = 'test-2@example.com'; + my $user = $mech->log_in_ok($test_email); + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $mech->submit_form_ok( + { + with_fields => { + title => "Test Report at café", + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + } + }, + "submit good details" + ); + + my $report = $user->problems->first; + ok $report, "Found the report"; + is $report->bodies_str, undef, "Report not going anywhere"; + + $user->problems->delete; + $contact1->body->update( { send_method => $old_send } ); + + # And test per-category refusing + my $old_email = $contact3->email; + $contact3->update( { email => 'REFUSED' } ); + $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.89&longitude=-2.09'); + ok $mech->content_like( qr/Cheltenham.*Trees.*unresponsive.*category=Trees/ ); + + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $mech->submit_form_ok( + { + with_fields => { + title => "Test Report at café", + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + } + }, + "submit good details" + ); + + $report = $user->problems->first; + ok $report, "Found the report"; + is $report->bodies_str, undef, "Report not going anywhere"; + + $contact3->update( { email => $old_email } ); + $mech->delete_user($user); + }; +}; + +subtest "unresponsive body page works" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + my $old_send = $contact1->body->send_method; + my $body_id = $contact1->body->id; + my $url = "/unresponsive?body=$body_id"; + is $mech->get($url)->code, 404, "page not found"; + $contact1->body->update( { send_method => 'Refused' } ); + $mech->get_ok($url); + $mech->content_contains('Edinburgh'); + $contact1->body->update( { send_method => $old_send } ); + + my $old_email = $contact3->email; + $body_id = $contact3->body->id; + $url = "/unresponsive?body=$body_id;category=Trees"; + is $mech->get($url)->code, 404, "page not found"; + $contact3->update( { email => 'REFUSED' } ); + $mech->get_ok($url); + $mech->content_contains('Cheltenham'); + $mech->content_contains('Trees'); + $contact3->update( { email => $old_email } ); + }; +}; + subtest "extra google analytics code displayed on logged in problem creation" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], @@ -1537,9 +1609,6 @@ subtest "extra google analytics code displayed on logged in problem creation" => my $report = $user->problems->first; ok $report, "Found the report"; - # check that we got redirected to /report/ - is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; - $mech->content_contains( "'id': 'report/" . $report->id . "'", 'extra google code present' ); # cleanup @@ -1606,12 +1675,8 @@ subtest "extra google analytics code displayed on email confirmation problem cre }; }; -$contact1->delete; -$contact2->delete; -$contact3->delete; -$contact4->delete; -$contact5->delete; -$contact6->delete; -$contact7->delete; - done_testing(); + +END { + $mech->delete_body($_) foreach @bodies; +} |