aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/alert_new.t
blob: 3d1bfeabf8ce150148583b664f3419afea8d0a75 (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
use strict;
use warnings;
use Test::More;


use FixMyStreet::TestMech;

my $mech = FixMyStreet::TestMech->new;

foreach my $test ( 
    {
        email => 'test@example.com',
        type  => 'area',
        content => 'your alert will not be activated',
        email_text => 'confirm the alert',
        uri   =>
        '/alert/subscribe?type=local&rznvy=test@example.com&feed=area:1000:A_Location',
        param1 => 1000
    },
    {
        email => 'test@example.com',
        type  => 'council',
        content => 'your alert will not be activated',
        email_text => 'confirm the alert',
        uri   =>
        '/alert/subscribe?type=local&rznvy=test@example.com&feed=council:1000:A_Location',
        param1 => 1000,
        param2 => 1000,
    },
    {
        email => 'test@example.com',
        type  => 'ward',
        content => 'your alert will not be activated',
        email_text => 'confirm the alert',
        uri   =>
        '/alert/subscribe?type=local&rznvy=test@example.com&feed=ward:1000:1001:A_Location:Diff_Location',
        param1 => 1000,
        param2 => 1001,
    },
    {
        email => 'test@example.com',
        type  => 'local',
        content => 'your alert will not be activated',
        email_text => 'confirm the alert',
        uri   =>
        '/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1',
        param1 => 10.2,
        param2 => 20.1,
    }
) {
  subtest "$test->{type} alert correctly created" => sub {
    $mech->clear_emails_ok;

    my $type = $test->{type} . '_problems';

    # we don't want an alert 
    my $alert = FixMyStreet::App->model('DB::Alert')->find( { email =>
        $test->{email}, alert_type => $type } );
    $alert->delete() if $alert;

    $mech->get_ok($test->{uri});
    $mech->content_contains($test->{content});

    $alert = FixMyStreet::App->model('DB::Alert')->find( { email =>
        $test->{email}, alert_type => $type, parameter =>
        $test->{param1}, parameter2 => $test->{param2} } );

    ok $alert, "Found the alert";

    SKIP: {
        skip 'sending email not yet implemented', 4;

        my $email = $mech->get_email;
        ok $email, "got an email";
        like $email->body, qr/$test->{email_text}/i, "Correct email text";

        my ($url) = $email->body =~ m{(http://\S+)};
        ok $url, "extracted confirm url '$url'";
    };
  };
}

done_testing();