diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-10 17:23:20 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-10 17:23:20 +0100 |
commit | 00177a5cd2ebbfeb08082712c1a1c392276c4a83 (patch) | |
tree | 8a27bed4bc193eaab663ffb623318d21eb4a3367 /t/app/controller/alert_new.t | |
parent | a1fa6aa37ce73e2a637e4bac565cd0a199f551e2 (diff) |
send out alert subscription email confirmations
Diffstat (limited to 't/app/controller/alert_new.t')
-rw-r--r-- | t/app/controller/alert_new.t | 96 |
1 files changed, 55 insertions, 41 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 3d1bfeabf..72467d31c 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -2,82 +2,96 @@ use strict; use warnings; use Test::More; - use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -foreach my $test ( +foreach my $test ( { - email => 'test@example.com', - type => 'area', - content => 'your alert will not be activated', + 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', + 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 => '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', + 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 => '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', + 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 => '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', + 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'; + ) +{ + subtest "$test->{type} alert correctly created" => sub { + $mech->clear_emails_ok; - # we don't want an alert - my $alert = FixMyStreet::App->model('DB::Alert')->find( { email => - $test->{email}, alert_type => $type } ); - $alert->delete() if $alert; + my $type = $test->{type} . '_problems'; - $mech->get_ok($test->{uri}); - $mech->content_contains($test->{content}); + # we don't want an alert + my $alert = FixMyStreet::App->model('DB::Alert')->find( + { + email => $test->{email}, + alert_type => $type + } + ); + $alert->delete() if $alert; - $alert = FixMyStreet::App->model('DB::Alert')->find( { email => - $test->{email}, alert_type => $type, parameter => - $test->{param1}, parameter2 => $test->{param2} } ); + $mech->get_ok( $test->{uri} ); + $mech->content_contains( $test->{content} ); - ok $alert, "Found the alert"; + $alert = FixMyStreet::App->model('DB::Alert')->find( + { + email => $test->{email}, + alert_type => $type, + parameter => $test->{param1}, + parameter2 => $test->{param2} + } + ); - SKIP: { - skip 'sending email not yet implemented', 4; + ok $alert, "Found the alert"; 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+)}; + my ( $url, $url_token ) = $email->body =~ m{(http://\S+/A/)(\S+)}; ok $url, "extracted confirm url '$url'"; + + my $token = FixMyStreet::App->model('DB::Token')->find( + { + token => $url_token, + scope => 'alert' + } + ); + ok $token, 'Token found in database'; + ok $alert->id == $token->data->{id}, 'token alertid matches alert id'; }; - }; } done_testing(); |