From 4c5626c9efb28d7f955bd955b7e505c801fcde40 Mon Sep 17 00:00:00 2001 From: barnold Date: Thu, 29 Sep 2022 13:10:43 +0100 Subject: [PATCH] Get tests passing again. --- t/basic.t | 13 +++---------- t/notfound.t | 16 +++++++++------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/t/basic.t b/t/basic.t index 477af2d..2992563 100644 --- a/t/basic.t +++ b/t/basic.t @@ -1,20 +1,13 @@ use Mojo::Base -strict; use Test2::V0; +use Test2::Plugin::BailOnFail; use Test::Mojo; my $t = Test::Mojo->new('MyApp'); -$t->get_ok('/')->status_is(200)->content_like(qr/home/i); +$t->get_ok('/')->status_is(200)->content_like(qr/Books/); $t->get_ok('/about')->status_is(200)->content_like(qr/about/i); -# No way to follow the redirect? -$t->get_ok('/account')->status_is(302); -$t->get_ok('/auth')->status_is(200)->content_like(qr/login/i); -$t->post_ok('/login' => form => { logname => 'Dobby' }); -$t->get_ok('/account')->status_is(200)->content_like(qr/dobby/i); -$t->get_ok('/books/1')->status_is(200)->content_like(qr/[[:digit:]] books/i); +$t->get_ok('/1')->status_is(200)->content_like(qr/[[:digit:]] books/i); $t->get_ok('/authors/1')->status_is(200)->content_like(qr/[[:digit:]] authors/i); -$t->get_ok('/logout')->status_is(302); -# Can't do "content_unlike()" so check it offers login now. -$t->get_ok('/')->status_is(200)->content_like(qr/login/i); done_testing(); diff --git a/t/notfound.t b/t/notfound.t index 9e56dcc..acc06a0 100644 --- a/t/notfound.t +++ b/t/notfound.t @@ -1,24 +1,26 @@ use Mojo::Base -strict; use Test2::V0; +use Test2::Plugin::BailOnFail; use Test::Mojo; my $t = Test::Mojo->new('MyApp'); # Page zero gets a redirect. -$t->get_ok('/books/0')->status_is(302); +$t->get_ok('/0')->status_is(302); # Now follow redirects and verify it's a 404. $t->ua->max_redirects(10); -$t->get_ok('/books/0')->status_is(404); +$t->get_ok('/0')->status_is(404); -# Likewise for a too-high page number. -$t->get_ok('/books/999?title_like=qxqxqxqx')->status_is(404); +# A too-high page number should take us to the last page. +$t->get_ok('/999?title_like=qxqxqxqx')->status_is(200) + ->content_like(qr/0\s+books\s+of\s+0/); # Likewise for invalid page numbers. -$t->get_ok('/books/x')->status_is(404); -$t->get_ok('/books/1.99')->status_is(404); -$t->get_ok('/books/-42')->status_is(404); +$t->get_ok('/x')->status_is(404); +$t->get_ok('/1.99')->status_is(404); +$t->get_ok('/-42')->status_is(404); # Or non-existent author. $t->get_ok('/author/0/1')->status_is(404);