From 419769545b5caac4c12299da11b4e356771af3cb Mon Sep 17 00:00:00 2001 From: swag Date: Wed, 12 Oct 2022 23:58:46 -0400 Subject: [PATCH] Cleaning stuff up --- lib/PostText.pm | 14 +++++++------- t/.#remark.t | 1 - t/remark.t | 27 +++++++++++++++------------ t/root.t | 2 +- t/thread.t | 40 +++++++++++++++++++++++++--------------- 5 files changed, 48 insertions(+), 36 deletions(-) delete mode 120000 t/.#remark.t diff --git a/lib/PostText.pm b/lib/PostText.pm index 3c6577c..e846c9a 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -13,16 +13,16 @@ sub startup($self) { $self->plugin(AssetPack => {pipes => [qw{Css Combine}]}); # Helpers - $self->helper(pg => sub { - state $pg = Mojo::Pg->new(shift->config->{$self->mode}{'pg_string'}) + $self->helper(pg => sub ($c) { + state $pg = Mojo::Pg->new($c->config->{$self->mode}{'pg_string'}) }); - $self->helper(thread => sub { - state $thread = PostText::Model::Thread->new(pg => shift->pg) + $self->helper(thread => sub ($c) { + state $thread = PostText::Model::Thread->new(pg => $c->pg) }); - $self->helper(remark => sub { - state $remark = PostText::Model::Remark->new(pg => shift->pg) + $self->helper(remark => sub ($c) { + state $remark = PostText::Model::Remark->new(pg => $c->pg) }); $self->helper(truncate_text => sub ($c, $input_text) { @@ -71,7 +71,7 @@ sub startup($self) { ->to('thread#create') ->name('post_thread'); - $thread->under('/:thread_id', [thread_id => qr/[0-9]+/]) + $thread->under('/single/:thread_id', [thread_id => qr/[0-9]+/]) ->get('/:thread_page', [thread_page => qr/[0-9]+/], {thread_page => 1}) ->to('thread#by_id') ->name('single_thread'); diff --git a/t/.#remark.t b/t/.#remark.t deleted file mode 120000 index 63494f2..0000000 --- a/t/.#remark.t +++ /dev/null @@ -1 +0,0 @@ -daniel@graymember.98268 \ No newline at end of file diff --git a/t/remark.t b/t/remark.t index 96659e9..a3f0388 100644 --- a/t/remark.t +++ b/t/remark.t @@ -4,46 +4,49 @@ use Test::Mojo; my $t = Test::Mojo->new('PostText'); -my %valid_remark = ( +my %valid_remark = ( author => 'Anonymous', body => 'hi' ); + my %invalid_remark = ( author => 'Anonymous', body => 'a' ); subtest 'View single remark', sub { - $t->get_ok('/remark/1')->status_is(200)->text_like(h2 => qr/Remark #1/); + $t->get_ok('/remark/single/1')->status_is(200) + ->text_like(h2 => qr/Remark #1/); }; -subtest 'Flagging remark', sub { - $t->get_ok('/remark/1')->status_is(200) - ->element_exists('a[href*="flag"]') - ->text_like(h2 => qr/Thread #1/); -} - $t->ua->max_redirects(1); subtest 'Post new remark', sub { # GET - $t->get_ok('/post/1')->status_is(200) + $t->get_ok('/remark/post/1')->status_is(200) ->element_exists('form input[name="author"]' ) ->element_exists('form textarea[name="body"]') ->element_exists('form input[type="submit"]' ) ->text_like(h2 => qr/New Remark/); # POST - $t->post_ok('/post/1')->status_is(200) + $t->post_ok('/remark/post/1')->status_is(200) ->element_exists('form input[name="author"]' ) ->element_exists('form textarea[name="body"]') ->element_exists('form input[type="submit"]' ) ->text_like(h2 => qr/New Remark/); - $t->post_ok('/post/1', form => \%valid_remark)->status_is(200) + $t->post_ok('/remark/post/1', form => \%valid_remark)->status_is(200) ->text_like(h2 => qr/Thread #1/); - $t->post_ok('/post/1', form => \%invalid_remark)->status_is(400) + + $t->post_ok('/remark/post/1', form => \%invalid_remark)->status_is(400) ->text_like(p => qr/Invalid text/); }; +subtest 'Flagging remark', sub { + $t->get_ok('/remark/single/1')->status_is(200) + ->element_exists('a[href*="flag"]') + ->text_like(h2 => qr/Thread #1/); +} + done_testing(); diff --git a/t/root.t b/t/root.t index df43724..c41e894 100644 --- a/t/root.t +++ b/t/root.t @@ -4,6 +4,6 @@ use Test::Mojo; my $t = Test::Mojo->new('PostText'); -$t->get_ok('/')->status_is(302); +$t->get_ok('/')->status_is(302)->header_like(Location => qr/thread/); done_testing(); diff --git a/t/thread.t b/t/thread.t index a7f9774..743d321 100644 --- a/t/thread.t +++ b/t/thread.t @@ -4,37 +4,45 @@ use Test::Mojo; my $t = Test::Mojo->new('PostText'); -my %valid_params = ( +my %valid_params = ( author => 'Anonymous', title => 'hi', body => 'ayy... lmao' ); + my %invalid_title = ( author => 'Anonymous', title => '', body => 'ayy... lmao' ); -my %invalid_post = ( + +my %invalid_post = ( author => 'Anonymous', title => 'hi', body => 'a' ); subtest 'List threads by page', sub { - $t->get_ok('/list' )->status_is(200)->text_like(h2 => qr/Threads List/); - $t->get_ok('/list/1')->status_is(200)->text_like(h2 => qr/Threads List/); + $t->get_ok('/thread/list')->status_is(200) + ->text_like(h2 => qr/Threads List/); + + $t->get_ok('/thread/list/1')->status_is(200) + ->text_like(h2 => qr/Threads List/); }; subtest 'View single thread', sub { - $t->get_ok('/thread/1' )->status_is(200)->text_like(h2 => qr/Thread #1/); - $t->get_ok('/thread/1/1')->status_is(200)->text_like(h2 => qr/Thread #1/); + $t->get_ok('/thread/single/1')->status_is(200) + ->text_like(h2 => qr/Thread #1/); + + $t->get_ok('/thread/single/1/1')->status_is(200) + ->text_like(h2 => qr/Thread #1/); }; $t->ua->max_redirects(1); subtest 'Post new thread', sub { # GET - $t->get_ok('/post')->status_is(200) + $t->get_ok('/thread/post')->status_is(200) ->element_exists('form input[name="author"]' ) ->element_exists('form input[name="title"]' ) ->element_exists('form textarea[name="body"]') @@ -42,37 +50,39 @@ subtest 'Post new thread', sub { ->text_like(h2 => qr/New Thread/); # POST - $t->post_ok('/post')->status_is(200) + $t->post_ok('/thread/post')->status_is(200) ->element_exists('form input[name="author"]' ) ->element_exists('form input[name="title"]' ) ->element_exists('form textarea[name="body"]') ->element_exists('form input[type="submit"]' ) ->text_like(h2 => qr/New Thread/); - $t->post_ok('/post', form => \%invalid_title)->status_is(400) + $t->post_ok('/thread/post', form => \%invalid_title)->status_is(400) ->text_like(p => qr/Invalid title/); - $t->post_ok('/post', form => \%invalid_post)->status_is(400) + + $t->post_ok('/thread/post', form => \%invalid_post)->status_is(400) ->text_like(p => qr/Invalid text/); - $t->post_ok('/post', form => \%valid_params)->status_is(200) + + $t->post_ok('/thread/post', form => \%valid_params)->status_is(200) ->text_like(h2 => qr/Thread #[0-9]+/); }; subtest 'Bumping thread', sub { - $t->get_ok('/list')->status_is(200) + $t->get_ok('/thread/list')->status_is(200) ->element_exists('a[href*="bump"]') ->text_like(h2 => qr/Threads List/); - $t->get_ok('/bump/1')->status_is(200) + $t->get_ok('/thread/bump/1')->status_is(200) ->element_exists('p[class="field-with-info"]') ->text_like(p => qr/Thread #[0-9]+ has been bumped/); }; subtest 'Flagging thread', sub { - $t->get_ok('/list')->status_is(200) + $t->get_ok('/thread/list')->status_is(200) ->element_exists('a[href*="flag"]') ->text_like(h2 => qr/Threads List/); - $t->get_ok('/thread/1')->status_is(200) + $t->get_ok('/thread/single/1')->status_is(200) ->element_exists('a[href*="flag"]') ->text_like(h2 => qr/Thread #1/); }