Tests for Moderator

This commit is contained in:
swag 2022-11-25 23:22:38 -05:00
parent 82dae0cf89
commit 9f51c4dad9
3 changed files with 32 additions and 4 deletions

View File

@ -33,7 +33,6 @@ Run the tests locally (against development environment):
## TODOs ## TODOs
1. Actions for creating moderators and resetting passwords 1. Actions for creating moderators and resetting passwords
1. Tests for Moderator
1. CSS 1. CSS
## Crazy future ideas ## Crazy future ideas

View File

@ -26,10 +26,10 @@ sub login($self) {
$email = $self->param('email' ); $email = $self->param('email' );
$password = $self->param('password'); $password = $self->param('password');
$mod_id = $self->moderator->get_id($email);
$mod_name = $self->moderator->get_name($mod_id);
if ($self->moderator->check($email, $password)) { if ($self->moderator->check($email, $password)) {
$mod_id = $self->moderator->get_id($email);
$mod_name = $self->moderator->get_name($mod_id);
$self->session(mod_id => $mod_id); $self->session(mod_id => $mod_id);
$self->flash(info => "Hello, $mod_name 😎"); $self->flash(info => "Hello, $mod_name 😎");

29
t/moderator.t Normal file
View File

@ -0,0 +1,29 @@
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'
);
my %invalid_login = (
email => 'fuck@example.com',
password => 'ah fuck'
);
subtest Login => sub {
$t->post_ok('/login', form => \%invalid_login)->status_is(403);
$t->post_ok('/login', form => \%valid_login)
->status_is(302)
->header_like(Location => qr{moderator/list});
$t->get_ok('/logout')
->status_is(302)
->header_like(Location => qr{thread/list});
};
done_testing();