PostText/t/post.t

59 lines
1.5 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Mojo::File qw{curfile};
use Test::Mojo;
2022-08-24 21:46:20 -04:00
my $script = curfile->dirname->sibling('PostText.pl');
my $t = Test::Mojo->new($script);
my %valid_params = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-08-14 00:30:26 -04:00
title => 'hi',
post => 'ayy... lmao'
2022-08-14 00:30:26 -04:00
);
2022-08-24 21:46:20 -04:00
my %invalid_title = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-08-15 17:11:14 -04:00
title => '',
2022-08-15 17:48:58 -04:00
post => 'ayy... lmao'
);
2022-08-24 21:46:20 -04:00
my %invalid_post = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-08-15 17:48:58 -04:00
title => 'hi',
2022-08-15 17:11:14 -04:00
post => 'a'
);
2022-08-24 21:46:20 -04:00
my %valid_remark = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-08-24 21:46:20 -04:00
post => 'hi'
);
my %invalid_remark = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-08-24 21:46:20 -04:00
post => 'a'
);
2022-08-15 17:48:58 -04:00
2022-08-14 00:30:26 -04:00
$t->ua->max_redirects(1);
2022-08-15 17:11:14 -04:00
# GET
2022-08-24 21:46:20 -04:00
$t->get_ok('/post' )->status_is(200)->text_like(h2 => qr/New Thread/);
$t->get_ok('/post/1')->status_is(200)->text_like(h2 => qr/New Remark/);
2022-08-15 17:11:14 -04:00
# POST
2022-08-24 21:46:20 -04:00
$t->post_ok('/post' )->status_is(200)->text_like(h2 => qr/New Thread/);
2022-08-14 00:30:26 -04:00
2022-08-15 17:48:58 -04:00
$t->post_ok('/post', form => \%invalid_title)->status_is(400)
->text_like(p => qr/Invalid title/);
$t->post_ok('/post', form => \%invalid_post)->status_is(400)
->text_like(p => qr/Invalid post/);
2022-08-14 00:30:26 -04:00
$t->post_ok('/post', form => \%valid_params)->status_is(200)
->text_like(h2 => qr/Threads List/);
2022-08-14 00:30:26 -04:00
2022-08-24 21:46:20 -04:00
$t->post_ok('/post/1')->status_is(200)->text_like(h2 => qr/New Remark/);
$t->post_ok('/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)
->text_like(h2 => qr/New Remark/);
done_testing();