diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/alert_new.t | 73 | ||||
-rw-r--r-- | t/app/controller/auth.t | 5 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 167 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 132 |
4 files changed, 274 insertions, 103 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index d0976b4bb..cb3b4b656 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -193,22 +193,11 @@ foreach my $test ( foreach my $test ( { desc => 'logged in user signing up', - user => 'test-sign-in@example.com', email => 'test-sign-in@example.com', type => 'council', param1 => 2651, param2 => 2651, confirmed => 1, - }, - { - desc => 'logged in user signing up with different email', - user => 'loggedin@example.com', - email => 'test-sign-in@example.com', - type => 'council', - param1 => 2651, - param2 => 2651, - confirmed => 0, - delete => 1, } ) { @@ -217,42 +206,18 @@ foreach my $test ( my $user = FixMyStreet::App->model('DB::User') - ->find_or_create( { email => $test->{user} } ); - - my $alert_user = - FixMyStreet::App->model('DB::User') - ->find( { email => $test->{email} } ); - - $mech->log_in_ok( $test->{user} ); + ->find_or_create( { email => $test->{email} } ); + $mech->log_in_ok( $test->{email} ); $mech->clear_emails_ok; - my $alert; - if ($alert_user) { - $alert = FixMyStreet::App->model('DB::Alert')->find( - { - user => $alert_user, - alert_type => $type - } - ); - - # clear existing data so we can be sure we're creating it - $alert->delete() if $alert; - } - $mech->get_ok('/alert/list?pc=EH991SP'); - - my $form_values = $mech->visible_form_values(); - ok $form_values->{rznvy} eq $test->{user}, - 'auto filled in correct email'; - - $mech->set_visible( [ radio => 'council:2651:City_of_Edinburgh' ], - [ text => $test->{email} ] ); + $mech->set_visible( [ radio => 'council:2651:City_of_Edinburgh' ] ); $mech->click('alert'); - $alert = FixMyStreet::App->model('DB::Alert')->find( + my $alert = FixMyStreet::App->model('DB::Alert')->find( { - user => $alert_user, + user => $user, alert_type => $type, parameter => $test->{param1}, parameter2 => $test->{param2}, @@ -261,13 +226,8 @@ foreach my $test ( ); ok $alert, 'New alert created with logged in user'; - - $mech->email_count_is( $test->{confirmed} ? 0 : 1 ); - - if ( $test->{delete} ) { - $mech->delete_user($user); - $mech->delete_user($alert_user); - } + $mech->email_count_is( 0 ); + $mech->delete_user($user); }; } @@ -391,17 +351,24 @@ subtest "Test normal alert signups and that alerts are sent" => sub { $user2->alerts->delete; for my $alert ( - { feed => 'local:55.951963:-3.189944', email_confirm => 1 }, - { feed => 'council:2651:City_of_Edinburgh', }, + { + fields => { + feed => 'local:55.951963:-3.189944', + rznvy => $user2->email, + }, + email_confirm => 1 + }, + { + fields => { + feed => 'council:2651:City_of_Edinburgh', + } + }, ) { $mech->get_ok( '/alert' ); $mech->submit_form_ok( { with_fields => { pc => 'EH11BB' } } ); $mech->submit_form_ok( { button => 'alert', - with_fields => { - rznvy => $user2->email, - feed => $alert->{feed}, - } + with_fields => $alert->{fields}, } ); if ( $alert->{email_confirm} ) { my $email = $mech->get_email; diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 8fbc413ec..1a16457f9 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -128,8 +128,7 @@ $mech->not_logged_in_ok; $mech->get_ok($link); is $mech->uri->path, '/faq', "redirected to the Help page"; - $mech->get_ok('/my'); - $mech->follow_link_ok( { url => '/auth/change_password' } ); + $mech->get_ok('/auth/change_password'); ok my $form = $mech->form_name('change_password'), "found change password form"; @@ -224,7 +223,7 @@ $mech->submit_form_ok( "sign in with '$test_email' & '$test_password" ); is $mech->uri->path, '/auth', "redirected to correct page"; -$mech->content_contains( 'Email or password wrong', 'found error message' ); +$mech->content_contains( 'problem with your email/password combination', 'found error message' ); # more test: # TODO: test that email are always lowercased diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 3e486d22c..537786ebc 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -65,13 +65,16 @@ foreach my $test ( email => '', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => {}, errors => [ 'Please enter a subject', 'Please enter some details', - 'Please enter your name', 'Please enter your email', + 'Please enter your name', ], }, { @@ -86,13 +89,16 @@ foreach my $test ( email => '', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => { may_show_name => '1' }, errors => [ 'Please enter a subject', 'Please enter some details', - 'Please enter your name', 'Please enter your email', + 'Please enter your name', ], }, { @@ -107,6 +113,9 @@ foreach my $test ( email => '', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => {}, errors => [ @@ -127,6 +136,9 @@ foreach my $test ( email => '', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => {}, errors => [ @@ -147,6 +159,9 @@ foreach my $test ( email => '', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => { title => 'Dog poo on walls', @@ -167,11 +182,14 @@ foreach my $test ( email => '', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => {}, errors => [ -'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', 'Please enter your email', +'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', ], }, { @@ -186,11 +204,14 @@ foreach my $test ( email => '', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => {}, errors => [ -'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', 'Please enter your email', +'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', ], }, { @@ -205,6 +226,9 @@ foreach my $test ( email => 'not an email', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => { email => 'notanemail', }, errors => [ 'Please enter a valid email', ], @@ -221,12 +245,18 @@ foreach my $test ( email => '', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => { title => 'Test title', detail => "First line\n\nSecond line", }, - errors => [ 'Please enter your name', 'Please enter your email', ], + errors => [ + 'Please enter your email', + 'Please enter your name', + ], }, { msg => 'clean up name and email', @@ -240,6 +270,9 @@ foreach my $test ( email => ' BOB @ExAmplE.COM ', phone => '', category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, }, changes => { name => 'Bob Jones', @@ -278,14 +311,30 @@ foreach my $test ( }; } -subtest "test report creation for a user who does not have an account" => sub { +foreach my $test ( + { + desc => 'does not have an account', + user => 0, + }, + { + desc => 'does have an account and is not signed in; does not sign in', + user => 1, + } +) { + subtest "test report creation for a user who " . $test->{desc} => sub { $mech->log_out_ok; $mech->clear_emails_ok; # check that the user does not exist my $test_email = 'test-1@example.com'; - ok !FixMyStreet::App->model('DB::User')->find( { email => $test_email } ), - "test user does not exist"; + if ($test->{user}) { + my $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + ok $user, "test user does exist"; + $user->problems->delete; + } else { + ok !FixMyStreet::App->model('DB::User')->find( { email => $test_email } ), + "test user does not exist"; + } # submit initial pc form $mech->get_ok('/around'); @@ -298,6 +347,7 @@ subtest "test report creation for a user who does not have an account" => sub { $mech->submit_form_ok( { + button => 'submit_register', with_fields => { title => 'Test Report', detail => 'Test report details.', @@ -307,6 +357,7 @@ subtest "test report creation for a user who does not have an account" => sub { email => 'test-1@example.com', phone => '07903 123 456', category => 'Street lighting', + password_register => 'secret', } }, "submit good details" @@ -319,6 +370,7 @@ subtest "test report creation for a user who does not have an account" => sub { my $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); ok $user, "created new user"; + ok $user->check_password('secret'), 'password set correctly'; # find the report my $report = $user->problems->first; @@ -358,15 +410,98 @@ subtest "test report creation for a user who does not have an account" => sub { $mech->logged_in_ok; # cleanup - $mech->delete_user($user); -}; + $mech->delete_user($user) + if $test->{user}; + }; +} + +subtest "test report creation for a user who is signing in as they report" => sub { + $mech->log_out_ok; + $mech->clear_emails_ok; + + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => $test_email } ); + ok $user, "test user does exist"; + + # setup the user. + ok $user->update( { + name => 'Joe Bloggs', + phone => '01234 567 890', + password => 'secret2', + } ), "set user details"; + + # submit initial pc form + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, + "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); + + $mech->submit_form_ok( + { + button => 'submit_sign_in', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + email => 'test-2@example.com', + password_sign_in => 'secret2', + category => 'Street lighting', + } + }, + "submit good details" + ); + + # check that we got the errors expected + is_deeply $mech->form_errors, [ + 'You have successfully signed in; please check and confirm your details are accurate:', + ], "check there were errors"; + + # Now submit with a name + $mech->submit_form_ok( + { + with_fields => { + name => 'Joe Bloggs', + } + }, + "submit good details" + ); + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; -#### test report creation for a user who has account but is not logged in -# come to site -# fill in report -# receive token -# confirm token -# report is confirmed + # check that we got redirected to /report/ + is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + + # Check the report has been assigned appropriately + is $report->council, 2651; + + # 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 ); + + # check that the reporter has an alert + my $alert = FixMyStreet::App->model('DB::Alert')->find( { + user => $report->user, + alert_type => 'new_updates', + parameter => $report->id, + } ); + ok $alert, "created new alert"; + + # user is created and logged in + $mech->logged_in_ok; + + # cleanup + $mech->delete_user($user) +}; #### test report creation for user with account and logged in foreach my $test ( diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 49bfc0d1b..e8acbfd14 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -201,9 +201,12 @@ for my $test ( fixed => undef, add_alert => 1, may_show_name => undef, + remember_me => undef, + password_register => '', + password_sign_in => '', }, changes => {}, - field_errors => [ 'Please enter a message', 'Please enter your email' ] + field_errors => [ 'Please enter a message', 'Please enter your email', 'Please enter your name' ] }, { desc => 'Invalid email, no message', @@ -215,9 +218,12 @@ for my $test ( fixed => undef, add_alert => 1, may_show_name => undef, + remember_me => undef, + password_sign_in => '', + password_register => '', }, changes => {}, - field_errors => [ 'Please enter a message', 'Please enter a valid email' ] + field_errors => [ 'Please enter a message', 'Please enter a valid email', 'Please enter your name' ] }, { desc => 'email with spaces, no message', @@ -229,11 +235,14 @@ for my $test ( fixed => undef, add_alert => 1, may_show_name => undef, + remember_me => undef, + password_register => '', + password_sign_in => '', }, changes => { rznvy => 'test@example.com', }, - field_errors => [ 'Please enter a message' ] + field_errors => [ 'Please enter a message', 'Please enter your name' ] }, { desc => 'email with uppercase, no message', @@ -245,11 +254,14 @@ for my $test ( fixed => undef, add_alert => 1, may_show_name => undef, + remember_me => undef, + password_register => '', + password_sign_in => '', }, changes => { rznvy => 'test@example.com', }, - field_errors => [ 'Please enter a message' ] + field_errors => [ 'Please enter a message', 'Please enter your name' ] }, ) { @@ -281,12 +293,17 @@ for my $test ( photo => '', update => '', fixed => undef, + remember_me => undef, + password_register => '', + password_sign_in => '', }, form_values => { submit_update => 1, rznvy => 'unregistered@example.com', update => 'Update from an unregistered user', add_alert => undef, + name => 'Unreg User', + may_show_name => undef, }, changes => {}, }, @@ -300,12 +317,17 @@ for my $test ( photo => '', update => '', fixed => undef, + remember_me => undef, + password_register => '', + password_sign_in => '', }, form_values => { submit_update => 1, rznvy => 'unregistered@example.com', update => 'update from an unregistered user', add_alert => 1, + name => 'Unreg User', + may_show_name => undef, }, changes => { update => 'Update from an unregistered user', @@ -562,32 +584,82 @@ $report->update; for my $test ( { - desc => 'submit update for registered user', - initial_values => { - name => 'Test User', - may_show_name => 1, - add_alert => 1, - photo => '', - update => '', - fixed => undef, - }, - email => 'test@example.com', - fields => { + desc => 'submit an update for a non registered user, signing in with wrong password', + form_values => { submit_update => 1, - update => 'update from a registered user', - add_alert => undef, - fixed => undef, - }, - changed => { - update => 'Update from a registered user' + rznvy => 'registered@example.com', + update => 'Update from a user', + add_alert => undef, + password_sign_in => 'secret', }, - initial_banner => '', - endstate_banner => '', - alert => 0, - anonymous => 0, + field_errors => [ + 'There was a problem with your email/password combination. Please try again.', + 'Please enter your name', # FIXME Not really necessary error + ], }, { - desc => 'submit update for registered user anonymously by unchecking', + desc => 'submit an update for a non registered user and sign in', + form_values => { + submit_update => 1, + rznvy => 'registered@example.com', + update => 'Update from a user', + add_alert => undef, + password_sign_in => 'secret2', + }, + field_errors => [ + 'You have successfully signed in; please check and confirm your details are accurate:', + ], + } +) { + subtest $test->{desc} => sub { + # Set things up + my $user = $mech->create_user_ok( $test->{form_values}->{rznvy} ); + my $pw = 'secret2'; + $user->update( { name => 'Mr Reg', password => $pw } ); + $report->comments->delete; + + $mech->log_out_ok(); + $mech->clear_emails_ok(); + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok( + { + button => 'submit_sign_in', + with_fields => $test->{form_values} + }, + 'submit update' + ); + + is_deeply $mech->form_errors, $test->{field_errors}, 'check there were errors'; + + SKIP: { + skip( "Incorrect password", 5 ) unless $test->{form_values}{password_sign_in} eq $pw; + + # Now submit with a name + $mech->submit_form_ok( + { + with_fields => { + name => 'Joe Bloggs', + } + }, + "submit good details" + ); + + is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; + $mech->email_count_is(0); + + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, $test->{form_values}->{update}, 'update text'; + is $update->user->email, $test->{form_values}->{rznvy}, 'update user'; + is $update->state, 'confirmed', 'update confirmed'; + $mech->delete_user( $update->user ); + } + }; +} + +for my $test ( + { + desc => 'submit update for registered user', initial_values => { name => 'Test User', may_show_name => 1, @@ -600,7 +672,6 @@ for my $test ( fields => { submit_update => 1, update => 'update from a registered user', - may_show_name => undef, add_alert => undef, fixed => undef, }, @@ -610,10 +681,10 @@ for my $test ( initial_banner => '', endstate_banner => '', alert => 0, - anonymous => 1, + anonymous => 0, }, { - desc => 'submit update for registered user anonymously by deleting name', + desc => 'submit update for registered user anonymously by unchecking', initial_values => { name => 'Test User', may_show_name => 1, @@ -625,9 +696,8 @@ for my $test ( email => 'test@example.com', fields => { submit_update => 1, - name => '', update => 'update from a registered user', - may_show_name => 1, + may_show_name => undef, add_alert => undef, fixed => undef, }, |