From 4a987a3c10dff0ef246068a497a4766ff9f6944c Mon Sep 17 00:00:00 2001 From: Manager Bot Date: Fri, 25 Nov 2022 08:02:16 +0000 Subject: [PATCH] More tests, and a fix. --- Web/t/01_endpoints/01_admin/03_people.t | 53 ++++++++++++++++++ Web/t/01_endpoints/01_admin/04_person.t | 52 ++++++++++++++++++ .../01_endpoints/01_admin/05_do_person_note.t | 45 +++++++++++++++ Web/t/01_endpoints/01_admin/06_blogs.t | 52 ++++++++++++++++++ Web/templates/admin/people.html.ep | 55 +++++++++---------- 5 files changed, 228 insertions(+), 29 deletions(-) create mode 100644 Web/t/01_endpoints/01_admin/03_people.t create mode 100644 Web/t/01_endpoints/01_admin/04_person.t create mode 100644 Web/t/01_endpoints/01_admin/05_do_person_note.t create mode 100644 Web/t/01_endpoints/01_admin/06_blogs.t diff --git a/Web/t/01_endpoints/01_admin/03_people.t b/Web/t/01_endpoints/01_admin/03_people.t new file mode 100644 index 0000000..b019b9a --- /dev/null +++ b/Web/t/01_endpoints/01_admin/03_people.t @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test file ensures that people panel can be seen by admins, but not +# normal or anonymouse users. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +# Make sure an unauthed user cannot access this. +$t->get_ok( '/admin/people' ) + ->status_is( 302 ) + ->header_is( location => '/login', 'Anonymouse users may not access the admin people panel.' ); + +# Register a user account and log into it. +# +# A normal user should still not be allowed to view this page. +# +# Promote the user to an admin +$t->app->config->{register}{enable_open} = 1; +$t->post_ok( '/register/open', form => { + name => 'fred', + email => 'fred@blog.com', + password => 'SuperSecure', + password_confirm => 'SuperSecure', + }) + ->status_is( 302 ) + ->code_block( sub { + is( scalar(@{shift->stash->{errors}}), 0, 'No errors' ); + }) + ->get_ok( '/admin/people' ) + ->status_is( 302 ) + ->header_is( location => '/dashboard', 'Normal users may not access the admin people panel.' ) + ->get_ok( '/' ) + ->code_block( sub { + my $self = shift; + $self->stash->{person}->is_admin( 1 ); + ok( $self->stash->{person}->update, 'Promoted fred to an admin' ); + }); + +# Check to ensure that the people array exists and fred is in it. +$t->get_ok( '/admin/people' ) + ->status_is( 200 ) + ->code_block( sub { + my $self = shift; + + is ref($self->stash->{people}), 'ARRAY', 'Have an array ref for invite codes.'; + is scalar(@{$self->stash->{people}}), 1, 'Have one person entry'; + is $self->stash->{people}->[0]->email, 'fred@blog.com', 'Fred is the person entry.'; + }); + +done_testing(); diff --git a/Web/t/01_endpoints/01_admin/04_person.t b/Web/t/01_endpoints/01_admin/04_person.t new file mode 100644 index 0000000..aee77e5 --- /dev/null +++ b/Web/t/01_endpoints/01_admin/04_person.t @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test file ensures that person panel can be seen by admins, but not +# normal or anonymouse users. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +# Make sure an unauthed user cannot access this. +$t->get_ok( '/admin/person/1' ) + ->status_is( 302 ) + ->header_is( location => '/login' ); + +# Register a user account and log into it. +# +# A normal user should still not be allowed to view this page. +# +# Promote the user to an admin +$t->app->config->{register}{enable_open} = 1; +$t->post_ok( '/register/open', form => { + name => 'fred', + email => 'fred@blog.com', + password => 'SuperSecure', + password_confirm => 'SuperSecure', + }) + ->status_is( 302 ) + ->code_block( sub { + is( scalar(@{shift->stash->{errors}}), 0, 'No errors' ); + }) + ->get_ok( '/admin/person/1' ) + ->status_is( 302 ) + ->header_is( location => '/dashboard', 'Normal users may not access the admin person panel.' ) + ->get_ok( '/' ) + ->code_block( sub { + my $self = shift; + $self->stash->{person}->is_admin( 1 ); + ok( $self->stash->{person}->update, 'Promoted fred to an admin' ); + }); + +# Check to ensure that the people array exists and fred is in it. +$t->get_ok( '/admin/person/1' ) + ->status_is( 200 ) + ->code_block( sub { + my $self = shift; + + # We should have fred loaded into the profile... + is $self->stash->{profile}->email, 'fred@blog.com', 'Fred is the profile entry.'; + }); + +done_testing(); diff --git a/Web/t/01_endpoints/01_admin/05_do_person_note.t b/Web/t/01_endpoints/01_admin/05_do_person_note.t new file mode 100644 index 0000000..78be514 --- /dev/null +++ b/Web/t/01_endpoints/01_admin/05_do_person_note.t @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test file ensures that notes can be added to a user's account. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +# Register a user account and log into it. +# +# A normal user should still not be allowed to view this page. +# +# Promote the user to an admin +$t->app->config->{register}{enable_open} = 1; +$t->post_ok( '/register/open', form => { + name => 'fred', + email => 'fred@blog.com', + password => 'SuperSecure', + password_confirm => 'SuperSecure', + }) + ->code_block( sub { + is( scalar(@{shift->stash->{errors}}), 0, 'No errors' ); + }) + ->get_ok( '/' ) + ->code_block( sub { + my $self = shift; + $self->stash->{person}->is_admin( 1 ); + ok( $self->stash->{person}->update, 'Promoted fred to an admin' ); + }); + +$t->post_ok( '/admin/person/1/note', form => { + content => "Hello World!", + }) + ->status_is( 302 ) + ->header_is( location => '/admin/person/1' ) + ->get_ok( '/admin/person/1' ) + ->code_block( sub { + my $self = shift; + + # We should have fred loaded into the profile... + is $self->stash->{notes}->[0]->content, 'Hello World!', 'The note was saved in the profile.'; + }); + +done_testing(); diff --git a/Web/t/01_endpoints/01_admin/06_blogs.t b/Web/t/01_endpoints/01_admin/06_blogs.t new file mode 100644 index 0000000..a5bb9ae --- /dev/null +++ b/Web/t/01_endpoints/01_admin/06_blogs.t @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This file tests to make sure that the admin blog page has the correct access +# rights and that there is an arrayref for blogs in the stash. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +# Make sure an unauthed user cannot access this. +$t->get_ok( '/admin/blogs' ) + ->status_is( 302 ) + ->header_is( location => '/login', 'Anonymouse users may not access the admin blogs panel.' ); + +# Register a user account and log into it. +# +# A normal user should still not be allowed to view this page. +# +# Promote the user to an admin +$t->app->config->{register}{enable_open} = 1; +$t->post_ok( '/register/open', form => { + name => 'fred', + email => 'fred@blog.com', + password => 'SuperSecure', + password_confirm => 'SuperSecure', + }) + ->status_is( 302 ) + ->code_block( sub { + is( scalar(@{shift->stash->{errors}}), 0, 'No errors' ); + }) + ->get_ok( '/admin/blogs' ) + ->status_is( 302 ) + ->header_is( location => '/dashboard', 'Normal users may not access the admin invites panel.' ) + ->get_ok( '/' ) + ->code_block( sub { + my $self = shift; + $self->stash->{person}->is_admin( 1 ); + ok( $self->stash->{person}->update, 'Promoted fred to an admin' ); + }); + +# Check to ensure that the invite code array exists. +$t->get_ok( '/admin/blogs' ) + ->status_is( 200 ) + ->code_block( sub { + my $self = shift; + + is ref($self->stash->{blogs}), 'ARRAY', 'Have an array ref for blogs.'; + is scalar(@{$self->stash->{blogs}}), 0, 'No entries for blogs.'; + }); + +done_testing(); diff --git a/Web/templates/admin/people.html.ep b/Web/templates/admin/people.html.ep index f16f76b..f4b60b4 100644 --- a/Web/templates/admin/people.html.ep +++ b/Web/templates/admin/people.html.ep @@ -4,32 +4,29 @@ %= include '_base/status_window'; -% if ( $people ) { - - - - - - - - - - - % for my $user ( @{$people} ) { - - - - - - - % } - -
NameEmail AddressCreatedBecome User
<%= $user->name %><%= $user->email %><%= $user->created_at->strftime( "%F" ) %> -
- - - -
-
-% } - + + + + + + + + + + + % for my $user ( @{$people} ) { + + + + + + + % } + +
NameEmail AddressCreatedBecome User
<%= $user->name %><%= $user->email %><%= $user->created_at->strftime( "%F" ) %> +
+ + + +
+