PostText/t/moderator.t

164 lines
5.5 KiB
Perl
Raw Permalink Normal View History

2022-11-25 23:22:38 -05:00
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('PostText');
my %valid_login = (
email => 'swaggboi@gangstalking.agency',
password => 'i also like to party'
2022-11-25 23:22:38 -05:00
);
my %invalid_login = (
email => 'fuck@example.com',
password => 'ah fuck goddamn'
2022-11-25 23:22:38 -05:00
);
subtest Login => sub {
2022-11-27 23:56:35 -05:00
$t->get_ok('/login')
->status_is(200)
2022-11-28 15:31:56 -05:00
->element_exists('form input[name="email"]')
->element_exists('form input[name="password"]')
2022-11-27 23:56:35 -05:00
->text_like(h2 => qr/Moderator Login/);
$t->post_ok('/login', form => \%invalid_login)
->status_is(403)
2022-11-28 15:31:56 -05:00
->element_exists('form input[name="email"]')
->element_exists('form input[name="password"]')
2022-11-27 23:56:35 -05:00
->text_like(p => qr/Invalid login/);
2022-11-25 23:22:38 -05:00
$t->post_ok('/login', form => \%valid_login)
->status_is(302)
->header_like(Location => qr{moderator/flagged});
2022-11-25 23:22:38 -05:00
2022-11-28 23:33:19 -05:00
$t->get_ok('/login')
->status_is(302)
->header_like(Location => qr{moderator/flagged});
2022-11-28 23:33:19 -05:00
# Do these subs while logged in
subtest Flag => sub {
$t->get_ok('/moderator/thread/unflag/1')
->status_is(302)
2023-05-12 23:48:29 -04:00
->header_like(Location => qr{moderator/flagged});
$t->get_ok('/moderator/remark/unflag/1')
->status_is(302)
2023-05-12 23:48:29 -04:00
->header_like(Location => qr{moderator/flagged});
};
subtest Hide => sub {
$t->get_ok('/moderator/thread/hide/1')
->status_is(302)
2023-05-12 23:48:29 -04:00
->header_like(Location => qr{moderator/flagged});
2023-06-02 15:51:40 -04:00
$t->get_ok('/moderator/thread/single/1')
->status_is(200)
->text_like(h2 => qr/Thread #/);
$t->get_ok('/thread/single/1')
->status_is(404)
->text_like(p => qr/Thread not found/);
$t->get_ok('/moderator/thread/unhide/1')
->status_is(302)
2023-05-12 23:48:29 -04:00
->header_like(Location => qr{moderator/hidden});
$t->get_ok('/moderator/remark/hide/1')
->status_is(302)
2023-05-12 23:48:29 -04:00
->header_like(Location => qr{moderator/flagged});
2023-06-02 15:51:40 -04:00
$t->get_ok('/moderator/remark/single/1')
->status_is(200)
->text_like(h2 => qr/Remark #/);
$t->get_ok('/remark/single/1')
->status_is(404)
->text_like(p => qr/Remark not found/);
$t->get_ok('/moderator/remark/unhide/1')
->status_is(302)
2023-05-12 23:48:29 -04:00
->header_like(Location => qr{moderator/hidden});
};
subtest 'Buttons for mods', sub {
$t->get_ok('/thread/single/1')
->status_is(200)
->element_exists('a[href*="/hide/1"]' )
->element_exists('a[href*="/unhide/1"]')
->element_exists('a[href*="/unflag/1"]');
2022-12-08 14:29:55 -05:00
$t->get_ok('/remark/single/1')
->status_is(200)
->element_exists('a[href*="/hide/1"]' )
->element_exists('a[href*="/unhide/1"]')
->element_exists('a[href*="/unflag/1"]');
};
2022-12-08 17:10:11 -05:00
subtest Flagged => sub {
$t->get_ok('/moderator/flagged')
->status_is(200)
->text_like(h2 => qr/Flagged Posts/)
2023-04-21 21:40:39 -04:00
->element_exists('a[href*="/moderator/flagged"]')
->element_exists('a[href*="/moderator/hidden"]' )
->element_exists('a[href*="/logout"]' )
2022-12-08 17:10:11 -05:00
};
2022-12-08 19:50:21 -05:00
subtest Hidden => sub {
$t->get_ok('/moderator/hidden')
->status_is(200)
->text_like(h2 => qr/Hidden Posts/)
2023-04-21 21:40:39 -04:00
->element_exists('a[href*="/moderator/flagged"]')
->element_exists('a[href*="/moderator/hidden"]' )
->element_exists('a[href*="/logout"]' )
};
subtest Reset => sub {
$t->get_ok('/moderator/reset')
->status_is(200)
->text_like(h2 => qr/Reset Password/)
->element_exists('a[href*="/moderator/reset"]')
->element_exists('form input[name="password"]')
2022-12-08 19:50:21 -05:00
};
2022-12-08 17:10:11 -05:00
subtest List => sub {
$t->get_ok('/moderator/list')
->status_is(200)
->text_like(h2 => qr/Moderator List/)
};
2022-12-08 14:29:55 -05:00
# Mod session ends
2022-11-25 23:22:38 -05:00
$t->get_ok('/logout')
->status_is(302)
->header_like(Location => qr{thread/list});
subtest 'No mod, no buttons', sub {
$t->get_ok('/thread/single/1')
->status_is(200)
2023-01-10 00:45:31 -05:00
->element_exists_not('a[href*="/hide/1"]' )
->element_exists_not('a[href*="/unhide/1"]' )
->element_exists_not('a[href*="/unflag/1"]' )
->element_exists_not('a[href*="/moderator/flagged"]')
->element_exists_not('a[href*="/moderator/hidden"]' )
->element_exists_not('a[href*="/moderator/list"]' )
2023-01-10 00:45:31 -05:00
->element_exists_not('a[href*="/logout"]' );
$t->get_ok('/remark/single/1')
->status_is(200)
2023-01-10 00:45:31 -05:00
->element_exists_not('a[href*="/hide/1"]' )
->element_exists_not('a[href*="/unhide/1"]' )
->element_exists_not('a[href*="/unflag/1"]' )
->element_exists_not('a[href*="/moderator/flagged"]')
->element_exists_not('a[href*="/moderator/hidden"]' )
->element_exists_not('a[href*="/moderator/list"]' )
2023-01-10 00:45:31 -05:00
->element_exists_not('a[href*="/logout"]' );
2022-12-08 17:10:11 -05:00
$t->get_ok('/moderator/flagged')
->status_is(302)
->header_like(Location => qr/login/);
2022-12-08 19:50:21 -05:00
$t->get_ok('/moderator/hidden')
->status_is(302)
->header_like(Location => qr/login/);
$t->get_ok('/moderator/list')
->status_is(302)
->header_like(Location => qr/login/);
};
2022-11-25 23:22:38 -05:00
};
2023-04-25 22:28:11 -04:00
done_testing;