Implement raw/txt format; moar tests

This commit is contained in:
swagg boi 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
1. Probably gotta add a link to the 'raw' txt view somewhere
1. "All new posts flagged" mode (require approval for new posts)
1. Tests for mod-only user?
@ -72,7 +73,4 @@ tests locally:
NOT hidden_status` but that returns null, probably need a different
`JOIN` which may not be worth the trouble/processing
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??)

View file

@ -136,7 +136,8 @@ sub startup($self) {
->name('post_thread');
$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')
->name('single_thread');
@ -160,7 +161,8 @@ sub startup($self) {
->to('remark#create')
->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')
->name('single_remark');

View file

@ -17,7 +17,14 @@ my %invalid_remark = (
subtest 'View single remark', sub {
$t->get_ok('/remark/single/1')->status_is(200)
->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);
@ -29,6 +36,8 @@ subtest 'Post new remark', sub {
->element_exists('form textarea[name="body"]')
->element_exists('form button[type="submit"]' )
->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
$t->get_ok('/remark/post/1/1')->status_is(200)
->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)
->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 {
$t->get_ok('/thread/single/1')->status_is(200)
->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
$t->get_ok('/thread/single/1/1')->status_is(200)
->element_exists('a[href$="/remark/post/1/1"]');
$t->get_ok('/thread/single/65536')->status_is(404)
->text_like(p => qr/Thread not found/);
$t->get_ok('/thread/single/1/65536')->status_is(404)
->text_like(p => qr/Page not found/);
};
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';
% }