2017-04-24 16:42:07 +00:00
|
|
|
use Mojo::Base -strict;
|
2017-04-08 12:38:54 +00:00
|
|
|
|
|
|
|
use Test::More;
|
2017-04-24 16:42:07 +00:00
|
|
|
use Mojo::JSON;
|
|
|
|
use Test::Pear::LocalLoop;
|
|
|
|
|
|
|
|
my $framework = Test::Pear::LocalLoop->new;
|
|
|
|
my $t = $framework->framework;
|
2017-04-08 12:38:54 +00:00
|
|
|
my $schema = $t->app->schema;
|
|
|
|
|
|
|
|
$schema->resultset('User')->create({
|
|
|
|
email => 'admin@example.com',
|
2017-04-21 19:52:14 +00:00
|
|
|
password => 'abc123',
|
2017-04-08 12:38:54 +00:00
|
|
|
administrator => {},
|
|
|
|
});
|
|
|
|
|
|
|
|
$schema->resultset('User')->create({
|
|
|
|
email => 'user@example.com',
|
2017-04-21 19:52:14 +00:00
|
|
|
password => 'abc123',
|
2017-04-08 12:38:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
is $schema->resultset('User')->count, 2, 'Users Created';
|
|
|
|
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
|
|
|
|
|
|
|
|
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')
|
2017-04-24 16:42:07 +00:00
|
|
|
->status_is(200)->or($framework->dump_error);
|
2017-04-08 12:38:54 +00:00
|
|
|
|
|
|
|
$t->ua->max_redirects(10);
|
2017-04-24 16:42:07 +00:00
|
|
|
$t->post_ok('/admin', form => {
|
2017-04-08 12:38:54 +00:00
|
|
|
email => 'user@example.com',
|
|
|
|
password => 'abc123',
|
2017-04-08 13:25:06 +00:00
|
|
|
})->status_is(200);
|
2017-04-08 12:38:54 +00:00
|
|
|
|
|
|
|
$t->ua->max_redirects(0);
|
2017-04-08 13:25:06 +00:00
|
|
|
$t->get_ok('/admin')
|
2017-04-24 16:42:07 +00:00
|
|
|
->status_is(200);
|
2017-04-08 12:38:54 +00:00
|
|
|
|
2017-04-24 16:42:07 +00:00
|
|
|
$t->get_ok('/admin/logout')
|
2017-04-08 12:38:54 +00:00
|
|
|
->status_is(302)
|
2017-04-24 16:42:07 +00:00
|
|
|
->$location_is('/admin');
|
2017-04-08 12:38:54 +00:00
|
|
|
|
2017-04-08 13:25:06 +00:00
|
|
|
$t->get_ok('/admin')
|
2017-04-24 16:42:07 +00:00
|
|
|
->status_is(200);
|
2017-04-08 12:38:54 +00:00
|
|
|
|
|
|
|
$t->ua->max_redirects(10);
|
2017-04-24 16:42:07 +00:00
|
|
|
$t->post_ok('/admin', form => {
|
2017-04-08 12:38:54 +00:00
|
|
|
email => 'admin@example.com',
|
|
|
|
password => 'abc123',
|
2017-04-08 13:25:06 +00:00
|
|
|
})->status_is(200);
|
2017-04-08 12:38:54 +00:00
|
|
|
|
|
|
|
$t->ua->max_redirects(0);
|
2017-04-24 16:42:07 +00:00
|
|
|
$t->get_ok('/admin/home')
|
2017-04-08 12:38:54 +00:00
|
|
|
->status_is(200)
|
|
|
|
->content_like(qr/Admin/);
|
|
|
|
|
2017-04-24 16:42:07 +00:00
|
|
|
$t->get_ok('/admin/logout')
|
2017-04-08 12:38:54 +00:00
|
|
|
->status_is(302)
|
2017-04-24 16:42:07 +00:00
|
|
|
->$location_is('/admin');
|
2017-04-08 12:38:54 +00:00
|
|
|
|
2017-04-08 13:25:06 +00:00
|
|
|
$t->get_ok('/admin')
|
2017-04-24 16:42:07 +00:00
|
|
|
->status_is(200);
|
2017-04-08 12:38:54 +00:00
|
|
|
|
|
|
|
done_testing;
|
|
|
|
|