diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/my.t | 15 | ||||
-rw-r--r-- | t/app/controller/my_planned.t | 52 |
2 files changed, 61 insertions, 6 deletions
diff --git a/t/app/controller/my.t b/t/app/controller/my.t index d24a66c8e..00070ed81 100644 --- a/t/app/controller/my.t +++ b/t/app/controller/my.t @@ -10,16 +10,19 @@ $mech->get_ok('/my'); is $mech->uri->path, '/auth', "got sent to the sign in page"; $mech->create_problems_for_body(1, 1234, 'Test Title'); +my $other_user = FixMyStreet::DB->resultset('User')->find_or_create({ email => 'another@example.com' }); +$mech->create_problems_for_body(1, 1234, 'Another Title', { user => $other_user }); -# sign in my $user = $mech->log_in_ok( 'test@example.com' ); $mech->get_ok('/my'); -is $mech->uri->path, '/my', "stayed on '/my/' page"; +is $mech->uri->path, '/my', "stayed on '/my' page"; -# Report listed $mech->content_contains('Test Title'); +$mech->content_lacks('Another Title'); -# cleanup -$mech->delete_user( $user ); -$mech->delete_problems_for_body(1234); done_testing(); + +END { + $mech->delete_user($user); + $mech->delete_user($other_user); +} diff --git a/t/app/controller/my_planned.t b/t/app/controller/my_planned.t new file mode 100644 index 000000000..25f82224e --- /dev/null +++ b/t/app/controller/my_planned.t @@ -0,0 +1,52 @@ +use strict; +use warnings; + +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +$mech->get_ok('/my/planned'); +is $mech->uri->path, '/auth', "got sent to the sign in page"; + +my $body = $mech->create_body_ok(2237, 'Oxfordshire'); +my ($problem) = $mech->create_problems_for_body(1, $body->id, 'Test Title'); + +$mech->get_ok($problem->url); +$mech->content_lacks('Add to planned reports'); +$mech->content_lacks('Remove from planned reports'); + +my $user = $mech->log_in_ok( 'test@example.com' ); +$user->update({ from_body => $body }); +$user->user_body_permissions->find_or_create({ + body => $body, + permission_type => 'planned_reports', +}); + +$mech->get_ok('/my/planned'); +$mech->content_lacks('Test Title'); + +$user->add_to_planned_reports($problem); +$mech->get_ok('/my/planned'); +$mech->content_contains('Test Title'); + +$user->remove_from_planned_reports($problem); +$mech->get_ok('/my/planned'); +$mech->content_lacks('Test Title'); + +$user->add_to_planned_reports($problem); +$mech->get_ok('/my/planned'); +$mech->content_contains('Test Title'); + +$mech->get_ok($problem->url); +$mech->content_contains('Remove from planned reports'); +$mech->submit_form_ok({ with_fields => { change => 'remove' } }); +$mech->content_contains('Add to planned reports'); +$mech->submit_form_ok({ with_fields => { change => 'add' } }); +$mech->content_contains('Remove from planned reports'); + +done_testing(); + +END { + $mech->delete_user($user); +} |