diff options
author | Struan Donald <struan@exo.org.uk> | 2011-06-01 17:28:37 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-06-01 17:28:37 +0100 |
commit | a2d9fe2659a1723824c58d7e3d663d1725bcab56 (patch) | |
tree | d97483d84bbc4a5333407aafb6cde0a2f863ae0f /t/app/controller | |
parent | e14a8bc6d38d48941628a6239c57385fcf7c7e00 (diff) |
mark new_updates alerts as confirmed when they are created
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/report_updates.t | 156 |
1 files changed, 100 insertions, 56 deletions
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 72a120b0e..4f7d1628d 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -270,73 +270,117 @@ for my $test ( }; } -subtest "submit an update for a non registered user" => sub { - $mech->log_out_ok(); - $mech->clear_emails_ok(); +for my $test ( + { + desc => 'submit an update for a non registered user', + initial_values => { + name => '', + rznvy => '', + may_show_name => undef, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + form_values => { + submit_update => 1, + rznvy => 'unregistered@example.com', + update => 'Update from an unregistered user', + add_alert => undef, + }, + changes => {}, + }, + { + desc => 'submit an update for a non registered user and sign up', + initial_values => { + name => '', + rznvy => '', + may_show_name => undef, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + form_values => { + submit_update => 1, + rznvy => 'unregistered@example.com', + update => 'update from an unregistered user', + add_alert => 1, + }, + changes => { + update => 'Update from an unregistered user', + }, + } +) { + subtest $test->{desc} => sub { + $mech->log_out_ok(); + $mech->clear_emails_ok(); - $mech->get_ok("/report/$report_id"); + $mech->get_ok("/report/$report_id"); - my $values = $mech->visible_form_values('updateForm'); - - is_deeply $values, - { - name => '', - rznvy => '', - may_show_name => undef, - add_alert => 1, - photo => '', - update => '', - fixed => undef, - }, - 'initial form values'; - - $mech->submit_form_ok( - { - with_fields => { - submit_update => 1, - rznvy => 'unregistered@example.com', - update => 'update from an unregistered user', - add_alert => undef, + my $values = $mech->visible_form_values('updateForm'); + + is_deeply $values, $test->{initial_values}, 'initial form values'; + + $mech->submit_form_ok( + { + with_fields => $test->{form_values} + }, + 'submit update' + ); + + $mech->content_contains('Nearly Done! Now check your email'); + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the update you/i, "Correct email text"; + + my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)}; + ok $url, "extracted confirm url '$url'"; + + my $token = FixMyStreet::App->model('DB::Token')->find( + { + token => $url_token, + scope => 'comment' } - }, - 'submit update' - ); + ); + ok $token, 'Token found in database'; - $mech->content_contains('Nearly Done! Now check your email'); + my $update_id = $token->data->{id}; + my $add_alerts = $token->data->{add_alert}; + my $update = + FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } ); - my $email = $mech->get_email; - ok $email, "got an email"; - like $email->body, qr/confirm the update you/i, "Correct email text"; + my $details = { + %{ $test->{form_values} }, + %{ $test->{changes} } + }; - my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)}; - ok $url, "extracted confirm url '$url'"; + ok $update, 'found update in database'; + is $update->state, 'unconfirmed', 'update unconfirmed'; + is $update->user->email, $details->{rznvy}, 'update email'; + is $update->text, $details->{update}, 'update text'; + is $add_alerts, $details->{add_alert} ? 1 : 0, 'do not sign up for alerts'; - my $token = FixMyStreet::App->model('DB::Token')->find( - { - token => $url_token, - scope => 'comment' - } - ); - ok $token, 'Token found in database'; + $mech->get_ok( $url . $url_token ); + $mech->content_contains("/report/$report_id#$update_id"); - my $update_id = $token->data->{id}; - my $add_alerts = $token->data->{add_alert}; - my $update = - FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } ); + my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } ); - ok $update, 'found update in database'; - is $update->state, 'unconfirmed', 'update unconfirmed'; - is $update->user->email, 'unregistered@example.com', 'update email'; - is $update->text, 'Update from an unregistered user', 'update text'; - is $add_alerts, 0, 'do not sign up for alerts'; + ok $unreg_user, 'found user'; - $mech->get_ok( $url . $url_token ); - $mech->content_contains("/report/$report_id#$update_id"); + my $alert = FixMyStreet::App->model( 'DB::Alert' )->find( + { user => $unreg_user, alert_type => 'new_updates', confirmed => 1, } + ); - $update->discard_changes; + ok $details->{add_alert} ? defined( $alert ) : !defined( $alert ), 'sign up for alerts'; - is $update->state, 'confirmed', 'update confirmed'; -}; + $update->discard_changes; + + is $update->state, 'confirmed', 'update confirmed'; + $mech->delete_user( $unreg_user ); + }; +} for my $test ( { @@ -519,7 +563,7 @@ for my $test ( my $alert = FixMyStreet::App->model('DB::Alert') - ->find( { user => $user, alert_type => 'new_updates' } ); + ->find( { user => $user, alert_type => 'new_updates', confirmed => 1 } ); ok $test->{alert} ? $alert : !$alert, 'not signed up for alerts'; }; |