2022-10-01 22:00:23 +00:00
|
|
|
use Mojo::Base -strict;
|
2022-08-20 03:28:16 +00:00
|
|
|
use Test::More;
|
|
|
|
use Test::Mojo;
|
|
|
|
|
2022-10-01 22:00:23 +00:00
|
|
|
my $t = Test::Mojo->new('PostText');
|
2022-08-20 03:28:16 +00:00
|
|
|
|
2022-10-13 03:58:46 +00:00
|
|
|
my %valid_params = (
|
2022-10-06 02:46:15 +00:00
|
|
|
author => 'Anonymous',
|
|
|
|
title => 'hi',
|
|
|
|
body => 'ayy... lmao'
|
|
|
|
);
|
2022-10-13 03:58:46 +00:00
|
|
|
|
2022-10-06 02:46:15 +00:00
|
|
|
my %invalid_title = (
|
|
|
|
author => 'Anonymous',
|
|
|
|
title => '',
|
|
|
|
body => 'ayy... lmao'
|
|
|
|
);
|
2022-10-13 03:58:46 +00:00
|
|
|
|
|
|
|
my %invalid_post = (
|
2022-10-06 02:46:15 +00:00
|
|
|
author => 'Anonymous',
|
|
|
|
title => 'hi',
|
|
|
|
body => 'a'
|
|
|
|
);
|
|
|
|
|
|
|
|
subtest 'List threads by page', sub {
|
2022-10-13 03:58:46 +00:00
|
|
|
$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/);
|
2022-10-06 02:46:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest 'View single thread', sub {
|
2022-10-13 03:58:46 +00:00
|
|
|
$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/);
|
2023-05-14 20:17:10 +00:00
|
|
|
|
|
|
|
$t->get_ok('/thread/single/65536')->status_is(404)
|
2023-05-28 06:07:09 +00:00
|
|
|
->text_like(p => qr/Thread not found/);
|
2022-10-06 02:46:15 +00:00
|
|
|
};
|
|
|
|
|
2023-04-24 18:25:32 +00:00
|
|
|
subtest 'Threads feed', sub {
|
|
|
|
$t->get_ok('/thread/feed.rss')->status_is(200)
|
|
|
|
->content_type_is('application/rss+xml')
|
|
|
|
};
|
|
|
|
|
2022-10-08 05:58:18 +00:00
|
|
|
$t->ua->max_redirects(1);
|
2022-10-08 04:42:31 +00:00
|
|
|
|
2022-10-06 02:46:15 +00:00
|
|
|
subtest 'Post new thread', sub {
|
|
|
|
# GET
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->get_ok('/thread/post')->status_is(200)
|
2022-10-06 02:46:15 +00:00
|
|
|
->element_exists('form input[name="author"]' )
|
|
|
|
->element_exists('form input[name="title"]' )
|
|
|
|
->element_exists('form textarea[name="body"]')
|
2023-05-21 03:43:32 +00:00
|
|
|
->element_exists('form button[type="submit"]' )
|
2022-10-06 02:46:15 +00:00
|
|
|
->text_like(h2 => qr/New Thread/);
|
|
|
|
|
|
|
|
# POST
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->post_ok('/thread/post')->status_is(200)
|
2022-10-06 02:46:15 +00:00
|
|
|
->element_exists('form input[name="author"]' )
|
|
|
|
->element_exists('form input[name="title"]' )
|
|
|
|
->element_exists('form textarea[name="body"]')
|
2023-05-21 03:43:32 +00:00
|
|
|
->element_exists('form button[type="submit"]' )
|
2022-10-06 02:46:15 +00:00
|
|
|
->text_like(h2 => qr/New Thread/);
|
|
|
|
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->post_ok('/thread/post', form => \%invalid_title)->status_is(400)
|
2023-05-28 04:42:07 +00:00
|
|
|
->text_like(p => qr/Must be between/);
|
2022-10-13 03:58:46 +00:00
|
|
|
|
|
|
|
$t->post_ok('/thread/post', form => \%invalid_post)->status_is(400)
|
2023-05-28 04:42:07 +00:00
|
|
|
->text_like(p => qr/Must be between/);
|
2022-10-13 03:58:46 +00:00
|
|
|
|
|
|
|
$t->post_ok('/thread/post', form => \%valid_params)->status_is(200)
|
2022-11-25 07:31:22 +00:00
|
|
|
->text_like(h2 => qr/Thread #\d+/);
|
2022-10-06 02:46:15 +00:00
|
|
|
};
|
2022-08-20 03:28:16 +00:00
|
|
|
|
2022-10-08 05:58:18 +00:00
|
|
|
subtest 'Bumping thread', sub {
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->get_ok('/thread/list')->status_is(200)
|
2022-10-08 05:58:18 +00:00
|
|
|
->element_exists('a[href*="bump"]')
|
|
|
|
->text_like(h2 => qr/Threads List/);
|
|
|
|
|
2022-10-14 03:57:58 +00:00
|
|
|
$t->get_ok('/thread/single/1')->status_is(200)
|
|
|
|
->element_exists('a[href*="bump"]')
|
|
|
|
->text_like(h2 => qr/Thread #1/);
|
|
|
|
|
2023-06-14 00:22:07 +00:00
|
|
|
$t->get_ok('/thread/bump/1' )->status_is(200);
|
2023-06-14 03:04:52 +00:00
|
|
|
$t->get_ok('/thread/bump/65536')->status_is(404)
|
|
|
|
->text_like(p => qr/Thread not found/);
|
2023-06-14 01:32:59 +00:00
|
|
|
$t->get_ok('/thread/bump/1', form => {captcha => 'bump'})->status_is(200);
|
|
|
|
$t->get_ok('/thread/bump/1', form => {captcha => 'aaaa'})->status_is(400);
|
2022-10-08 05:58:18 +00:00
|
|
|
};
|
|
|
|
|
2022-10-13 02:14:28 +00:00
|
|
|
subtest 'Flagging thread', sub {
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->get_ok('/thread/list')->status_is(200)
|
2022-10-13 02:14:28 +00:00
|
|
|
->element_exists('a[href*="flag"]')
|
|
|
|
->text_like(h2 => qr/Threads List/);
|
|
|
|
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->get_ok('/thread/single/1')->status_is(200)
|
2022-10-13 02:14:28 +00:00
|
|
|
->element_exists('a[href*="flag"]')
|
|
|
|
->text_like(h2 => qr/Thread #1/);
|
2022-10-14 03:57:58 +00:00
|
|
|
|
2023-06-13 23:58:13 +00:00
|
|
|
$t->get_ok('/thread/flag/1' )->status_is(200);
|
2023-06-14 03:04:52 +00:00
|
|
|
$t->get_ok('/thread/flag/65536')->status_is(404)
|
|
|
|
->text_like(p => qr/Thread not found/);
|
2023-06-14 01:32:59 +00:00
|
|
|
$t->get_ok('/thread/flag/1', form => {captcha => 'flag'})->status_is(200);
|
|
|
|
$t->get_ok('/thread/flag/1', form => {captcha => 'aaaa'})->status_is(400);
|
2022-10-14 03:57:58 +00:00
|
|
|
};
|
2022-10-13 02:14:28 +00:00
|
|
|
|
2023-04-26 02:28:11 +00:00
|
|
|
done_testing;
|