This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/t/admin/login.t

63 lines
1.2 KiB
Perl
Raw Normal View History

use Mojo::Base -strict;
2017-04-08 12:38:54 +00:00
use FindBin qw/ $Bin /;
2017-04-08 12:38:54 +00:00
use Test::More;
use Test::Pear::LocalLoop;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/../etc",
);
$framework->install_fixtures('users');
my $t = $framework->framework;
2017-04-08 12:38:54 +00:00
my $schema = $t->app->schema;
my $location_is = sub {
my ($t, $value, $desc) = @_;
$desc ||= "Location: $value";
local $Test::Builder::Level = $Test::Builder::Level + 1;
return $t->success(is($t->tx->res->headers->location, $value, $desc));
};
$t->get_ok('/admin')
->status_is(200)->or($framework->dump_error);
2017-04-08 12:38:54 +00:00
$t->ua->max_redirects(10);
$t->post_ok('/admin', form => {
email => 'test1@example.com',
2017-04-08 12:38:54 +00:00
password => 'abc123',
})->status_is(200);
2017-04-08 12:38:54 +00:00
$t->ua->max_redirects(0);
$t->get_ok('/admin')
->status_is(200);
2017-04-08 12:38:54 +00:00
$t->get_ok('/admin/logout')
2017-04-08 12:38:54 +00:00
->status_is(302)
->$location_is('/admin');
2017-04-08 12:38:54 +00:00
$t->get_ok('/admin')
->status_is(200);
2017-04-08 12:38:54 +00:00
$t->ua->max_redirects(10);
$t->post_ok('/admin', form => {
2017-04-08 12:38:54 +00:00
email => 'admin@example.com',
password => 'abc123',
})->status_is(200);
2017-04-08 12:38:54 +00:00
$t->ua->max_redirects(0);
$t->get_ok('/admin/home')
2017-04-08 12:38:54 +00:00
->status_is(200)
->content_like(qr/Admin/);
$t->get_ok('/admin/logout')
2017-04-08 12:38:54 +00:00
->status_is(302)
->$location_is('/admin');
2017-04-08 12:38:54 +00:00
$t->get_ok('/admin')
->status_is(200);
2017-04-08 12:38:54 +00:00
done_testing;