diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/alert_new.t | 5 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 129 | ||||
-rw-r--r-- | t/map/tests.t | 1 | ||||
-rw-r--r-- | t/open311/getservicerequests.t | 26 |
4 files changed, 153 insertions, 8 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 4e8fd1b29..27371e4a9 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -451,9 +451,8 @@ subtest "Test normal alert signups and that alerts are sent" => sub { is $count, 5, 'Three emails, with five matching lines in them'; my $email = $emails[0]; - my $body = $mech->get_text_body_from_email($email); - like $body, qr/Other User/, 'Update name given'; - unlike $body, qr/Anonymous User/, 'Update name not given'; + is +(my $c = () = $email->as_string =~ /Other User/g), 2, 'Update name given, twice'; + unlike $email->as_string, qr/Anonymous User/, 'Update name not given'; # The update alert was to the problem reporter, so has a special update URL $mech->log_out_ok; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 32d86d803..0e7547a85 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -86,6 +86,16 @@ my $contact8 = $mech->create_contact_ok( category => 'Street lighting', email => 'highways@example.com' ); +my $contact9 = $mech->create_contact_ok( + body_id => $body_ids{2226}, # Gloucestershire + category => 'Street lighting', + email => 'streetlights-2226@example.com', +); +my $contact10 = $mech->create_contact_ok( + body_id => $body_ids{2326}, # Cheltenham + category => 'Street lighting', + email => 'streetlights-2326@example.com', +); # test that the various bit of form get filled in and errors correctly # generated. @@ -932,6 +942,125 @@ foreach my $test ( } +# XXX add test for category with multiple bodies +foreach my $test ( + { + desc => "test report creation for multiple bodies", + category => 'Street lighting', + councils => [ 2226, 2326 ], + extra_fields => {}, + email_count => 2, + }, + { + desc => "test single_body_only means only one report body", + category => 'Street lighting', + councils => [ 2326 ], + extra_fields => { single_body_only => 'Cheltenham Borough Council' }, + email_count => 1, + }, + { + desc => "test invalid single_body_only means multiple report bodies", + category => 'Street lighting', + councils => [ 2226, 2326 ], + extra_fields => { single_body_only => 'Invalid council' }, + email_count => 1, + }, +) { + subtest $test->{desc} => sub { + + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + $mech->clear_emails_ok; + my $user = $mech->log_in_ok($test_email); + + # setup the user. + ok $user->update( + { + name => 'Test User', + phone => '01234 567 890', + } + ), + "set users details"; + + # submit initial pc form + $mech->get_ok('/around'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, + "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + # check that the fields are correctly prefilled + is_deeply( + $mech->visible_form_values, + { + title => '', + detail => '', + may_show_name => '1', + name => 'Test User', + phone => '01234 567 890', + photo1 => '', + photo2 => '', + photo3 => '', + category => '-- Pick a category --', + }, + "user's details prefilled" + ); + + $mech->submit_form_ok( + { + with_fields => { + title => "Test Report at café", + detail => 'Test report details.', + photo1 => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => $test->{category}, + %{$test->{extra_fields}} + } + }, + "submit good details" + ); + }; + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # Check the report has been assigned appropriately + is $report->bodies_str, join(',', @body_ids{@{$test->{councils}}}); + + $mech->content_contains('Thank you for reporting this issue'); + + # check that no emails have been sent + $mech->email_count_is(0); + + # check report is confirmed and available + is $report->state, 'confirmed', "report is now confirmed"; + $mech->get_ok( '/report/' . $report->id ); + + # Test that AJAX pages return the right data + $mech->get_ok( + '/around?ajax=1&bbox=' . ($report->longitude - 0.01) . ',' . ($report->latitude - 0.01) + . ',' . ($report->longitude + 0.01) . ',' . ($report->latitude + 0.01) + ); + $mech->content_contains( "Test Report at caf\xc3\xa9" ); + $saved_lat = $report->latitude; + $saved_lon = $report->longitude; + + # cleanup + $mech->delete_user($user); + }; + +} + subtest "Test inactive categories" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], diff --git a/t/map/tests.t b/t/map/tests.t index 1123133e4..3b2b072b7 100644 --- a/t/map/tests.t +++ b/t/map/tests.t @@ -6,6 +6,7 @@ my $requires = { 'Bing' => 'map-bing-ol.js', 'Bristol' => 'bristol/js.js', 'Bromley' => 'bromley/map.js', + 'Buckinghamshire' => 'buckinghamshire/js.js', 'FMS' => 'map-fms.js', 'Google' => 'map-google.js', 'GoogleOL' => 'map-google-ol.js', diff --git a/t/open311/getservicerequests.t b/t/open311/getservicerequests.t index f8795bd61..a28c6e3cf 100644 --- a/t/open311/getservicerequests.t +++ b/t/open311/getservicerequests.t @@ -58,18 +58,32 @@ my $o = Open311->new( test_get_returns => { 'requests.xml' => $requests_xml } ); +my $p1_date = $dtf->parse_datetime('2010-04-14T06:37:38-08:00') + ->set_time_zone( + FixMyStreet->time_zone || FixMyStreet->local_time_zone + ); +my $p2_date = $dtf->parse_datetime('2010-04-15T06:37:38-08:00') + ->set_time_zone( + FixMyStreet->time_zone || FixMyStreet->local_time_zone + ); +my $start_date = $p1_date->clone; +$start_date->add( hours => -2); +my $end_date = $p2_date->clone; +$end_date->add( hours => 2); + + subtest 'basic parsing checks' => sub { - my $update = Open311::GetServiceRequests->new( system_user => $user ); + my $update = Open311::GetServiceRequests->new( + system_user => $user, + start_date => $start_date, + end_date => $end_date + ); FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', }, sub { $update->create_problems( $o, $body ); }; - my $p1_date = $dtf->parse_datetime('2010-04-14T06:37:38-08:00') - ->set_time_zone( - FixMyStreet->time_zone || FixMyStreet->local_time_zone - ); my $p = FixMyStreet::DB->resultset('Problem')->search( { external_id => 638344 } @@ -277,6 +291,8 @@ for my $test ( my $update = Open311::GetServiceRequests->new( system_user => $user, convert_latlong => 1, + start_date => $start_date, + end_date => $end_date ); FixMyStreet::override_config { |