diff options
author | Marius Halden <marius.h@lden.org> | 2020-09-29 14:23:52 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2020-09-29 14:23:52 +0200 |
commit | a27ce1524d801d2742a2bdb6ec1da45126d64353 (patch) | |
tree | 64123c4e17dc1776aa0a7cd65ee01d49d3e7d978 /t/script | |
parent | 377bd96aab7cad3434185c30eb908c9da447fe40 (diff) | |
parent | 2773c60226b9370fe8ee00f7b205b571bb87c3b5 (diff) |
Merge tag 'v3.0.1' into fiksgatami-dev
Diffstat (limited to 't/script')
-rw-r--r-- | t/script/createsuperuser.t | 23 | ||||
-rw-r--r-- | t/script/inactive.t | 81 |
2 files changed, 98 insertions, 6 deletions
diff --git a/t/script/createsuperuser.t b/t/script/createsuperuser.t new file mode 100644 index 000000000..1d4826111 --- /dev/null +++ b/t/script/createsuperuser.t @@ -0,0 +1,23 @@ +use Test::More; +use Test::Output; + +use_ok 'FixMyStreet::Script::CreateSuperuser'; + +stderr_like { FixMyStreet::Script::CreateSuperuser::createsuperuser(); } + qr/Specify a single email address/, 'Email error shown'; +stderr_is { FixMyStreet::Script::CreateSuperuser::createsuperuser('test@example.org'); } + "Specify a password for this new user.\n", 'Password error shown'; +stdout_is { FixMyStreet::Script::CreateSuperuser::createsuperuser('test@example.org', 'password'); } + "test\@example.org is now a superuser.\n", 'Correct message shown'; + +my $user = FixMyStreet::DB->resultset("User")->find({ email => 'test@example.org' }); +ok $user, 'user created'; +is $user->is_superuser, 1, 'is a superuser'; + +$user->update({ is_superuser => 0 }); +stdout_is { FixMyStreet::Script::CreateSuperuser::createsuperuser('test@example.org'); } + "test\@example.org is now a superuser.\n", 'Correct message shown'; +$user->discard_changes; +is $user->is_superuser, 1, 'is a superuser again'; + +done_testing; diff --git a/t/script/inactive.t b/t/script/inactive.t index 4667c989b..5ef4073dd 100644 --- a/t/script/inactive.t +++ b/t/script/inactive.t @@ -1,16 +1,17 @@ use FixMyStreet::TestMech; +use Test::Output; 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 $user = $mech->create_user_ok('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' }); +my $user_inactive = $mech->create_user_ok('inactive@example.com'); $t = DateTime->now->subtract(months => 4); $user_inactive->last_active($t); $user_inactive->update; @@ -22,6 +23,7 @@ for (my $m = 1; $m <= 12; $m++) { dt => $t, lastupdate => "$t", state => $m % 2 ? 'fixed - user' : 'confirmed', + cobrand => $m % 3 ? 'default' : 'bromley', }); } @@ -50,23 +52,90 @@ subtest 'Anonymization of inactive fixed/closed reports' => sub { is $comment->user->email, 'removed-automatically@example.org', 'Comment user anonymized'; }; +subtest 'Test operating on one cobrand only' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'bromley' + }, sub { + my $in = FixMyStreet::Script::Inactive->new( cobrand => 'bromley', close => 1 ); + $in->reports; + # Reports not a multiple of 2 are fixed, reports a multiple of 3 are bromley + $problems[2]->discard_changes; + is $problems[2]->get_extra_metadata('closed_updates'), 1, 'Closed to updates'; + $problems[4]->discard_changes; + is $problems[4]->get_extra_metadata('closed_updates'), undef, 'Not closed to updates'; + $problems[6]->discard_changes; + is $problems[6]->get_extra_metadata('closed_updates'), undef, 'Not closed to updates'; + $problems[8]->discard_changes; + is $problems[8]->get_extra_metadata('closed_updates'), 1, 'Closed to updates'; + }; +}; + 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'; - $mech->get_ok("/report/" . $problems[2]->id); + $problems[4]->discard_changes; + is $problems[4]->get_extra_metadata('closed_updates'), 1, 'Closed to updates'; + $mech->get_ok("/report/" . $problems[4]->id); $mech->content_contains('now closed to updates'); }; +subtest 'Deleting reports' => sub { + my $in = FixMyStreet::Script::Inactive->new( delete => 6 ); + $in->reports; + + my $count = FixMyStreet::DB->resultset("Problem")->count; + is $count, 6, 'Six left'; + + $mech->get("/report/" . $problems[2]->id); + is $mech->res->code, 404; +}; + subtest 'Anonymization of inactive users' => sub { - $in->users; + my $in = FixMyStreet::Script::Inactive->new( anonymize => 6, email => 3, verbose => 1 ); + stdout_is { $in->users } "Anonymizing user #" . $user->id . "\nEmailing user #" . $user_inactive->id . "\n", 'users dealt with first time'; my $email = $mech->get_email; like $email->as_string, qr/inactive\@example.com/, 'Inactive email sent'; + $mech->clear_emails_ok; $user->discard_changes; is $user->email, 'removed-' . $user->id . '@example.org', 'User has been anonymized'; + + stdout_is { $in->users } '', 'No output second time'; + + $mech->email_count_is(0); # No further email sent + + $user->discard_changes; + is $user->email, 'removed-' . $user->id . '@example.org', 'User has been anonymized'; +}; + +subtest 'Test TfL deletion of safety critical reports' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'tfl' + }, sub { + for (my $y = 2; $y <= 10; $y+=2) { + # 2 years, not safety; 4 years safety, 6 years not safety, 8 years safety, 10 years not safety + my $t = DateTime->now->subtract(years => $y); + my ($problem) = $mech->create_problems_for_body(1, 2237, 'Title', { + dt => $t, + lastupdate => "$t", + state => 'fixed - user', + cobrand => 'tfl', + }); + $problem->update_extra_field({ name => 'safety_critical', value => $y % 4 ? 'no' : 'yes' }); + $problem->update; + } + + my $in = FixMyStreet::Script::Inactive->new( cobrand => 'tfl', delete => 36 ); + $in->reports; + my $count = FixMyStreet::DB->resultset("Problem")->search({ cobrand => 'tfl' })->count; + is $count, 3, 'Three reports left, one too recent, two safety critical'; + + $in = FixMyStreet::Script::Inactive->new( cobrand => 'tfl', delete => 84 ); + $in->reports; + $count = FixMyStreet::DB->resultset("Problem")->search({ cobrand => 'tfl' })->count; + is $count, 2, 'Two reports left, two too recent'; + } }; done_testing; |