aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/report_new.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/report_new.t')
-rw-r--r--t/app/controller/report_new.t105
1 files changed, 96 insertions, 9 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 29fb650e5..88236a1c3 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -34,6 +34,9 @@ my %contact_params = (
note => 'Created for test',
);
# 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,
area_id => 2651, # Edinburgh
@@ -64,11 +67,25 @@ my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
category => 'Trees',
email => 'trees@example.com',
} );
+my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2434, # Lichfield
+ category => 'Trees',
+ email => 'trees@example.com',
+} );
+my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2240, # Lichfield
+ 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";
# test that the various bit of form get filled in and errors correctly
# generated.
@@ -371,7 +388,7 @@ foreach my $test (
# submit initial pc form
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
"submit location" );
- is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'";
+ is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'";
# click through to the report page
$mech->follow_link_ok( { text_regex => qr/skip this step/i, },
@@ -382,7 +399,7 @@ foreach my $test (
"submit form" );
# check that we got the errors expected
- is_deeply $mech->form_errors, $test->{errors}, "check errors";
+ is_deeply $mech->page_errors, $test->{errors}, "check errors";
# check that fields have changed as expected
my $new_values = {
@@ -463,7 +480,7 @@ foreach my $test (
);
# check that we got the errors expected
- is_deeply $mech->form_errors, [], "check there were no errors";
+ is_deeply $mech->page_errors, [], "check there were no errors";
# check that the user has been created/ not changed
my $user =
@@ -573,7 +590,7 @@ subtest "test password errors for a user who is signing in as they report" => su
);
# check that we got the errors expected
- is_deeply $mech->form_errors, [
+ is_deeply $mech->page_errors, [
"There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the \x{2018}sign in by email\x{2019} section of the form.",
], "check there were errors";
};
@@ -620,7 +637,7 @@ subtest "test report creation for a user who is signing in as they report" => su
);
# check that we got the errors expected
- is_deeply $mech->form_errors, [
+ is_deeply $mech->page_errors, [
'You have successfully signed in; please check and confirm your details are accurate:',
], "check there were errors";
@@ -798,10 +815,8 @@ subtest "check that a lat/lon off coast leads to /around" => sub {
is $mech->uri->path, '/around', "redirected to '/around'";
is_deeply #
- $mech->form_errors,
- [ 'That spot does not appear to be covered by a council. If you have'
- . ' tried to report an issue past the shoreline, for example, please'
- . ' specify the closest point on land.' ], #
+ $mech->page_errors,
+ [ 'That location does not appear to be covered by a council; perhaps it is offshore or outside the country. Please try again.' ],
"Found location error";
};
@@ -859,6 +874,10 @@ for my $test (
)
{
subtest $test->{desc} => sub {
+ if ( $test->{host} =~ /bromley/ && !FixMyStreet::Cobrand->exists('bromley') ) {
+ plan skip_all => 'Skipping Bromley tests without Bromley cobrand';
+ }
+
$mech->host( $test->{host} );
$mech->log_out_ok;
@@ -941,10 +960,78 @@ for my $test (
};
}
+SKIP: {
+ skip( "Need 'lichfielddc' in ALLOWED_COBRANDS config", 100 )
+ unless FixMyStreet::Cobrand->exists('lichfielddc');
+
+ my $test_email = 'test-22@example.com';
+ $mech->host( 'http://lichfielddc.fixmystreet.com/' );
+ $mech->clear_emails_ok;
+ $mech->log_out_ok;
+
+ $mech->get_ok('/around');
+ $mech->submit_form_ok( { with_fields => { pc => 'WS13 7RD' } }, "submit location" );
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
+ $mech->submit_form_ok(
+ {
+ button => 'submit_register',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ photo => '',
+ name => 'Joe Bloggs',
+ may_show_name => '1',
+ email => $test_email,
+ phone => '07903 123 456',
+ category => 'Street lighting',
+ }
+ },
+ "submit good details"
+ );
+ is_deeply $mech->page_errors, [], "check there were no errors";
+
+ # check that the user has been created/ not changed
+ my $user =
+ FixMyStreet::App->model('DB::User')->find( { email => $test_email } );
+ ok $user, "user found";
+
+ # find the report
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+
+ # Check the report has been assigned appropriately
+ is $report->council, 2240;
+
+ # receive token
+ my $email = $mech->get_email;
+ ok $email, "got an email";
+ like $email->body, qr/confirm the problem/i, "confirm the problem";
+
+ my ($url) = $email->body =~ m{(http://\S+)};
+ ok $url, "extracted confirm url '$url'";
+
+ # confirm token
+ $mech->get_ok($url);
+ $report->discard_changes;
+ is $report->state, 'confirmed', "Report is now confirmed";
+
+ # Shouldn't be found, as it was a county problem
+ is $mech->get( '/report/' . $report->id )->code, 404, "report not found";
+
+ # But should be on the main site
+ $mech->host( 'www.fixmystreet.com' );
+ $mech->get_ok( '/report/' . $report->id );
+ is $report->name, 'Joe Bloggs', 'name updated correctly';
+
+ $mech->delete_user($user);
+}
+
$contact1->delete;
$contact2->delete;
$contact3->delete;
$contact4->delete;
$contact5->delete;
+$contact6->delete;
+$contact7->delete;
done_testing();