Cleaning stuff up

This commit is contained in:
swag 2022-10-12 23:58:46 -04:00
parent 99cef47f95
commit 419769545b
5 changed files with 48 additions and 36 deletions

View File

@ -13,16 +13,16 @@ sub startup($self) {
$self->plugin(AssetPack => {pipes => [qw{Css Combine}]}); $self->plugin(AssetPack => {pipes => [qw{Css Combine}]});
# Helpers # Helpers
$self->helper(pg => sub { $self->helper(pg => sub ($c) {
state $pg = Mojo::Pg->new(shift->config->{$self->mode}{'pg_string'}) state $pg = Mojo::Pg->new($c->config->{$self->mode}{'pg_string'})
}); });
$self->helper(thread => sub { $self->helper(thread => sub ($c) {
state $thread = PostText::Model::Thread->new(pg => shift->pg) state $thread = PostText::Model::Thread->new(pg => $c->pg)
}); });
$self->helper(remark => sub { $self->helper(remark => sub ($c) {
state $remark = PostText::Model::Remark->new(pg => shift->pg) state $remark = PostText::Model::Remark->new(pg => $c->pg)
}); });
$self->helper(truncate_text => sub ($c, $input_text) { $self->helper(truncate_text => sub ($c, $input_text) {
@ -71,7 +71,7 @@ sub startup($self) {
->to('thread#create') ->to('thread#create')
->name('post_thread'); ->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}) ->get('/:thread_page', [thread_page => qr/[0-9]+/], {thread_page => 1})
->to('thread#by_id') ->to('thread#by_id')
->name('single_thread'); ->name('single_thread');

View File

@ -1 +0,0 @@
daniel@graymember.98268

View File

@ -4,46 +4,49 @@ use Test::Mojo;
my $t = Test::Mojo->new('PostText'); my $t = Test::Mojo->new('PostText');
my %valid_remark = ( my %valid_remark = (
author => 'Anonymous', author => 'Anonymous',
body => 'hi' body => 'hi'
); );
my %invalid_remark = ( my %invalid_remark = (
author => 'Anonymous', author => 'Anonymous',
body => 'a' body => 'a'
); );
subtest 'View single remark', sub { 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); $t->ua->max_redirects(1);
subtest 'Post new remark', sub { subtest 'Post new remark', sub {
# GET # 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 input[name="author"]' )
->element_exists('form textarea[name="body"]') ->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' ) ->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Remark/); ->text_like(h2 => qr/New Remark/);
# POST # 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 input[name="author"]' )
->element_exists('form textarea[name="body"]') ->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' ) ->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Remark/); ->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/); ->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/); ->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(); done_testing();

View File

@ -4,6 +4,6 @@ use Test::Mojo;
my $t = Test::Mojo->new('PostText'); 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(); done_testing();

View File

@ -4,37 +4,45 @@ use Test::Mojo;
my $t = Test::Mojo->new('PostText'); my $t = Test::Mojo->new('PostText');
my %valid_params = ( my %valid_params = (
author => 'Anonymous', author => 'Anonymous',
title => 'hi', title => 'hi',
body => 'ayy... lmao' body => 'ayy... lmao'
); );
my %invalid_title = ( my %invalid_title = (
author => 'Anonymous', author => 'Anonymous',
title => '', title => '',
body => 'ayy... lmao' body => 'ayy... lmao'
); );
my %invalid_post = (
my %invalid_post = (
author => 'Anonymous', author => 'Anonymous',
title => 'hi', title => 'hi',
body => 'a' body => 'a'
); );
subtest 'List threads by page', sub { subtest 'List threads by page', sub {
$t->get_ok('/list' )->status_is(200)->text_like(h2 => qr/Threads List/); $t->get_ok('/thread/list')->status_is(200)
$t->get_ok('/list/1')->status_is(200)->text_like(h2 => qr/Threads List/); ->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 { subtest 'View single thread', sub {
$t->get_ok('/thread/1' )->status_is(200)->text_like(h2 => qr/Thread #1/); $t->get_ok('/thread/single/1')->status_is(200)
$t->get_ok('/thread/1/1')->status_is(200)->text_like(h2 => qr/Thread #1/); ->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); $t->ua->max_redirects(1);
subtest 'Post new thread', sub { subtest 'Post new thread', sub {
# GET # 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="author"]' )
->element_exists('form input[name="title"]' ) ->element_exists('form input[name="title"]' )
->element_exists('form textarea[name="body"]') ->element_exists('form textarea[name="body"]')
@ -42,37 +50,39 @@ subtest 'Post new thread', sub {
->text_like(h2 => qr/New Thread/); ->text_like(h2 => qr/New Thread/);
# POST # 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="author"]' )
->element_exists('form input[name="title"]' ) ->element_exists('form input[name="title"]' )
->element_exists('form textarea[name="body"]') ->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' ) ->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Thread/); ->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/); ->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/); ->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]+/); ->text_like(h2 => qr/Thread #[0-9]+/);
}; };
subtest 'Bumping thread', sub { subtest 'Bumping thread', sub {
$t->get_ok('/list')->status_is(200) $t->get_ok('/thread/list')->status_is(200)
->element_exists('a[href*="bump"]') ->element_exists('a[href*="bump"]')
->text_like(h2 => qr/Threads List/); ->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"]') ->element_exists('p[class="field-with-info"]')
->text_like(p => qr/Thread #[0-9]+ has been bumped/); ->text_like(p => qr/Thread #[0-9]+ has been bumped/);
}; };
subtest 'Flagging thread', sub { subtest 'Flagging thread', sub {
$t->get_ok('/list')->status_is(200) $t->get_ok('/thread/list')->status_is(200)
->element_exists('a[href*="flag"]') ->element_exists('a[href*="flag"]')
->text_like(h2 => qr/Threads List/); ->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"]') ->element_exists('a[href*="flag"]')
->text_like(h2 => qr/Thread #1/); ->text_like(h2 => qr/Thread #1/);
} }