]>
iEval git - gruntmaster-page.git/blob - t/mech.t
5 use Test
::MockTime
':all';
6 use Test
::More tests
=> 14;
7 use Test
::WWW
::Mechanize
::PSGI
;
10 use JSON
::MaybeXS qw
/decode_json/;
11 use Log
::Log4perl qw
/:easy/;
15 my $mech = Test
::WWW
::Mechanize
::PSGI
->new(app
=> do 'app.psgi');
19 Log
::Log4perl
->easy_init($OFF);
22 my ($url, $expect_fail) = @_;
23 my $param = $url =~ /[?]/ ?
'&format=json' : '?format=json';
24 $expect_fail ?
$mech->get("$url$param") : $mech->get_ok("$url$param");
25 $result = $mech->response->code;
26 $content = $result == 200 ? decode_json
$mech->content(decoded_by_headers
=> 1) : '';
29 our $db = Gruntmaster
::Data
->connect('dbi:SQLite:dbname=:memory:');
32 $db->users->create({id
=> 'MGV', admin
=> 1});
33 $db->contests->create({id
=> 'fc', start
=> 10, stop
=> 20, name
=> 'Finished contest', owner
=> 'MGV'});
34 $db->contests->create({id
=> 'rc', start
=> 20, stop
=> 30, name
=> 'Running contest', owner
=> 'MGV'});
35 $db->contests->create({id
=> 'pc', start
=> 30, stop
=> 40, name
=> 'Pending contest', owner
=> 'MGV'});
50 $db->problems->create({id
=> 'fca', private
=> 0, @pbjunk});
51 $db->problems->create({id
=> 'rca', private
=> 0, @pbjunk});
52 $db->problems->create({id
=> 'pca', private
=> 0, @pbjunk});
53 $db->problems->create({id
=> 'arc', private
=> 0, @pbjunk});
54 $db->problems->create({id
=> 'prv', private
=> 1, @pbjunk});
55 $db->contest_problems->create({problem
=> "${_}a", contest
=> $_}) for qw
/fc rc pc/;
57 sub problem_list
() { [sort map {$_->{id
}} @
{$content->{beginner
}}] }
59 is_deeply problem_list
, [qw
/arc fca/], '/pb/ has correct problems';
60 get
'/pb/?contest=pc', 1;
61 is
$result, 401, '/pb/?contest=pc returns 401';
62 get
'/pb/?contest=rc';
63 is_deeply problem_list
, [qw
/rca/], '/pb/?contest=rc has correct problems';
64 get
'/pb/?contest=fc';
65 is_deeply problem_list
, [qw
/fca/], '/pb/?contest=fc has correct problems';
68 my ($mgv) = @
{$content->{us
}};
69 is
$mgv->{id
}, 'MGV', 'first (and only) user is MGV';
70 is
$mgv->{admin
}, 1, 'MGV is an admin';
73 my $pc = $content->{pending
}->[0];
74 my $rc = $content->{running
}->[0];
75 my $fc = $content->{finished
}->[0];
76 is
$pc->{id
}, 'pc', 'pc is pending';
77 is
$rc->{id
}, 'rc', 'rc is running';
78 is
$fc->{id
}, 'fc', 'fc is running';
This page took 0.064195 seconds and 4 git commands to generate.