aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2011-08-09 18:33:52 +0100
committerMatthew Somerville <matthew@mysociety.org>2011-08-09 18:33:52 +0100
commiteb9fdecc08f346b17c6cf9334a74fe13af69b716 (patch)
tree72f2ecada6ea6978a089dc36335d20dd023e8bd3 /t/app/controller
parenta4bfd8e348a5d589c7a3886cd5fe11bd12f17c6d (diff)
parent223c035294f0f3a79ae341349f8f78ffdf61ccd5 (diff)
Merge branch 'admin_abuse_additions'
Diffstat (limited to 't/app/controller')
-rw-r--r--t/app/controller/admin.t195
-rw-r--r--t/app/controller/contact.t11
2 files changed, 192 insertions, 14 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 4e2ec82fe..8d55bbc18 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -233,6 +233,7 @@ foreach my $test (
name => 'Test User',
email => $user->email,
anonymous => 0,
+ flagged => undef,
},
changes => {
title => 'Edited Report',
@@ -250,6 +251,7 @@ foreach my $test (
name => 'Test User',
email => $user->email,
anonymous => 0,
+ flagged => undef,
},
changes => {
detail => 'Edited Detail',
@@ -267,6 +269,7 @@ foreach my $test (
name => 'Test User',
email => $user->email,
anonymous => 0,
+ flagged => undef,
},
changes => {
name => 'Edited User',
@@ -277,7 +280,7 @@ foreach my $test (
user => $user,
},
{
- description => 'edit report user email',
+ description => 'edit report set flagged true',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
@@ -285,13 +288,33 @@ foreach my $test (
name => 'Edited User',
email => $user->email,
anonymous => 0,
+ flagged => undef,
},
changes => {
- email => $user2->email,
+ flagged => 'on',
},
log_count => 4,
log_entries => [ qw/edit edit edit edit/ ],
resend => 0,
+ user => $user,
+ },
+ {
+ description => 'edit report user email',
+ fields => {
+ title => 'Edited Report',
+ detail => 'Edited Detail',
+ state => 'confirmed',
+ name => 'Edited User',
+ email => $user->email,
+ anonymous => 0,
+ flagged => 'on',
+ },
+ changes => {
+ email => $user2->email,
+ },
+ log_count => 5,
+ log_entries => [ qw/edit edit edit edit edit/ ],
+ resend => 0,
user => $user2,
},
{
@@ -303,12 +326,13 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'unconfirmed'
},
- log_count => 5,
- log_entries => [ qw/state_change edit edit edit edit/ ],
+ log_count => 6,
+ log_entries => [ qw/state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -320,12 +344,13 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'confirmed'
},
- log_count => 6,
- log_entries => [ qw/state_change state_change edit edit edit edit/ ],
+ log_count => 7,
+ log_entries => [ qw/state_change state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -337,12 +362,13 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'fixed'
},
- log_count => 7,
- log_entries => [ qw/state_change state_change state_change edit edit edit edit/ ],
+ log_count => 8,
+ log_entries => [ qw/state_change state_change state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -354,12 +380,13 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'hidden'
},
- log_count => 8,
- log_entries => [ qw/state_change state_change state_change state_change edit edit edit edit/ ],
+ log_count => 9,
+ log_entries => [ qw/state_change state_change state_change state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -371,13 +398,14 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'confirmed',
anonymous => 1,
},
- log_count => 10,
- log_entries => [ qw/edit state_change state_change state_change state_change state_change edit edit edit edit/ ],
+ log_count => 11,
+ log_entries => [ qw/edit state_change state_change state_change state_change state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -389,11 +417,12 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 1,
+ flagged => 'on',
},
changes => {
},
- log_count => 11,
- log_entries => [ qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit/ ],
+ log_count => 12,
+ log_entries => [ qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit edit/ ],
resend => 1,
},
) {
@@ -426,6 +455,7 @@ foreach my $test (
$mech->content_lacks( 'type="submit" name="resend"', 'no resend button' );
}
+ $test->{changes}->{flagged} = 1 if $test->{changes}->{flagged};
is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'email' } keys %{ $test->{changes} };
if ( $test->{user} ) {
@@ -449,6 +479,7 @@ subtest 'change email to new user' => sub {
name => $report->name,
email => $report->user->email,
anonymous => 1,
+ flagged => 'on',
};
is_deeply( $mech->visible_form_values(), $fields, 'initial form values' );
@@ -488,6 +519,65 @@ subtest 'change email to new user' => sub {
is $report->user_id, $user3->id, 'user changed to new user';
};
+subtest 'adding email to abuse list from report page' => sub {
+ my $email = $report->user->email;
+
+ my $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ $abuse->delete if $abuse;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Ban email address');
+
+ $mech->click_ok('banuser');
+
+ $mech->content_contains('Email added to abuse list');
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+
+ $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ ok $abuse, 'entry created in abuse table';
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+};
+
+subtest 'flagging user from report page' => sub {
+ $report->user->flagged(0);
+ $report->user->update;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Flag user');
+
+ $mech->click_ok('flaguser');
+
+ $mech->content_contains('User flagged');
+ $mech->content_contains('Remove flag');
+
+ $report->discard_changes;
+ ok $report->user->flagged, 'user flagged';
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Remove flag');
+};
+
+subtest 'unflagging user from report page' => sub {
+ $report->user->flagged(1);
+ $report->user->update;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Remove flag');
+
+ $mech->click_ok('removeuserflag');
+
+ $mech->content_contains('User flag removed');
+ $mech->content_contains('Flag user');
+
+ $report->discard_changes;
+ ok !$report->user->flagged, 'user not flagged';
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Flag user');
+};
+
$log_entries->delete;
my $update = FixMyStreet::App->model('DB::Comment')->create(
@@ -668,6 +758,65 @@ subtest 'editing update email creates new user if required' => sub {
is $update->user->id, $user->id, 'update set to new user';
};
+subtest 'adding email to abuse list from update page' => sub {
+ my $email = $update->user->email;
+
+ my $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ $abuse->delete if $abuse;
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Ban email address');
+
+ $mech->click_ok('banuser');
+
+ $mech->content_contains('Email added to abuse list');
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+
+ $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ ok $abuse, 'entry created in abuse table';
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+};
+
+subtest 'flagging user from update page' => sub {
+ $update->user->flagged(0);
+ $update->user->update;
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Flag user');
+
+ $mech->click_ok('flaguser');
+
+ $mech->content_contains('User flagged');
+ $mech->content_contains('Remove flag');
+
+ $update->discard_changes;
+ ok $update->user->flagged, 'user flagged';
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Remove flag');
+};
+
+subtest 'unflagging user from update page' => sub {
+ $update->user->flagged(1);
+ $update->user->update;
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Remove flag');
+
+ $mech->click_ok('removeuserflag');
+
+ $mech->content_contains('User flag removed');
+ $mech->content_contains('Flag user');
+
+ $update->discard_changes;
+ ok !$update->user->flagged, 'user not flagged';
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Flag user');
+};
+
subtest 'hiding comment marked as fixed reopens report' => sub {
$update->mark_fixed( 1 );
$update->update;
@@ -724,6 +873,24 @@ subtest 'report search' => sub {
$mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $r_id \s* </td>}xs );
};
+subtest 'search abuse' => sub {
+ $mech->get_ok( '/admin/search_abuse?search=example' );
+
+ $mech->content_contains('test4@example.com');
+};
+
+subtest 'show flagged entries' => sub {
+ $report->flagged( 1 );
+ $report->update;
+
+ $user->flagged( 1 );
+ $user->update;
+
+ $mech->get_ok('/admin/list_flagged');
+ $mech->content_contains( $report->title );
+ $mech->content_contains( $user->email );
+};
+
$mech->delete_user( $user );
$mech->delete_user( $user2 );
$mech->delete_user( $user3 );
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index bbb3a0f83..86b845eb3 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -248,6 +248,9 @@ for my $test (
)
{
subtest 'check email sent correctly' => sub {
+ $problem_main->discard_changes;
+ ok !$problem_main->flagged, 'problem not flagged';
+
$mech->clear_emails_ok;
if ($test->{fields}{id}) {
$mech->get_ok('/contact?id=' . $test->{fields}{id});
@@ -267,6 +270,14 @@ for my $test (
my $problem_id = $test->{fields}{id};
like $email->body, qr/Complaint about report $problem_id/, 'reporting a report'
if $test->{fields}{id};
+
+ $problem_main->discard_changes;
+ if ( $problem_id ) {
+ ok $problem_main->flagged, 'problem flagged';
+ } else {
+ ok !$problem_main->flagged, 'problem not flagged';
+ }
+
};
}