2022-07-30 03:30:19 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
|
|
|
use Mojo::File qw{curfile};
|
|
|
|
use Test::Mojo;
|
|
|
|
|
2022-08-15 21:48:58 +00:00
|
|
|
my $script = curfile->dirname->sibling('PostText.pl');
|
|
|
|
my $t = Test::Mojo->new($script);
|
|
|
|
my %valid_params = (
|
2022-08-14 04:30:26 +00:00
|
|
|
name => 'Anonymous',
|
|
|
|
title => 'hi',
|
2022-08-14 22:30:22 +00:00
|
|
|
post => 'ayy... lmao'
|
2022-08-14 04:30:26 +00:00
|
|
|
);
|
2022-08-15 21:48:58 +00:00
|
|
|
my %invalid_title = (
|
2022-08-15 21:11:14 +00:00
|
|
|
name => 'Anonymous',
|
|
|
|
title => '',
|
2022-08-15 21:48:58 +00:00
|
|
|
post => 'ayy... lmao'
|
|
|
|
);
|
|
|
|
my %invalid_post = (
|
|
|
|
name => 'Anonymous',
|
|
|
|
title => 'hi',
|
2022-08-15 21:11:14 +00:00
|
|
|
post => 'a'
|
|
|
|
);
|
2022-07-30 03:30:19 +00:00
|
|
|
|
2022-08-15 21:48:58 +00:00
|
|
|
|
2022-08-14 04:30:26 +00:00
|
|
|
$t->ua->max_redirects(1);
|
2022-07-30 03:30:19 +00:00
|
|
|
|
2022-08-15 21:11:14 +00:00
|
|
|
# GET
|
|
|
|
$t->get_ok('/post')->status_is(200)->text_like(h2 => qr/New Thread/);
|
|
|
|
|
|
|
|
# POST
|
|
|
|
$t->post_ok('/post')->status_is(200)->text_like(h2 => qr/New Thread/);
|
2022-08-14 04:30:26 +00:00
|
|
|
|
2022-08-15 21:48:58 +00: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-07-30 03:30:19 +00:00
|
|
|
|
2022-08-14 04:30:26 +00:00
|
|
|
$t->post_ok('/post', form => \%valid_params)->status_is(200)
|
|
|
|
->text_like(h2 => qr/View Threads/);
|
|
|
|
|
2022-07-30 03:30:19 +00:00
|
|
|
done_testing();
|