guestbook-ng/t/sign.t

52 lines
1.3 KiB
Perl
Raw Normal View History

2022-01-08 22:01:51 -05:00
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Mojo::File qw{curfile};
use Test::Mojo;
my $script = curfile->dirname->sibling('guestbook-ng.pl');
my $t = Test::Mojo->new($script);
my %invalid_form = (
name => 'swagg boi',
url => 'INVALID://',
message => '',
answer => 'false'
);
my %spam_form = (
name => 'swagg boi',
url => 'http://localhost/',
message => 'hi',
answer => 0
);
2022-04-08 13:47:33 -04:00
my %valid_form = (
name => 'swagg boi',
url => 'http://localhost',
message => 'Ayy... lmao',
answer => 'false'
);
2022-04-09 15:35:24 -04:00
# Null POST body
my %null_form;
2022-01-08 22:01:51 -05:00
$t->ua->max_redirects(1);
2022-04-08 13:47:33 -04:00
# Valid requests
$t->get_ok('/sign')->status_is(200)->text_is(h2 => 'Sign the Guestbook');
2022-04-09 15:35:24 -04:00
$t->post_ok('/sign', form => \%valid_form)->status_is(200)
->text_is(h2 => 'Messages from the World Wide Web');
2022-04-08 13:47:33 -04:00
2022-01-08 22:01:51 -05:00
# Invalid input
2022-04-09 15:35:24 -04:00
$t->post_ok('/sign', form => \%invalid_form)->status_is(400)
2022-01-08 22:01:51 -05:00
->content_like(qr/cannot be blank/);
2022-04-09 15:35:24 -04:00
$t->post_ok('/sign', form => \%invalid_form)->status_is(400)
2022-01-08 22:01:51 -05:00
->content_like(qr/URL does not appear to be/);
2022-04-09 15:35:24 -04:00
$t->post_ok('/sign', form => \%null_form)->status_is(400)
->text_is(h2 => 'Sign the Guestbook');
2022-01-08 22:01:51 -05:00
# Spam test
2022-04-08 16:01:30 -04:00
$t->post_ok('/sign', form => \%spam_form)->status_is(403)
->text_is(p => 'This message was flagged as spam');
2022-01-08 22:01:51 -05:00
done_testing();