diff options
author | Struan Donald <struan@exo.org.uk> | 2018-04-19 15:58:02 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2018-06-25 10:12:25 +0100 |
commit | 7c009ce048fbe36db24dd1a24f3542503db2e898 (patch) | |
tree | dba5f5e7d0b4bab9a5d3565781fe1bbd12aff807 /t | |
parent | 43ef59400d632c3c29321c6908128932a31148a7 (diff) |
add a send login email button to user edit page
Add a button to the user edit page that sends a login token email to the
user. Helpful for user support situations where someone is having
trouble logging in. Also for situations where you have added a user and
want to get them logged in.
Fixes #2041
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/admin/users.t | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t index 0d8290c37..37d95feed 100644 --- a/t/app/controller/admin/users.t +++ b/t/app/controller/admin/users.t @@ -401,6 +401,71 @@ FixMyStreet::override_config { $user = $mech->create_user_ok('test@example.com', name => 'Test User'); +subtest "Send login email from admin" => sub { + $mech->email_count_is(0); + $mech->get_ok( '/admin/user_edit/' . $user->id ); + $mech->submit_form_ok( + { + button => 'send_login_email' + }, + "send login email form submitted" + ); + + my $email = $mech->get_email; + ok $email, "got an email"; + + is $email->header('Subject'), "Your FixMyStreet account details", + "subject is correct"; + is $email->header('To'), $user->email, "to is correct"; + + my $link = $mech->get_link_from_email($email); + + my $mech2 = FixMyStreet::TestMech->new; + $mech2->not_logged_in_ok; + $mech2->get_ok($link); + $mech2->logged_in_ok; + $mech2->log_out_ok; + + $mech->clear_emails_ok; +}; + +subtest "Send login email from admin for unverified email" => sub { + $user->update( { email_verified => 0 } ); + $mech->email_count_is(0); + $mech->get_ok( '/admin/user_edit/' . $user->id ); + $mech->submit_form_ok( + { + button => 'send_login_email' + }, + "send login email form submitted" + ); + + my $email = $mech->get_email; + ok $email, "got an email"; + + is $email->header('Subject'), "Your FixMyStreet account details", + "subject is correct"; + is $email->header('To'), 'test@example.com', "to is correct"; + + my $link = $mech->get_link_from_email($email); + + my $mech2 = FixMyStreet::TestMech->new; + $mech2->not_logged_in_ok; + $mech2->get_ok($link); + $mech2->logged_in_ok; + + my $test_user = FixMyStreet::DB->resultset('User')->search({ + email => $user->email + }, { order_by => [ { -desc => 'id' } ] } ); + $user->discard_changes; + + is $test_user->count, 1, "only one user"; + is $test_user->first->id, $user->id, "User is same"; + ok $user->email_verified, 'email is verified now'; + $mech2->log_out_ok; + $user->update( { email_verified => 1 } ); +}; + subtest "Anonymizing user from admin" => sub { $mech->create_problems_for_body(4, 2237, 'Title'); my $count_p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->count; |