diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/auth_profile.t | 67 | ||||
-rw-r--r-- | t/app/controller/report_new_text.t | 4 | ||||
-rw-r--r-- | t/app/controller/report_update_text.t | 2 |
3 files changed, 66 insertions, 7 deletions
diff --git a/t/app/controller/auth_profile.t b/t/app/controller/auth_profile.t index 224365eb6..de2ad6534 100644 --- a/t/app/controller/auth_profile.t +++ b/t/app/controller/auth_profile.t @@ -75,9 +75,68 @@ subtest "Test change password page" => sub { { form_name => 'change_password', fields => - { new_password => $test_password, confirm => $test_password, }, + { new_password => 'new_password', confirm => 'new_password', }, }, - "change_password with '$test_password' and '$test_password'" + "change_password with 'new_password' and 'new_password'" + ); + is $mech->uri->path, '/auth/change_password', + "still on change password page"; + $mech->content_contains('check your email'); + + $link = $mech->get_link_from_email; + $mech->get_ok($link); + is $mech->uri->path, '/my', "redirected to /my"; + + $mech->content_contains( 'password has been changed', + "found password changed" ); + + $user->discard_changes(); + ok $user->password, "user now has a password"; +}; + +# Change password, when already got one +subtest "Test change password page with current password" => sub { + $mech->get_ok('/auth/change_password'); + + ok my $form = $mech->form_name('change_password'), + "found change password form"; + is_deeply [ sort grep { $_ } map { $_->name } $form->inputs ], # + [ 'confirm', 'current_password', 'new_password', 'token' ], + "check we got expected fields (ie not old_password)"; + + # check the various ways the form can be wrong + for my $test ( + { current => '', new => '', conf => '', err => 'check the passwords', }, + { current => 'new_password', new => '', conf => '', err => 'enter a password', }, + { current => 'new_password', new => 'secret', conf => '', err => 'do not match', }, + { current => 'new_password', new => '', conf => 'secret', err => 'do not match', }, + { current => 'new_password', new => 'secret', conf => 'not_secret', err => 'do not match', }, + ) + { + $mech->get_ok('/auth/change_password'); + $mech->content_lacks( $test->{err}, "did not find expected error" ); + $mech->submit_form_ok( + { + form_name => 'change_password', + fields => + { current_password => $test->{current}, new_password => $test->{new}, confirm => $test->{conf}, }, + }, + "change_password with '$test->{current}', '$test->{new}' and '$test->{conf}'" + ); + $mech->content_contains( $test->{err}, "found expected error" ); + } + + my $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + ok $user, "got a user"; + + $mech->get_ok('/auth/change_password'); + $mech->submit_form_ok( + { + form_name => 'change_password', + fields => + { current_password => 'new_password', new_password => $test_password, confirm => $test_password }, + }, + "change_password with 'new_password' and '$test_password'" ); is $mech->uri->path, '/auth/change_password', "still on change password page"; @@ -92,12 +151,12 @@ subtest 'check password length/common' => sub { $mech->get_ok('/auth/change_password'); $mech->submit_form_ok({ form_name => 'change_password', - fields => { new_password => 'short', confirm => 'short' }, + fields => { current_password => $test_password, new_password => 'short', confirm => 'short' }, }); $mech->content_contains("Please make sure your password is at least"); $mech->submit_form_ok({ form_name => 'change_password', - fields => { new_password => 'common', confirm => 'common' }, + fields => { current_password => $test_password, new_password => 'common', confirm => 'common' }, }); $mech->content_contains("Please choose a less commonly-used password"); }; diff --git a/t/app/controller/report_new_text.t b/t/app/controller/report_new_text.t index 734b9dbb4..cb07e57ee 100644 --- a/t/app/controller/report_new_text.t +++ b/t/app/controller/report_new_text.t @@ -45,8 +45,8 @@ foreach my $test ( password_register => '', password_sign_in => '', }, changes => { - username => '+44 121 496 0000', - phone => '+44 121 496 0000', + username => '0121 496 0000', + phone => '0121 496 0000', }, errors => [ 'Please enter a mobile number', ], }, diff --git a/t/app/controller/report_update_text.t b/t/app/controller/report_update_text.t index 45b4e78c2..a3b767221 100644 --- a/t/app/controller/report_update_text.t +++ b/t/app/controller/report_update_text.t @@ -95,7 +95,7 @@ for my $test ( password_sign_in => '', }, changes => { - username => '+44 121 496 0000', + username => '0121 496 0000', }, field_errors => [ 'Please enter a mobile number' ] }, |