aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/admin/users.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/admin/users.t')
-rw-r--r--t/app/controller/admin/users.t172
1 files changed, 151 insertions, 21 deletions
diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t
index 8759e260d..e2c922a23 100644
--- a/t/app/controller/admin/users.t
+++ b/t/app/controller/admin/users.t
@@ -19,7 +19,7 @@ subtest 'search abuse' => sub {
};
subtest 'remove user from abuse list from edit user page' => sub {
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
$mech->content_contains('User in abuse table');
$mech->click_ok('unban');
@@ -31,7 +31,7 @@ subtest 'remove user from abuse list from edit user page' => sub {
subtest 'remove user with phone account from abuse list from edit user page' => sub {
my $abuse_user = $mech->create_user_ok('01234 456789');
my $abuse = FixMyStreet::App->model('DB::Abuse')->find_or_create( { email => $abuse_user->phone } );
- $mech->get_ok( '/admin/user_edit/' . $abuse_user->id );
+ $mech->get_ok( '/admin/users/' . $abuse_user->id );
$mech->content_contains('User in abuse table');
my $abuse_found = FixMyStreet::App->model('DB::Abuse')->find( { email => $abuse_user->phone } );
ok $abuse_found, 'user in abuse table';
@@ -45,7 +45,7 @@ subtest 'remove user with phone account from abuse list from edit user page' =>
subtest 'no option to remove user already in abuse list' => sub {
my $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $user->email } );
$abuse->delete if $abuse;
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
$mech->content_lacks('User in abuse table');
};
@@ -66,11 +66,11 @@ subtest 'user search' => sub {
$mech->content_contains( $user->name);
my $u_id = $user->id;
- $mech->content_like( qr{user_edit/$u_id">Edit</a>} );
+ $mech->content_like( qr{users/$u_id">Edit</a>} );
$mech->get_ok('/admin/users?search=' . $user->email);
- $mech->content_like( qr{user_edit/$u_id">Edit</a>} );
+ $mech->content_like( qr{users/$u_id">Edit</a>} );
$user->from_body($haringey->id);
$user->update;
@@ -96,7 +96,7 @@ subtest 'user_edit does not show user from another council' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'oxfordshire' ],
}, sub {
- $mech->get('/admin/user_edit/' . $user->id);
+ $mech->get('/admin/users/' . $user->id);
ok !$mech->res->is_success(), "want a bad response";
is $mech->res->code, 404, "got 404";
};
@@ -168,14 +168,17 @@ for my $test (
my %default_perms = (
"permissions[moderate]" => undef,
"permissions[planned_reports]" => undef,
+ "permissions[report_mark_private]" => undef,
"permissions[report_edit]" => undef,
"permissions[report_edit_category]" => undef,
"permissions[report_edit_priority]" => undef,
"permissions[report_inspect]" => undef,
"permissions[report_instruct]" => undef,
+ "permissions[report_prefill]" => undef,
"permissions[contribute_as_another_user]" => undef,
"permissions[contribute_as_anonymous_user]" => undef,
"permissions[contribute_as_body]" => undef,
+ "permissions[default_to_body]" => undef,
"permissions[view_body_contribute_details]" => undef,
"permissions[user_edit]" => undef,
"permissions[user_manage_permissions]" => undef,
@@ -206,7 +209,7 @@ FixMyStreet::override_config {
phone_verified => undef,
flagged => undef,
is_superuser => undef,
- area_id => '',
+ area_ids => undef,
%default_perms,
},
changes => {
@@ -226,7 +229,7 @@ FixMyStreet::override_config {
phone_verified => undef,
flagged => undef,
is_superuser => undef,
- area_id => '',
+ area_ids => undef,
%default_perms,
},
changes => {
@@ -246,7 +249,7 @@ FixMyStreet::override_config {
phone_verified => undef,
flagged => undef,
is_superuser => undef,
- area_id => '',
+ area_ids => undef,
%default_perms,
},
changes => {
@@ -266,7 +269,7 @@ FixMyStreet::override_config {
phone_verified => undef,
flagged => undef,
is_superuser => undef,
- area_id => '',
+ area_ids => undef,
%default_perms,
},
changes => {
@@ -286,7 +289,7 @@ FixMyStreet::override_config {
phone_verified => undef,
flagged => 'on',
is_superuser => undef,
- area_id => '',
+ area_ids => undef,
%default_perms,
},
changes => {
@@ -306,7 +309,7 @@ FixMyStreet::override_config {
phone_verified => undef,
flagged => undef,
is_superuser => undef,
- area_id => '',
+ area_ids => undef,
%default_perms,
},
changes => {
@@ -329,7 +332,7 @@ FixMyStreet::override_config {
phone_verified => undef,
flagged => undef,
is_superuser => 'on',
- area_id => '',
+ area_ids => undef,
},
changes => {
is_superuser => undef,
@@ -342,7 +345,7 @@ FixMyStreet::override_config {
},
) {
subtest $test->{desc} => sub {
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
my $visible = $mech->visible_form_values;
is_deeply $visible, $test->{fields}, 'expected user';
@@ -378,7 +381,7 @@ FixMyStreet::override_config {
SMS_AUTHENTICATION => 1,
}, sub {
subtest "Test edit user add verified phone" => sub {
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
$mech->submit_form_ok( { with_fields => {
phone => '+61491570157',
phone_verified => 1,
@@ -390,9 +393,9 @@ FixMyStreet::override_config {
my $existing_user = $mech->create_user_ok('existing@example.com', name => 'Existing User');
$mech->create_problems_for_body(2, 2514, 'Title', { user => $existing_user });
my $count = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->count;
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
$mech->submit_form_ok( { with_fields => { email => 'existing@example.com' } }, 'submit email change' );
- is $mech->uri->path, '/admin/user_edit/' . $existing_user->id, 'redirected';
+ is $mech->uri->path, '/admin/users/' . $existing_user->id, 'redirected';
my $p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $existing_user->id })->count;
is $p, $count + 2, 'reports merged';
};
@@ -401,11 +404,76 @@ 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/users/' . $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/users/' . $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;
my $count_u = FixMyStreet::DB->resultset('Comment')->search({ user_id => $user->id })->count;
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
$mech->submit_form_ok({ button => 'anon_everywhere' });
my $c = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id, anonymous => 1 })->count;
is $c, $count_p;
@@ -416,7 +484,7 @@ subtest "Anonymizing user from admin" => sub {
subtest "Hiding user's reports from admin" => sub {
my $count_p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->count;
my $count_u = FixMyStreet::DB->resultset('Comment')->search({ user_id => $user->id })->count;
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
$mech->submit_form_ok({ button => 'hide_everywhere' });
my $c = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id, state => 'hidden' })->count;
is $c, $count_p;
@@ -429,7 +497,7 @@ subtest "Logging user out" => sub {
$mech2->log_in_ok($user->email);
$mech2->logged_in_ok;
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
$mech->submit_form_ok({ button => 'logout_everywhere' }, 'Logging user out');
$mech2->not_logged_in_ok;
};
@@ -438,7 +506,7 @@ subtest "Removing account from admin" => sub {
$mech->create_problems_for_body(4, 2237, 'Title');
my $count_p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->count;
my $count_u = FixMyStreet::DB->resultset('Comment')->search({ user_id => $user->id })->count;
- $mech->get_ok( '/admin/user_edit/' . $user->id );
+ $mech->get_ok( '/admin/users/' . $user->id );
$mech->submit_form_ok({ button => 'remove_account' }, 'Removing account');
my $c = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id, anonymous => 1, name => '' })->count;
is $c, $count_p, 'All reports anon/nameless';
@@ -450,4 +518,66 @@ subtest "Removing account from admin" => sub {
is $user->email, 'removed-' . $user->id . '@example.org', 'Email gone'
};
+subtest "can view list of user's alerts" => sub {
+ $mech->get_ok( '/admin/users/' . $user->id );
+ $mech->content_lacks("User's alerts", 'no list of alerts');
+
+ $mech->create_problems_for_body(1, 2514, 'Title', { user => $user });
+ my $p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->first;
+
+ my $alert = FixMyStreet::DB->resultset('Alert')->find_or_create({
+ user_id => $user->id,
+ alert_type => 'new_updates',
+ parameter => $p->id
+ });
+
+
+ $mech->get_ok( '/admin/users/' . $user->id );
+ $mech->content_contains("User's alerts", 'has list of alerts');
+ $mech->content_contains($alert->id, 'lists alert');
+};
+
+subtest "can edit list of user's alerts" => sub {
+ $mech->get_ok( '/admin/users/' . $user->id );
+
+ my $alert = FixMyStreet::DB->resultset('Alert')->search({
+ user_id => $user->id,
+ alert_type => 'new_updates',
+ })->first;
+
+ $mech->content_like(qr[<td>${\$alert->id}</td>\s*<td>new_updates</td>]m, 'alert on page');
+
+ $mech->submit_form_ok( {
+ with_fields => {
+ 'edit_alert[' . $alert->id . ']' => 'disable'
+ }
+ }, 'disabling alert');
+
+ $alert->discard_changes;
+ ok $alert->whendisabled, 'alert disabled';
+
+ $mech->submit_form_ok( {
+ with_fields => {
+ 'edit_alert[' . $alert->id . ']' => 'enable'
+ }
+ }, 'enabling alert');
+
+ $alert->discard_changes;
+ is $alert->whendisabled, undef, 'alert enabled';
+
+ $mech->submit_form_ok( {
+ with_fields => {
+ 'edit_alert[' . $alert->id . ']' => 'delete',
+ }
+ }, 'deleting alert');
+
+ $mech->content_unlike(qr[<td>${\$alert->id}</td>\s*<td>new_updates</td>]m, 'alert not on page');
+
+ is $user->alerts->count, 0, 'alert deleted';
+};
+
+subtest "View timeline" => sub {
+ $mech->get_ok('/admin/timeline');
+};
+
done_testing();