Skip to content

Instantly share code, notes, and snippets.

@jasonblewis
Created February 18, 2016 04:02
Show Gist options
  • Save jasonblewis/fdefa44455b28c3e243b to your computer and use it in GitHub Desktop.
Save jasonblewis/fdefa44455b28c3e243b to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Test::More tests => 7;
use Test::WWW::Mechanize::PSGI;
use_ok 'Reports';
my %routes = ('/' => undef,
'/accounts-receivable' => undef,
'/accounts-payable' => undef,
'/business-metrics' => {TODO => 1 },
'/sales' => undef);
my $app = Reports->to_app;
isa_ok( $app, 'CODE' );
my $mech = Test::WWW::Mechanize::PSGI->new(
app => $app,
max_redirect => 0
);
$mech->get('/');
ok $mech->status eq '302', "/" or diag $mech->status;
my $loc = $mech->response->header('Location');
is $loc, 'http://localhost/login?return_url=%2F', '/ redirects to /login' or diag "Location header: $loc";
$mech->get($loc);
ok $mech->status eq '401', "login page" or diag $mech->status;
$mech->submit_form(
form_number => 1,
fields => { username => 'test',
password => 'test' },
) or diag "died on submit";
diag "mech success: $mech->success";
$loc = $mech->response->header('Location');
diag "loc: $loc";
$mech->get_ok($loc);
my $base = $mech->base;
diag "base: $base";
subtest 'all routes work' => sub {
plan tests => scalar keys %routes;
for my $route (keys %routes) {
unless (defined $routes{$route}{TODO} ) {
$mech->get_ok($base->new_abs($route,$base));
} else {
TODO: { $mech->get_ok ($base->new_abs($route,$base));
}
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment