diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/admin/report_edit.t | 46 | ||||
-rw-r--r-- | t/app/model/session.t | 14 | ||||
-rw-r--r-- | t/script/inactive.t | 71 |
3 files changed, 129 insertions, 2 deletions
diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t index 0a4e702bb..5e3e6c315 100644 --- a/t/app/controller/admin/report_edit.t +++ b/t/app/controller/admin/report_edit.t @@ -79,6 +79,7 @@ foreach my $test ( anonymous => 0, flagged => undef, non_public => undef, + closed_updates => undef, }, changes => { title => 'Edited Report', }, log_entries => [qw/edit/], @@ -95,6 +96,7 @@ foreach my $test ( anonymous => 0, flagged => undef, non_public => undef, + closed_updates => undef, }, changes => { detail => 'Edited Detail', }, log_entries => [qw/edit edit/], @@ -111,6 +113,7 @@ foreach my $test ( anonymous => 0, flagged => undef, non_public => undef, + closed_updates => undef, }, changes => { name => 'Edited User', }, log_entries => [qw/edit edit edit/], @@ -128,6 +131,7 @@ foreach my $test ( anonymous => 0, flagged => undef, non_public => undef, + closed_updates => undef, }, changes => { flagged => 'on', @@ -147,6 +151,7 @@ foreach my $test ( anonymous => 0, flagged => 'on', non_public => undef, + closed_updates => undef, }, changes => { username => $user2->email, }, log_entries => [qw/edit edit edit edit edit/], @@ -164,6 +169,7 @@ foreach my $test ( anonymous => 0, flagged => 'on', non_public => undef, + closed_updates => undef, }, expect_comment => 1, changes => { state => 'unconfirmed' }, @@ -181,6 +187,7 @@ foreach my $test ( anonymous => 0, flagged => 'on', non_public => undef, + closed_updates => undef, }, expect_comment => 1, changes => { state => 'confirmed' }, @@ -198,6 +205,7 @@ foreach my $test ( anonymous => 0, flagged => 'on', non_public => undef, + closed_updates => undef, }, expect_comment => 1, changes => { state => 'fixed' }, @@ -216,6 +224,7 @@ foreach my $test ( anonymous => 0, flagged => 'on', non_public => undef, + closed_updates => undef, }, expect_comment => 1, changes => { state => 'hidden' }, @@ -235,6 +244,7 @@ foreach my $test ( anonymous => 0, flagged => 'on', non_public => undef, + closed_updates => undef, }, expect_comment => 1, changes => { @@ -257,6 +267,7 @@ foreach my $test ( anonymous => 1, flagged => 'on', non_public => undef, + closed_updates => undef, }, changes => {}, log_entries => [ @@ -275,6 +286,7 @@ foreach my $test ( anonymous => 1, flagged => 'on', non_public => undef, + closed_updates => undef, }, changes => { non_public => 'on', @@ -285,6 +297,24 @@ foreach my $test ( resend => 0, }, { + description => 'close to updates', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + username => $user2->email, + anonymous => 1, + flagged => 'on', + non_public => 'on', + closed_updates => undef, + }, + changes => { closed_updates => 'on' }, + log_entries => [ + qw/edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ + ], + }, + { description => 'change state to investigating as body superuser', fields => { title => 'Edited Report', @@ -295,12 +325,13 @@ foreach my $test ( anonymous => 1, flagged => 'on', non_public => 'on', + closed_updates => undef, }, expect_comment => 1, user_body => $oxfordshire, changes => { state => 'investigating' }, log_entries => [ - qw/edit state_change edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ + qw/edit state_change edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ ], resend => 0, }, @@ -315,13 +346,14 @@ foreach my $test ( anonymous => 1, flagged => 'on', non_public => 'on', + closed_updates => undef, }, expect_comment => 1, expected_text => '*Category changed from ‘Other’ to ‘Potholes’*', user_body => $oxfordshire, changes => { state => 'in progress', category => 'Potholes' }, log_entries => [ - qw/edit state_change edit state_change edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ + qw/edit state_change edit state_change edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ ], resend => 0, }, @@ -371,6 +403,15 @@ foreach my $test ( $test->{changes}->{flagged} = 1 if $test->{changes}->{flagged}; $test->{changes}->{non_public} = 1 if $test->{changes}->{non_public}; + if ($test->{changes}->{closed_updates}) { + is $report->get_extra_metadata('closed_updates'), 1, "closed_updates updated"; + $mech->get_ok("/report/$report_id"); + $mech->content_lacks('Provide an update'); + $report->unset_extra_metadata('closed_updates'); + $report->update; + delete $test->{changes}->{closed_updates}; + } + is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'username' } keys %{ $test->{changes} }; if ( $test->{user} ) { @@ -451,6 +492,7 @@ subtest 'change email to new user' => sub { anonymous => 1, flagged => 'on', non_public => 'on', + closed_updates => undef, external_id => '13', external_body => '', external_team => '', diff --git a/t/app/model/session.t b/t/app/model/session.t new file mode 100644 index 000000000..f76533727 --- /dev/null +++ b/t/app/model/session.t @@ -0,0 +1,14 @@ +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +$mech->log_in_ok('test@example.com'); + +my $session = FixMyStreet::DB->resultset("Session")->first; + +my $id = $session->id; +$id =~ s/\s+$//; +is $id, "session:" . $session->id_code; +is $session->user->email, 'test@example.com'; + +done_testing; diff --git a/t/script/inactive.t b/t/script/inactive.t new file mode 100644 index 000000000..4d78b385f --- /dev/null +++ b/t/script/inactive.t @@ -0,0 +1,71 @@ +use FixMyStreet::TestMech; + +use_ok 'FixMyStreet::Script::Inactive'; + +my $in = FixMyStreet::Script::Inactive->new( anonymize => 6, email => 3 ); +my $mech = FixMyStreet::TestMech->new; + +my $user = FixMyStreet::DB->resultset("User")->find_or_create({ email => 'test@example.com' }); +my $t = DateTime->new(year => 2016, month => 1, day => 1, hour => 12); +$user->last_active($t); +$user->update; + +my $user_inactive = FixMyStreet::DB->resultset("User")->find_or_create({ email => 'inactive@example.com' }); +$t = DateTime->now->subtract(months => 4); +$user_inactive->last_active($t); +$user_inactive->update; + +my @problems; +for (my $m = 1; $m <= 12; $m++) { + my $t = DateTime->new(year => 2017, month => $m, day => 1, hour => 12); + push @problems, $mech->create_problems_for_body(1, 2237, 'Title', { + dt => $t, + lastupdate => "$t", + state => $m % 2 ? 'fixed - user' : 'confirmed', + }); +} + +$mech->create_comment_for_problem($problems[0], $user, 'Name', 'Update', 0, 'confirmed', $problems[0]->state); +FixMyStreet::DB->resultset("Alert")->create({ alert_type => 'new_updates', parameter => $problems[2]->id, user => $user }); + +subtest 'Anonymization of inactive fixed/closed reports' => sub { + $in->reports; + + my $count = FixMyStreet::DB->resultset("Problem")->search({ user_id => $user->id })->count; + is $count, 6, 'Six non-anonymised'; + + my $comment = FixMyStreet::DB->resultset("Comment")->first; + my $alert = FixMyStreet::DB->resultset("Alert")->first; + is $comment->anonymous, 1, 'Comment anonymized'; + is $comment->user->email, 'removed-automatically@example.org', 'Comment user anonymized'; + is $alert->user->email, 'removed-automatically@example.org', 'Alert anonymized'; + isnt $alert->whendisabled, undef, 'Alert disabled'; + + $mech->create_comment_for_problem($problems[0], $user, 'Name 2', 'Update', 0, 'confirmed', $problems[0]->state); + $comment = FixMyStreet::DB->resultset("Comment")->search({ name => 'Name 2' })->first; + + $in->reports; + $comment->discard_changes; + is $comment->anonymous, 1, 'Comment anonymized'; + is $comment->user->email, 'removed-automatically@example.org', 'Comment user anonymized'; +}; + +subtest 'Closing updates on inactive fixed/closed reports' => sub { + my $in = FixMyStreet::Script::Inactive->new( close => 1 ); + $in->reports; + $problems[2]->discard_changes; + is $problems[2]->get_extra_metadata('closed_updates'), 1, 'Closed to updates'; + # TODO Visit page, check closed for updates +}; + +subtest 'Anonymization of inactive users' => sub { + $in->users; + + my $email = $mech->get_email; + like $email->as_string, qr/inactive\@example.com/, 'Inactive email sent'; + + $user->discard_changes; + is $user->email, 'removed-' . $user->id . '@example.org', 'User has been anonymized'; +}; + +done_testing; |