diff --git a/README.md b/README.md index 4323244..24bd6f8 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,4 @@ Sequel to the smash hit ## TODOs -- Tests - Fill in placeholder comments diff --git a/hr2.pl b/hr2.pl old mode 100644 new mode 100755 index 881fa2d..c868de5 --- a/hr2.pl +++ b/hr2.pl @@ -3,6 +3,7 @@ # May 2025 # Jia Tan +use v5.40; use Mojolicious::Lite -signatures; use Mojo::Util qw{b64_decode b64_encode gunzip gzip diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/t/create.t b/t/create.t new file mode 100644 index 0000000..2f643d9 --- /dev/null +++ b/t/create.t @@ -0,0 +1,23 @@ +use Test::More; +use Mojo::File qw{curfile}; +use Test::Mojo; + +my $script = curfile->dirname->sibling('hr2.pl'); +my $t = Test::Mojo->new($script); +my $example = 'H4sIAKeZJ2gAA8soKSmw0tdPrUjMLchJ1UvOzwUArN4B1xIAAAA%3D%0A'; +my %hl_form = (hyperlink => 'http://example.com'); +my %mr_form = ( + 'hyperlink', $hl_form{'hyperlink'}, + 'meta-refresh', 1 + ); + +$t->get_ok('/create')->status_is(200) + ->text_like(h1 => qr/Create new hyperlink/); + +$t->post_ok('/create', form => \%hl_form)->status_is(200) + ->attr_like(a => href => qr/$example/); + +$t->post_ok('/create', form => \%hl_form)->status_is(200) + ->attr_like(a => href => qr/--meta-refresh\/$example/); + +done_testing; diff --git a/t/favicon.t b/t/favicon.t new file mode 100644 index 0000000..c8c49fb --- /dev/null +++ b/t/favicon.t @@ -0,0 +1,10 @@ +use Test::More; +use Mojo::File qw{curfile}; +use Test::Mojo; + +my $script = curfile->dirname->sibling('hr2.pl'); +my $t = Test::Mojo->new($script); + +$t->get_ok('/favicon.ico')->status_is(200); + +done_testing; diff --git a/t/hyperlink.t b/t/hyperlink.t new file mode 100644 index 0000000..38b9104 --- /dev/null +++ b/t/hyperlink.t @@ -0,0 +1,15 @@ +use Test::More; +use Mojo::File qw{curfile}; +use Test::Mojo; + +my $script = curfile->dirname->sibling('hr2.pl'); +my $t = Test::Mojo->new($script); +my $example = 'H4sIAKeZJ2gAA8soKSmw0tdPrUjMLchJ1UvOzwUArN4B1xIAAAA%3D%0A'; + +$t->get_ok("/$example")->status_is(302) + ->header_is(Location => 'http://example.com'); + +$t->get_ok("/--meta-refresh/$example")->status_is(200) + ->attr_like(meta => content => qr/http:\/\/example\.com/); + +done_testing; diff --git a/t/root.t b/t/root.t new file mode 100644 index 0000000..9dccd63 --- /dev/null +++ b/t/root.t @@ -0,0 +1,10 @@ +use Test::More; +use Mojo::File qw{curfile}; +use Test::Mojo; + +my $script = curfile->dirname->sibling('hr2.pl'); +my $t = Test::Mojo->new($script); + +$t->get_ok('/')->status_is(302)->header_like(Location => qr/create/); + +done_testing;