aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model/user.t
blob: 5a9c898a27982b7cedd834947dcdae79e0799f3d (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use FixMyStreet::TestMech;
use FixMyStreet::DB;

my $mech = FixMyStreet::TestMech->new();
$mech->log_in_ok('test@example.com');

my ($problem) = $mech->create_problems_for_body(1, '2504', 'Title', { anonymous => 'f' });
is $problem->user->latest_anonymity, 0, "User's last report was not anonymous";

FixMyStreet::override_config {
    ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
    MAPIT_URL => 'http://mapit.uk/',
}, sub {
    $mech->get_ok('/around?pc=sw1a1aa');
    $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
    $mech->content_like(qr/may_show_name[^>]*checked/);
};

($problem) = $mech->create_problems_for_body(1, '2504', 'Title', { anonymous => 't' });
is $problem->user->latest_anonymity, 1, "User's last report was anonymous";

create_update($problem, anonymous => 'f');
is $problem->user->latest_anonymity, 0, "User's last update was not anonyous";

create_update($problem, anonymous => 't');
is $problem->user->latest_anonymity, 1, "User's last update was anonymous";

subtest "Sign user up for alerts" => sub {
    my $user = $problem->user;

    my $alert_exists =  $user->alert_for_problem( $problem->id );
    is !defined( $alert_exists ), 1, "No current alerts exist";

    my $options = {
      cobrand      => 'default',
      lang         => 'en-gb',
    };
    $user->create_alert($problem->id, $options);
    my $alert = $user->alert_for_problem( $problem->id );

    is defined( $alert ), 1, "User is signed up for alerts";
    is $alert->confirmed, 1, "Alert is confirmed";

    $alert->delete();

    $user->alerts->create({
        alert_type   => 'new_updates',
        parameter    => $problem->id,
    });

    $user->create_alert($problem->id, $options);

    my $new_alert = $user->alert_for_problem( $problem->id );
    is $alert->confirmed, 1, "Already created alert is confirmed";
};

FixMyStreet::override_config {
    ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
    MAPIT_URL => 'http://mapit.uk/',
}, sub {
    $mech->get_ok('/around?pc=sw1a1aa');
    $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
    $mech->content_like(qr/may_show_name[^>c]*>/);
};

END {
    done_testing();
}

sub create_update {
    my ($problem, %params) = @_;
    my $dt = DateTime->now()->add(days => 1);
    return FixMyStreet::App->model('DB::Comment')->find_or_create({
        problem_id => $problem->id,
        user_id => $problem->user_id,
        name => 'Other User',
        mark_fixed => 'false',
        text => 'This is some update text',
        state => 'confirmed',
        anonymous => 'f',
        created => $dt->ymd . ' ' . $dt->hms,
        %params,
    });
}