From 26813603521435ab78534926945d6f96c05c8a9d Mon Sep 17 00:00:00 2001 From: swag Date: Tue, 10 Jan 2023 00:45:31 -0500 Subject: [PATCH] Fix logging out and tests --- lib/PostText/Controller/Moderator.pm | 2 +- t/moderator.t | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/PostText/Controller/Moderator.pm b/lib/PostText/Controller/Moderator.pm index ad7dc7a..8c839e8 100644 --- a/lib/PostText/Controller/Moderator.pm +++ b/lib/PostText/Controller/Moderator.pm @@ -79,7 +79,7 @@ sub login($self) { } sub logout($self) { - delete $self->session->{'mod_id'}; + delete $self->session->%{qw(mod_id is_admin)}; $self->flash(info => 'Logged out successfully 👋'); diff --git a/t/moderator.t b/t/moderator.t index 4a7c76a..910aefa 100644 --- a/t/moderator.t +++ b/t/moderator.t @@ -82,6 +82,7 @@ subtest Login => sub { ->text_like(h2 => qr/Flagged Posts/) ->element_exists('a[href*="/moderator/flagged"]') ->element_exists('a[href*="/moderator/hidden"]' ) + ->element_exists('a[href*="/logout"]' ) }; subtest Hidden => sub { @@ -90,6 +91,7 @@ subtest Login => sub { ->text_like(h2 => qr/Hidden Posts/) ->element_exists('a[href*="/moderator/flagged"]') ->element_exists('a[href*="/moderator/hidden"]' ) + ->element_exists('a[href*="/logout"]' ) }; # Mod session ends @@ -100,15 +102,21 @@ subtest Login => sub { subtest 'No mod, no buttons', sub { $t->get_ok('/thread/single/1') ->status_is(200) - ->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*="/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*="/logout"]' ); $t->get_ok('/remark/single/1') ->status_is(200) - ->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*="/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*="/logout"]' ); $t->get_ok('/moderator/flagged') ->status_is(302)