aboutsummaryrefslogtreecommitdiffstats
path: root/t/script/inactive.t
blob: 0eaeea2adaf4deaa2fe11c8afb3fc704d582030c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;

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;