Split up the tests for mod actions and admin actions

This commit is contained in:
swag 2023-04-21 19:04:43 -04:00
parent 86a7d92156
commit 1c6e8811dc
2 changed files with 61 additions and 16 deletions

61
t/admin.t Normal file
View File

@ -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();

View File

@ -83,7 +83,6 @@ subtest Login => sub {
->element_exists('a[href*="/moderator/flagged"]' ) ->element_exists('a[href*="/moderator/flagged"]' )
->element_exists('a[href*="/moderator/hidden"]' ) ->element_exists('a[href*="/moderator/hidden"]' )
->element_exists('a[href*="/logout"]' ) ->element_exists('a[href*="/logout"]' )
->element_exists('a[href*="/moderator/admin/create"]' )
}; };
subtest Hidden => sub { subtest Hidden => sub {
@ -93,17 +92,6 @@ subtest Login => sub {
->element_exists('a[href*="/moderator/flagged"]' ) ->element_exists('a[href*="/moderator/flagged"]' )
->element_exists('a[href*="/moderator/hidden"]' ) ->element_exists('a[href*="/moderator/hidden"]' )
->element_exists('a[href*="/logout"]' ) ->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 # Mod session ends
@ -137,10 +125,6 @@ subtest Login => sub {
$t->get_ok('/moderator/hidden') $t->get_ok('/moderator/hidden')
->status_is(302) ->status_is(302)
->header_like(Location => qr/login/); ->header_like(Location => qr/login/);
$t->get_ok('/moderator/admin/create')
->status_is(302)
->header_like(Location => qr/login/);
}; };
}; };