More tests

This commit is contained in:
swagg boi 2022-01-08 22:01:51 -05:00
parent e4aad2ccbd
commit d7c0f715d2
4 changed files with 39 additions and 4 deletions

View file

@ -49,6 +49,5 @@ Add the `-v` option for more verbose output
## TODOs
1. More tests
1. /spam route would be interesting
1. Include the total number of visitors or messages

View file

@ -46,8 +46,7 @@ under sub ($c) {
$c->session(expiration => 604800);
$c->stash(status => 403)
if $c->flash('error') eq 'This message was flagged as spam';
$c->stash(status => 403) if $c->flash('error');
1;
};

View file

@ -15,9 +15,11 @@ my %form = (
answer => 'false'
);
$t->ua->max_redirects(1);
$t->get_ok('/')->status_is(200)
->text_is(h2 => 'Messages from the World Wide Web');
$t->get_ok('/sign')->status_is(200)->text_is(h2 => 'Sign the Guestbook');
$t->post_ok('/sign', form => \%form)->status_is(302);
$t->post_ok('/sign', form => \%form)->status_is(200);
done_testing();

35
t/validation.t Normal file
View file

@ -0,0 +1,35 @@
#!/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
);
$t->ua->max_redirects(1);
# Invalid input
$t->post_ok('/sign', form => \%invalid_form)->status_is(200)
->content_like(qr/cannot be blank/);
$t->post_ok('/sign', form => \%invalid_form)->status_is(200)
->content_like(qr/URL does not appear to be/);
# Spam test
$t->post_ok('/sign', form => \%spam_form)->status_is(403);
done_testing();