diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-19 17:11:37 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-19 17:11:37 +0100 |
commit | 2c3160b0fb07d9412925a3d57f4017c998de835e (patch) | |
tree | 8071a5be05d5ccb3c20c1bce4649400cf6b92b95 /t/app/controller | |
parent | 1463288a3282ec5d0f195e2ed44253b78f5b915b (diff) |
sign up logged in users for alerts as appropriate
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/report_updates.t | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 8f64f1109..182f3a244 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -262,37 +262,60 @@ subtest "submit an update for a non registered user" => sub { is $add_alerts, 0, 'do not sign up for alerts'; }; -subtest "submit an update for a registered user" => sub { - # clear out comments for this problem to make - # checking details easier later - ok( $_->delete, 'deleted comment ' . $_->id ) - for $report->comments; +for my $test ( + { + desc => 'submit update for register user', + fields => { + rznvy => 'test@example.com', + update => 'update from a registered user' + }, + alert => 0, + }, + { + desc => 'submit update for register user and sign up', + fields => { + rznvy => 'test@example.com', + update => 'update from a registered user', + add_alert => 1, + }, + alert => 1, + }, +) { + subtest $test->{desc} => sub { + # clear out comments for this problem to make + # checking details easier later + ok( $_->delete, 'deleted comment ' . $_->id ) + for $report->comments; - $mech->clear_emails_ok(); + $mech->clear_emails_ok(); - $mech->log_in_ok( $user->email ); - $mech->get_ok("/report/$report_id"); + $mech->log_in_ok( $user->email ); + $mech->get_ok("/report/$report_id"); - $mech->submit_form_ok( - { - with_fields => { - rznvy => 'test@example.com', - update => 'update from a registered user' - } - }, - 'submit update' - ); + $mech->submit_form_ok( + { + with_fields => $test->{fields}, + }, + 'submit update' + ); - is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; + is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; - $mech->email_count_is(0); + $mech->email_count_is(0); - my $update = $report->comments->first; - ok $update, 'found update'; - is $update->text, 'update from a registered user', 'update text'; - is $update->user->email, 'test@example.com', 'update user'; - is $update->state, 'confirmed', 'update confirmed'; -}; + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, $test->{fields}->{update}, 'update text'; + is $update->user->email, 'test@example.com', 'update user'; + is $update->state, 'confirmed', 'update confirmed'; + + my $alert = + FixMyStreet::App->model('DB::Alert') + ->find( { user => $user, alert_type => 'new_updates' } ); + + ok $test->{alert} ? $alert : !$alert, 'not signed up for alerts'; + }; +} ok $comment->delete, 'deleted comment'; $mech->delete_user('commenter@example.com'); |