New testing

This commit is contained in:
swagg boi 2022-04-08 13:47:33 -04:00
parent 121ed5ab52
commit 6d9bf6ce36
6 changed files with 75 additions and 12 deletions

24
t/message.t Normal file
View file

@ -0,0 +1,24 @@
#!/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);
$t->ua->max_redirects(0);
# This one is not spam
$t->get_ok('/message/8')->status_is(200)
->text_is(h2 => 'Messages from the World Wide Web');
# This one _is_ spam
$t->get_ok('/message/19')->status_is(200)
->text_is(h2 => 'Messages from the World Wide Web');
# This one is deleted
$t->get_ok('/message/1')->status_is(404)
->text_is(h2 => 'Messages from the World Wide Web');
done_testing();

16
t/root_redirect.t Normal file
View file

@ -0,0 +1,16 @@
#!/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);
$t->ua->max_redirects(0);
$t->get_ok('/')->status_is(302);
done_testing();

View file

@ -20,9 +20,19 @@ my %spam_form = (
message => 'hi',
answer => 0
);
my %valid_form = (
name => 'swagg boi',
url => 'http://localhost',
message => 'Ayy... lmao',
answer => 'false'
);
$t->ua->max_redirects(1);
# Valid requests
$t->get_ok('/sign')->status_is(200)->text_is(h2 => 'Sign the Guestbook');
$t->post_ok('/sign', form => \%valid_form)->status_is(200);
# Invalid input
$t->post_ok('/sign', form => \%invalid_form)->status_is(200)
->content_like(qr/cannot be blank/);

View file

@ -8,20 +8,12 @@ use Test::Mojo;
my $script = curfile->dirname->sibling('guestbook-ng.pl');
my $t = Test::Mojo->new($script);
my %form = (
name => 'swagg boi',
url => 'http://localhost',
message => 'Ayy... lmao',
answer => 'false'
);
$t->ua->max_redirects(1);
$t->ua->max_redirects(0);
$t->get_ok('/')->status_is(200)
->text_is(h2 => 'Messages from the World Wide Web');
$t->get_ok('/spam')->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(200);
$t->get_ok('/spam/1')->status_is(200)
->text_is(h2 => 'Messages from the World Wide Web');
done_testing();

19
t/view.t Normal file
View file

@ -0,0 +1,19 @@
#!/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);
$t->ua->max_redirects(0);
$t->get_ok('/view')->status_is(200)
->text_is(h2 => 'Messages from the World Wide Web');
$t->get_ok('/view/1')->status_is(200)
->text_is(h2 => 'Messages from the World Wide Web');
done_testing();

View file

@ -1,10 +1,11 @@
% layout 'default';
% title 'View';
<h2>Messages from the World Wide Web</h2>
<% if (@$view_post[0]) { =%>
<div class="articles">
<article>
<span class="message_id field">
<%= link_to "#@$view_post[4]" => "/message/@$view_post[4]" %>
<%= link_to "#@$view_post[4]", "/message/@$view_post[4]" %>
</span>
<h3><%= @$view_post[0] %></h3>
<div class="message field">
@ -20,3 +21,4 @@
</div>
</article>
</div>
<% } =%>