aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/controller/admin/report_edit.t46
-rw-r--r--t/app/model/defecttype.t21
-rw-r--r--t/app/model/responsepriority.t18
-rw-r--r--t/app/model/responsetemplate.t28
-rw-r--r--t/app/model/session.t14
-rw-r--r--t/script/inactive.t71
6 files changed, 157 insertions, 41 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/defecttype.t b/t/app/model/defecttype.t
index 4f380db59..e924129e2 100644
--- a/t/app/model/defecttype.t
+++ b/t/app/model/defecttype.t
@@ -99,27 +99,6 @@ subtest 'by_categories returns defect types for an area with multiple bodies' =>
is scalar @$pavements, 3, 'Pavements have 3 defect types';
};
-subtest 'by_categories encodes HTML entities' => sub {
- my $apostrophe_defect_type = FixMyStreet::App->model('DB::DefectType')->find_or_create(
- {
- body_id => $oxfordshire->id,
- name => 'This defect type\'s name has an apostrophe',
- description => 'This defect type is for all categories'
- }
- );
- $apostrophe_defect_type->set_extra_metadata('defect_code' => 'Here\'s an apostrophe');
- $apostrophe_defect_type->update();
-
- my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all;
- my $defect_types = FixMyStreet::App->model('DB::DefectType')->by_categories($area_id, @contacts);
- my $traffic_lights = decode_json($defect_types->{'Traffic lights'});
- my $defect_type = @$traffic_lights[2];
- is $defect_type->{name}, 'This defect type's name has an apostrophe';
- is $defect_type->{extra}->{defect_code}, 'Here's an apostrophe';
-
-};
-
-
END {
done_testing();
}
diff --git a/t/app/model/responsepriority.t b/t/app/model/responsepriority.t
index 03c5bccae..4e624bf07 100644
--- a/t/app/model/responsepriority.t
+++ b/t/app/model/responsepriority.t
@@ -78,24 +78,6 @@ subtest 'by_categories returns all response priorities for an area with multiple
is scalar @$traffic_lights, 2, 'Traffic lights have 2 defect types';
};
-subtest 'by_categories encodes HTML entities' => sub {
- FixMyStreet::App->model('DB::ResponsePriority')->find_or_create(
- {
- body_id => $other_body->id,
- name => 'This priority\'s name has an apostrophe',
- description => 'This priority is for all categories'
- }
- );
-
- my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all;
- my $priorities = FixMyStreet::App->model('DB::ResponsePriority')->by_categories($area_id, @contacts);
-
- my $traffic_lights = decode_json($priorities->{'Traffic lights'});
- use Data::Dumper;
- my $priority = @$traffic_lights[2];
- is $priority->{name}, 'This priority's name has an apostrophe';
-};
-
END {
$mech->delete_body( $other_body );
$mech->delete_body( $oxfordshire );
diff --git a/t/app/model/responsetemplate.t b/t/app/model/responsetemplate.t
new file mode 100644
index 000000000..fbabc1c12
--- /dev/null
+++ b/t/app/model/responsetemplate.t
@@ -0,0 +1,28 @@
+use FixMyStreet::TestMech;
+use JSON::MaybeXS;
+
+my $mech = FixMyStreet::TestMech->new;
+my $area_id = 2651;
+
+my $body = $mech->create_body_ok($area_id, 'Edinburgh Council');
+my $c1 = $mech->create_contact_ok(category => 'Potholes', body_id => $body->id, email => 'p');
+my $c2 = $mech->create_contact_ok(category => 'Graffiti', body_id => $body->id, email => 'g');
+my $t1 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 1", text => "Text 1" });
+my $t2 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 2", text => "Text 2", state => 'investigating' });
+my $t3 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 3", text => "Text 3" });
+$t1->add_to_contacts($c1);
+$t2->add_to_contacts($c2);
+
+my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $body->id ] } )->all;
+
+subtest 'by_categories returns allresponse templates grouped by category' => sub {
+ my $templates = FixMyStreet::App->model('DB::ResponseTemplate')->by_categories($area_id, @contacts);
+ my $potholes = decode_json($templates->{Potholes});
+ my $graffiti = decode_json($templates->{Graffiti});
+
+ is scalar @$potholes, 2, 'Potholes have 2 templates';
+ is scalar @$graffiti, 2, 'Graffiti has 2 templates';
+ is $graffiti->[0]->{state}, 'investigating', 'Graffiti first template has right state';
+};
+
+done_testing;
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;