Implement raw/txt format; moar tests

This commit is contained in:
swag 2023-06-27 01:30:32 -04:00
parent 93f0689d1b
commit 402c550b74
6 changed files with 46 additions and 8 deletions

View File

@ -61,6 +61,7 @@ tests locally:
## TODOs ## TODOs
1. Probably gotta add a link to the 'raw' txt view somewhere
1. "All new posts flagged" mode (require approval for new posts) 1. "All new posts flagged" mode (require approval for new posts)
1. Tests for mod-only user? 1. Tests for mod-only user?
@ -72,7 +73,4 @@ tests locally:
NOT hidden_status` but that returns null, probably need a different NOT hidden_status` but that returns null, probably need a different
`JOIN` which may not be worth the trouble/processing `JOIN` which may not be worth the trouble/processing
1. Implement tripcodes (moving this down in priority due to complexity...) 1. Implement tripcodes (moving this down in priority due to complexity...)
1. Return a text response instead of HTML if a `.txt` extension [is
requested](https://docs.mojolicious.org/Mojolicious/Plugin/DefaultHelpers#respond_to)
(JSON?)
1. Post thread via SMS (twil.io??) 1. Post thread via SMS (twil.io??)

View File

@ -136,7 +136,8 @@ sub startup($self) {
->name('post_thread'); ->name('post_thread');
$thread->any('/single/:thread_id', [thread_id => qr/\d+/]) $thread->any('/single/:thread_id', [thread_id => qr/\d+/])
->get('/:thread_page', [thread_page => qr/\d+/], {thread_page => 0}) ->any('/:thread_page', [thread_page => qr/\d+/], {thread_page => 0})
->get('/', [format => [qw{html txt}]], {format => undef})
->to('thread#by_id') ->to('thread#by_id')
->name('single_thread'); ->name('single_thread');
@ -160,7 +161,8 @@ sub startup($self) {
->to('remark#create') ->to('remark#create')
->name('post_remark'); ->name('post_remark');
$remark->get('/single/:remark_id', [remark_id => qr/\d+/]) $remark->any('/single/:remark_id', [remark_id => qr/\d+/])
->get('/', [format => [qw{html txt}]], {format => undef})
->to('remark#by_id') ->to('remark#by_id')
->name('single_remark'); ->name('single_remark');

View File

@ -17,7 +17,14 @@ my %invalid_remark = (
subtest 'View single remark', sub { subtest 'View single remark', sub {
$t->get_ok('/remark/single/1')->status_is(200) $t->get_ok('/remark/single/1')->status_is(200)
->text_like(h2 => qr/Remark #1/) ->text_like(h2 => qr/Remark #1/)
->element_exists('a[href$="/remark/post/1/1"]') ->element_exists('a[href$="/remark/post/1/1"]');
$t->get_ok('/remark/single/65536')->status_is(404)
->text_like(p => qr/Remark not found/);
$t->get_ok('/remark/single/1.txt')->status_is(200)
->content_type_like(qr{text/plain});
$t->get_ok('/remark/single/65536.txt')->status_is(404)
->content_type_like(qr{text/plain});
}; };
$t->ua->max_redirects(1); $t->ua->max_redirects(1);
@ -29,6 +36,8 @@ subtest 'Post new remark', sub {
->element_exists('form textarea[name="body"]') ->element_exists('form textarea[name="body"]')
->element_exists('form button[type="submit"]' ) ->element_exists('form button[type="submit"]' )
->text_like(h2 => qr/Remark on Thread #/); ->text_like(h2 => qr/Remark on Thread #/);
$t->get_ok('/remark/post/65536')->status_is(404)
->text_like(p => qr/Thread not found/);
# Test the remark-to-remark thing # Test the remark-to-remark thing
$t->get_ok('/remark/post/1/1')->status_is(200) $t->get_ok('/remark/post/1/1')->status_is(200)
->element_exists('form input[name="author"]' ) ->element_exists('form input[name="author"]' )

View File

@ -28,18 +28,28 @@ subtest 'List threads by page', sub {
$t->get_ok('/thread/list/1')->status_is(200) $t->get_ok('/thread/list/1')->status_is(200)
->text_like(h2 => qr/Threads List/); ->text_like(h2 => qr/Threads List/);
$t->get_ok('/thread/list/65536')->status_is(404)
->text_like(p => qr/Page not found/);
}; };
subtest 'View single thread', sub { subtest 'View single thread', sub {
$t->get_ok('/thread/single/1')->status_is(200) $t->get_ok('/thread/single/1')->status_is(200)
->text_like(h2 => qr/Thread #1/); ->text_like(h2 => qr/Thread #1/);
$t->get_ok('/thread/single/65536')->status_is(404)
->text_like(p => qr/Thread not found/);
$t->get_ok('/thread/single/1.txt')->status_is(200)
->content_type_like(qr{text/plain});
$t->get_ok('/thread/single/65536.txt')->status_is(404)
->content_type_like(qr{text/plain});
# Test the thread_page and remark_id params # Test the thread_page and remark_id params
$t->get_ok('/thread/single/1/1')->status_is(200) $t->get_ok('/thread/single/1/1')->status_is(200)
->element_exists('a[href$="/remark/post/1/1"]'); ->element_exists('a[href$="/remark/post/1/1"]');
$t->get_ok('/thread/single/65536')->status_is(404) $t->get_ok('/thread/single/1/65536')->status_is(404)
->text_like(p => qr/Thread not found/); ->text_like(p => qr/Page not found/);
}; };
subtest 'Threads feed', sub { subtest 'Threads feed', sub {

View File

@ -0,0 +1,9 @@
% if (keys %{$remark}) {
%= $remark->{'id'};
%= $remark->{'date'};
%= $remark->{'author'};
%= $remark->{'body'};
% } else {
%= stash 'error';
% }

View File

@ -0,0 +1,10 @@
% if (keys %{$thread}) {
%= $thread->{'id'};
%= $thread->{'title'};
%= $thread->{'date'};
%= $thread->{'author'};
%= $thread->{'body'};
% } else {
%= stash 'error';
% }