diff options
Diffstat (limited to 't/app/controller/admin')
-rw-r--r-- | t/app/controller/admin/bodies.t | 53 | ||||
-rw-r--r-- | t/app/controller/admin/defecttypes.t | 25 | ||||
-rw-r--r-- | t/app/controller/admin/permissions.t | 30 | ||||
-rw-r--r-- | t/app/controller/admin/report_edit.t | 26 | ||||
-rw-r--r-- | t/app/controller/admin/reportextrafields.t | 66 | ||||
-rw-r--r-- | t/app/controller/admin/search.t | 2 | ||||
-rw-r--r-- | t/app/controller/admin/users.t | 172 |
7 files changed, 342 insertions, 32 deletions
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t index a485d286d..f67e45bf6 100644 --- a/t/app/controller/admin/bodies.t +++ b/t/app/controller/admin/bodies.t @@ -1,9 +1,17 @@ +package FixMyStreet::Cobrand::Tester; + +use parent 'FixMyStreet::Cobrand::Default'; + +sub enable_category_groups { 1 } + +package main; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1); $mech->log_in_ok( $superuser->email ); +my $body = $mech->create_body_ok(2650, 'Aberdeen City Council'); # This override is wrapped around ALL the /admin/body tests FixMyStreet::override_config { @@ -12,7 +20,6 @@ FixMyStreet::override_config { BASE_URL => 'http://www.example.org', }, sub { -my $body = $mech->create_body_ok(2650, 'Aberdeen City Council'); $mech->get_ok('/admin/body/' . $body->id); $mech->content_contains('Aberdeen City Council'); $mech->content_like(qr{AB\d\d}); @@ -56,6 +63,7 @@ subtest 'check contact creation' => sub { subtest 'check contact editing' => sub { $mech->get_ok('/admin/body/' . $body->id .'/test%20category'); + $mech->content_lacks( 'group</strong> is used for the top-level category' ); $mech->submit_form_ok( { with_fields => { email => 'test2@example.com', @@ -201,4 +209,47 @@ subtest 'check text output' => sub { }; # END of override wrap +FixMyStreet::override_config { + ALLOWED_COBRANDS => ['tester'], + MAPIT_URL => 'http://mapit.uk/', + MAPIT_TYPES => [ 'UTA' ], + BASE_URL => 'http://www.example.org', +}, sub { + subtest 'group editing works' => sub { + $mech->get_ok('/admin/body/' . $body->id); + $mech->content_contains( 'group</strong> is used for the top-level category' ); + + $mech->submit_form_ok( { with_fields => { + category => 'grouped category', + email => 'test@example.com', + note => 'test note', + group => 'group a', + non_public => undef, + state => 'unconfirmed', + } } ); + + my $contact = $body->contacts->find({ category => 'grouped category' }); + is $contact->get_extra_metadata('group'), 'group a', "group stored correctly"; + }; + + subtest 'group can be unset' => sub { + $mech->get_ok('/admin/body/' . $body->id); + $mech->content_contains( 'group</strong> is used for the top-level category' ); + + $mech->submit_form_ok( { with_fields => { + category => 'grouped category', + email => 'test@example.com', + note => 'test note', + group => undef, + non_public => undef, + state => 'unconfirmed', + } } ); + + my $contact = $body->contacts->find({ category => 'grouped category' }); + is $contact->get_extra_metadata('group'), undef, "group unset correctly"; + }; + +}; + + done_testing(); diff --git a/t/app/controller/admin/defecttypes.t b/t/app/controller/admin/defecttypes.t index e7d0e42af..12ae8948c 100644 --- a/t/app/controller/admin/defecttypes.t +++ b/t/app/controller/admin/defecttypes.t @@ -1,4 +1,5 @@ use FixMyStreet::TestMech; +use Test::MockModule; my $mech = FixMyStreet::TestMech->new; @@ -26,8 +27,32 @@ FixMyStreet::override_config { ALLOWED_COBRANDS => ['bromley'], }, sub { FixMyStreet::override_config { ALLOWED_COBRANDS => ['oxfordshire'], }, sub { + my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Oxfordshire'); + $cobrand->mock('available_permissions', sub { + my $self = shift; + + my $perms = FixMyStreet::Cobrand::Default->available_permissions; + $perms->{Bodies}->{defect_type_edit} = "Add/edit defect types"; + + return $perms; + }); + my $body = $mech->create_body_ok( 2237, 'Oxfordshire County Council' ); + subtest 'check defect types menu available to superusers' => sub { + my $user = $mech->create_user_ok( + 'superuser@example.com', + name => 'Test Superuser', + is_superuser => 1 + ); + + $mech->log_in_ok( $user->email ); + $mech->get_ok('/admin'); + $mech->content_contains('Defect Types'); + $mech->get_ok('/admin/defecttypes'); + $mech->log_out_ok(); + }; + my $user = $mech->create_user_ok( 'oxford@example.com', name => 'Test User', diff --git a/t/app/controller/admin/permissions.t b/t/app/controller/admin/permissions.t index 7944cc0b1..ff5a8ec4f 100644 --- a/t/app/controller/admin/permissions.t +++ b/t/app/controller/admin/permissions.t @@ -1,4 +1,5 @@ use FixMyStreet::TestMech; +use Test::MockModule; my $mech = FixMyStreet::TestMech->new; @@ -28,6 +29,13 @@ ok $report, "created test report - $report_id"; $mech->log_in_ok( $oxfordshireuser->email ); +my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Oxfordshire'); +$cobrand->mock('available_permissions', sub { + my $self = shift; + + return FixMyStreet::Cobrand::Default->available_permissions; +}); + subtest "Users can't edit report without report_edit permission" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'oxfordshire' ], @@ -91,7 +99,7 @@ FixMyStreet::override_config { my $p = $perm ? 'with' : 'without'; my $r = $report->user eq $user2 ? 'with' : 'without'; subtest "User $u edit user for $b $p permission, $r cobrand relation" => sub { - $mech->get("/admin/user_edit/$user2_id"); + $mech->get("/admin/users/$user2_id"); my $success = $mech->res->is_success(); ok $result == 200 ? $success : !$success, "got correct response"; is $mech->res->code, $result, "got $result"; @@ -100,13 +108,23 @@ FixMyStreet::override_config { } } + subtest "Users can't edit users of their own council without permission" => sub { + $mech->get_ok("/admin/users/$user2_id"); + $mech->submit_form_ok( { with_fields => { + email => $user2->email, + } } ); + $user2->discard_changes; + # Make sure we haven't lost the from_body info + is $user2->from_body->id, $oxfordshire->id; + }; + $oxfordshireuser->user_body_permissions->create({ body => $oxfordshire, permission_type => 'user_assign_body', }); subtest "Users can edit users of their own council" => sub { - $mech->get_ok("/admin/user_edit/$user2_id"); + $mech->get_ok("/admin/users/$user2_id"); $mech->content_contains( $user2->name ); # We shouldn't be able to see the permissions tick boxes @@ -131,7 +149,7 @@ FixMyStreet::override_config { subtest "Users can edit permissions" => sub { is $user2->user_body_permissions->count, 0, 'user2 has no permissions'; - $mech->get_ok("/admin/user_edit/$user2_id"); + $mech->get_ok("/admin/users/$user2_id"); $mech->content_contains('Moderate report details'); $mech->submit_form_ok( { with_fields => { @@ -163,8 +181,9 @@ FixMyStreet::override_config { subtest "Unsetting user from_body removes all permissions and area " => sub { is $user2->user_body_permissions->count, 1, 'user2 has 1 permission'; + $user2->update({ area_ids => [123] }); # Set to check cleared - $mech->get_ok("/admin/user_edit/$user2_id"); + $mech->get_ok("/admin/users/$user2_id"); $mech->content_contains('Moderate report details'); $mech->submit_form_ok( { with_fields => { @@ -186,8 +205,9 @@ FixMyStreet::override_config { "permissions[user_assign_areas]" => undef, } } ); + $user2->discard_changes; is $user2->user_body_permissions->count, 0, 'user2 has had permissions removed'; - is $user2->area_id, undef, 'user2 has had area removed'; + is $user2->area_ids, undef, 'user2 has had area removed'; }; }; diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t index 5e3e6c315..c6e03ff7e 100644 --- a/t/app/controller/admin/report_edit.t +++ b/t/app/controller/admin/report_edit.t @@ -608,6 +608,32 @@ subtest "Test display of report extra data" => sub { $mech->content_contains('extra_field</strong>: this is extra data'); }; +subtest "Test alert count display" => sub { + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->content_contains('Alerts: 0'); + + my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( + { + alert_type => 'new_updates', + parameter => $report_id, + user => $user, + } + ); + + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->content_contains('Alerts: 0', 'does not include unconfirmed reports'); + + $alert->update( { confirmed => 1 } ); + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->content_contains('Alerts: 1'); + + $alert->update( { whendisabled => \"now()" } ); + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->content_contains('Alerts: 0'); + + $alert->delete; +}; + my $report2 = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'SW1A 1AA', diff --git a/t/app/controller/admin/reportextrafields.t b/t/app/controller/admin/reportextrafields.t index fb06665f4..e02df864f 100644 --- a/t/app/controller/admin/reportextrafields.t +++ b/t/app/controller/admin/reportextrafields.t @@ -120,12 +120,42 @@ FixMyStreet::override_config { $contact->update; }; + subtest 'check contact updating does not remove server_set' => sub { + $contact->set_extra_fields(({ code => 'POT', automated => 'server_set' })); + $contact->update; + + $mech->get_ok("/admin/body/" . $body->id . "/" . $contact->category); + $mech->submit_form_ok( { with_fields => { + email => 'test4@example.com', + note => 'test4 note', + } } ); + + $mech->content_like(qr'test4@example.com's); + + $contact->discard_changes; + my $meta_data = $contact->get_extra_fields; + is $contact->email, 'test4@example.com', 'contact updated'; + is_deeply $meta_data, [ { + order => 0, + datatype => 'string', + datatype_description => '', + description => '', + required => 'false', + variable => 'true', + code => 'POT', + automated => 'server_set' + } ], "automated fields not unset"; + }; + + subtest 'Create and update new ReportExtraFields' => sub { my $extra_fields = []; - my $model = FixMyStreet::App->model('DB::ReportExtraFields'); + my $model = FixMyStreet::App->model('DB::ReportExtraField'); is $model->count, 0, 'no ReportExtraFields yet'; + $mech->get_ok("/admin/reportextrafields"); + $mech->get_ok("/admin/reportextrafields/new"); $mech->submit_form_ok({ with_fields => { name => "Test extra fields", @@ -181,11 +211,39 @@ FixMyStreet::override_config { { name => "name1", key => "key1" }, ] }; + $object->discard_changes; is_deeply $object->get_extra_fields, $extra_fields, 'new list field was added'; is $object->language, "en-gb", "Correct language was set"; $mech->get_ok("/admin/reportextrafields/" . $object->id); + $mech->submit_form_ok({ with_fields => { + "metadata[2].order" => "3", + "metadata[2].code" => "automated_test", + "metadata[2].required" => undef, + "metadata[2].notice" => "", + "metadata[2].description" => "", + "metadata[2].datatype_description" => "", + "metadata[2].datatype" => "string", + "metadata[2].automated" => "server_set", + }}); + + push @$extra_fields, { + order => "3", + code => "automated_test", + required => "false", + variable => "true", + description => "", + datatype_description => "", + datatype => "string", + automated => "server_set", + }; + + $object->discard_changes; + is_deeply $object->get_extra_fields, $extra_fields, 'new automated field was added'; + is $object->language, "en-gb", "Correct language was set"; + + $mech->get_ok("/admin/reportextrafields/" . $object->id); $mech->submit_form_ok( { with_fields => { "metadata[1].values[1].key" => "key2", "metadata[1].values[1].name" => "name2", @@ -233,7 +291,7 @@ FixMyStreet::override_config { LANGUAGES => [ 'en-gb,English,en_GB' ] }, sub { subtest "Extra fields are missing from cobrand that doesn't allow them" => sub { - my $object = FixMyStreet::App->model('DB::ReportExtraFields')->first; + my $object = FixMyStreet::App->model('DB::ReportExtraField')->first; $object->update({ language => "", cobrand => ""}); $mech->get_ok("/report/new?longitude=-1.351488&latitude=51.847235&category=" . $contact->category); @@ -242,7 +300,7 @@ FixMyStreet::override_config { }; }; -FixMyStreet::App->model('DB::ReportExtraFields')->delete_all; +FixMyStreet::App->model('DB::ReportExtraField')->delete_all; $mech->log_out_ok; subtest 'Reports are created with correct extra metadata' => sub { @@ -250,7 +308,7 @@ subtest 'Reports are created with correct extra metadata' => sub { ALLOWED_COBRANDS => [ 'tester' ], MAPIT_URL => 'http://mapit.uk/', }, sub { - my $model = FixMyStreet::App->model('DB::ReportExtraFields'); + my $model = FixMyStreet::App->model('DB::ReportExtraField'); my $extra_fields = $model->find_or_create({ name => "Test extra fields", language => "", diff --git a/t/app/controller/admin/search.t b/t/app/controller/admin/search.t index 497ac9fd6..f8e70cb7a 100644 --- a/t/app/controller/admin/search.t +++ b/t/app/controller/admin/search.t @@ -103,7 +103,7 @@ subtest 'report search' => sub { $update->update; $mech->get_ok('/admin/reports?search=' . $report->user->email); - $mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $u_id \s* </td>}xs ); + $mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td[^>]*> \s* $u_id \s* </td>}xs ); $report->state('hidden'); $report->update; 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(); |