2023-04-21 23:04:43 +00:00
|
|
|
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/)
|
2023-04-22 01:40:39 +00:00
|
|
|
->element_exists('a[href*="/moderator/admin/create"]')
|
|
|
|
->element_exists('a[href*="/moderator/admin/reset"]' )
|
2023-04-21 23:04:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest Create => sub {
|
|
|
|
$t->get_ok('/moderator/admin/create')
|
|
|
|
->status_is(200)
|
|
|
|
->text_like(h2 => qr/Create Moderator/)
|
2023-04-22 01:40:39 +00:00
|
|
|
->element_exists('form input[name="name"]' )
|
|
|
|
->element_exists('form input[name="email"]' )
|
|
|
|
->element_exists('form input[name="password"]')
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest Reset => sub {
|
|
|
|
$t->get_ok('/moderator/admin/reset')
|
|
|
|
->status_is(200)
|
|
|
|
->text_like(h2 => qr/Reset Password/)
|
|
|
|
->element_exists('a[href*="/moderator/admin/reset"]')
|
2023-04-22 02:25:05 +00:00
|
|
|
->element_exists('form input[name="email"]' )
|
|
|
|
->element_exists('form input[name="password"]' )
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest Lock => sub {
|
|
|
|
$t->get_ok('/moderator/admin/lock')
|
|
|
|
->status_is(200)
|
|
|
|
->text_like(h2 => qr/Lock Account/)
|
|
|
|
->element_exists('a[href*="/moderator/admin/lock"]')
|
|
|
|
->element_exists('form input[name="email"]' )
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest Unlock => sub {
|
|
|
|
$t->get_ok('/moderator/admin/unlock')
|
|
|
|
->status_is(200)
|
|
|
|
->text_like(h2 => qr/Unlock Account/)
|
|
|
|
->element_exists('a[href*="/moderator/admin/unlock"]')
|
|
|
|
->element_exists('form input[name="email"]' )
|
2023-04-21 23:04:43 +00:00
|
|
|
};
|
|
|
|
|
2023-04-22 03:21:12 +00:00
|
|
|
subtest Promote => sub {
|
|
|
|
$t->get_ok('/moderator/admin/promote')
|
|
|
|
->status_is(200)
|
|
|
|
->text_like(h2 => qr/Promote Moderator/)
|
|
|
|
->element_exists('a[href*="/moderator/admin/promote"]')
|
|
|
|
->element_exists('form input[name="email"]' )
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest Demote => sub {
|
|
|
|
$t->get_ok('/moderator/admin/demote')
|
|
|
|
->status_is(200)
|
|
|
|
->text_like(h2 => qr/Demote Admin/)
|
|
|
|
->element_exists('a[href*="/moderator/admin/demote"]')
|
|
|
|
->element_exists('form input[name="email"]' )
|
|
|
|
};
|
|
|
|
|
2023-04-21 23:04:43 +00:00
|
|
|
# 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)
|
2023-04-22 03:21:12 +00:00
|
|
|
->element_exists_not('a[href*="/moderator/admin/create"]' )
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/reset"]' )
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/lock"]' )
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/unlock"]' )
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/promote"]')
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/demote"]' );
|
2023-04-21 23:04:43 +00:00
|
|
|
|
|
|
|
$t->get_ok('/remark/single/1')
|
|
|
|
->status_is(200)
|
2023-04-22 03:21:12 +00:00
|
|
|
->element_exists_not('a[href*="/moderator/admin/create"]' )
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/reset"]' )
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/lock"]' )
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/unlock"]' )
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/promote"]')
|
|
|
|
->element_exists_not('a[href*="/moderator/admin/demote"]' );
|
2023-04-21 23:04:43 +00:00
|
|
|
|
|
|
|
$t->get_ok('/moderator/admin/create')
|
|
|
|
->status_is(302)
|
|
|
|
->header_like(Location => qr/login/);
|
2023-04-22 02:25:05 +00:00
|
|
|
|
|
|
|
$t->get_ok('/moderator/admin/reset')
|
|
|
|
->status_is(302)
|
|
|
|
->header_like(Location => qr/login/);
|
|
|
|
|
|
|
|
$t->get_ok('/moderator/admin/lock')
|
|
|
|
->status_is(302)
|
|
|
|
->header_like(Location => qr/login/);
|
|
|
|
|
|
|
|
$t->get_ok('/moderator/admin/unlock')
|
|
|
|
->status_is(302)
|
|
|
|
->header_like(Location => qr/login/);
|
2023-04-22 03:21:12 +00:00
|
|
|
|
|
|
|
$t->get_ok('/moderator/admin/promote')
|
|
|
|
->status_is(302)
|
|
|
|
->header_like(Location => qr/login/);
|
|
|
|
|
|
|
|
$t->get_ok('/moderator/admin/demote')
|
|
|
|
->status_is(302)
|
|
|
|
->header_like(Location => qr/login/);
|
2023-04-21 23:04:43 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-04-26 02:28:11 +00:00
|
|
|
done_testing;
|