From 1c6e8811dc14b7499b7692e3bd145f238296eff8 Mon Sep 17 00:00:00 2001 From: swag Date: Fri, 21 Apr 2023 19:04:43 -0400 Subject: [PATCH] Split up the tests for mod actions and admin actions --- t/admin.t | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ t/moderator.t | 16 -------------- 2 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 t/admin.t diff --git a/t/admin.t b/t/admin.t new file mode 100644 index 0000000..1d01e77 --- /dev/null +++ b/t/admin.t @@ -0,0 +1,61 @@ +use Mojo::Base -strict; +use Test::More; +use Test::Mojo; + +my $t = Test::Mojo->new('PostText'); + +my %valid_login = ( + email => 'swaggboi@slackware.uk', + password => 'i like to party' + ); + +subtest Login => sub { + $t->post_ok('/login', form => \%valid_login) + ->status_is(302) + ->header_like(Location => qr{moderator/flagged}); + + $t->get_ok('/login') + ->status_is(302) + ->header_like(Location => qr{moderator/flagged}); + + # Do these subs while logged in + subtest 'Buttons for admins', sub { + $t->get_ok('/moderator/flagged') + ->status_is(200) + ->text_like(h2 => qr/Flagged Posts/) + ->element_exists('a[href*="/moderator/admin/create"]' ); + + $t->get_ok('/moderator/hidden') + ->status_is(200) + ->text_like(h2 => qr/Hidden Posts/) + ->element_exists('a[href*="/moderator/admin/create"]' ); + }; + + subtest Create => sub { + $t->get_ok('/moderator/admin/create') + ->status_is(200) + ->text_like(h2 => qr/Create Moderator/) + ->element_exists('a[href*="/moderator/admin/create"]' ) + }; + + # Admin session ends + $t->get_ok('/logout') + ->status_is(302) + ->header_like(Location => qr{thread/list}); + + subtest 'No admin, no buttons', sub { + $t->get_ok('/thread/single/1') + ->status_is(200) + ->element_exists_not('a[href*="/moderator/admin/create"]' ); + + $t->get_ok('/remark/single/1') + ->status_is(200) + ->element_exists_not('a[href*="/moderator/admin/create"]' ); + + $t->get_ok('/moderator/admin/create') + ->status_is(302) + ->header_like(Location => qr/login/); + }; +}; + +done_testing(); diff --git a/t/moderator.t b/t/moderator.t index 7c7f52b..41fcb08 100644 --- a/t/moderator.t +++ b/t/moderator.t @@ -83,7 +83,6 @@ subtest Login => sub { ->element_exists('a[href*="/moderator/flagged"]' ) ->element_exists('a[href*="/moderator/hidden"]' ) ->element_exists('a[href*="/logout"]' ) - ->element_exists('a[href*="/moderator/admin/create"]' ) }; subtest Hidden => sub { @@ -93,17 +92,6 @@ subtest Login => sub { ->element_exists('a[href*="/moderator/flagged"]' ) ->element_exists('a[href*="/moderator/hidden"]' ) ->element_exists('a[href*="/logout"]' ) - ->element_exists('a[href*="/moderator/admin/create"]' ) - }; - - subtest Create => sub { - $t->get_ok('/moderator/admin/create') - ->status_is(200) - ->text_like(h2 => qr/Create Moderator/) - ->element_exists('a[href*="/moderator/flagged"]' ) - ->element_exists('a[href*="/moderator/hidden"]' ) - ->element_exists('a[href*="/logout"]' ) - ->element_exists('a[href*="/moderator/admin/create"]' ) }; # Mod session ends @@ -137,10 +125,6 @@ subtest Login => sub { $t->get_ok('/moderator/hidden') ->status_is(302) ->header_like(Location => qr/login/); - - $t->get_ok('/moderator/admin/create') - ->status_is(302) - ->header_like(Location => qr/login/); }; };