From 9f51c4dad99f8db9bc696e0a6299094f8c64ff37 Mon Sep 17 00:00:00 2001 From: swag Date: Fri, 25 Nov 2022 23:22:38 -0500 Subject: [PATCH] Tests for Moderator --- README.md | 1 - lib/PostText/Controller/Moderator.pm | 6 +++--- t/moderator.t | 29 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 t/moderator.t diff --git a/README.md b/README.md index 1f415ec..7e03205 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,6 @@ Run the tests locally (against development environment): ## TODOs 1. Actions for creating moderators and resetting passwords -1. Tests for Moderator 1. CSS ## Crazy future ideas diff --git a/lib/PostText/Controller/Moderator.pm b/lib/PostText/Controller/Moderator.pm index be2f65a..3419529 100644 --- a/lib/PostText/Controller/Moderator.pm +++ b/lib/PostText/Controller/Moderator.pm @@ -26,10 +26,10 @@ sub login($self) { $email = $self->param('email' ); $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)) { + $mod_id = $self->moderator->get_id($email); + $mod_name = $self->moderator->get_name($mod_id); + $self->session(mod_id => $mod_id); $self->flash(info => "Hello, $mod_name 😎"); diff --git a/t/moderator.t b/t/moderator.t new file mode 100644 index 0000000..3dd6844 --- /dev/null +++ b/t/moderator.t @@ -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();