From 6d9bf6ce36094458c4cca8944b141f2bd9a8d72a Mon Sep 17 00:00:00 2001 From: swag Date: Fri, 8 Apr 2022 13:47:33 -0400 Subject: [PATCH] New testing --- t/message.t | 24 ++++++++++++++++++++++++ t/root_redirect.t | 16 ++++++++++++++++ t/{validation.t => sign.t} | 10 ++++++++++ t/{basic.t => spam.t} | 14 +++----------- t/view.t | 19 +++++++++++++++++++ templates/message_id.html.ep | 4 +++- 6 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 t/message.t create mode 100644 t/root_redirect.t rename t/{validation.t => sign.t} (73%) rename t/{basic.t => spam.t} (53%) create mode 100644 t/view.t diff --git a/t/message.t b/t/message.t new file mode 100644 index 0000000..0cd5d8c --- /dev/null +++ b/t/message.t @@ -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(); diff --git a/t/root_redirect.t b/t/root_redirect.t new file mode 100644 index 0000000..8909c75 --- /dev/null +++ b/t/root_redirect.t @@ -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(); diff --git a/t/validation.t b/t/sign.t similarity index 73% rename from t/validation.t rename to t/sign.t index 8bed2f4..4df9a12 100644 --- a/t/validation.t +++ b/t/sign.t @@ -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/); diff --git a/t/basic.t b/t/spam.t similarity index 53% rename from t/basic.t rename to t/spam.t index b5aea2b..958b558 100644 --- a/t/basic.t +++ b/t/spam.t @@ -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(); diff --git a/t/view.t b/t/view.t new file mode 100644 index 0000000..54a9a04 --- /dev/null +++ b/t/view.t @@ -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(); diff --git a/templates/message_id.html.ep b/templates/message_id.html.ep index 6ceffe7..5d67bca 100644 --- a/templates/message_id.html.ep +++ b/templates/message_id.html.ep @@ -1,10 +1,11 @@ % layout 'default'; % title 'View';

Messages from the World Wide Web

+<% if (@$view_post[0]) { =%>
- <%= link_to "#@$view_post[4]" => "/message/@$view_post[4]" %> + <%= link_to "#@$view_post[4]", "/message/@$view_post[4]" %>

<%= @$view_post[0] %>

@@ -20,3 +21,4 @@
+<% } =%>