App-Dochazka-REST
view release on metacpan or search on metacpan
t/dispatch/interval_lock.t view on Meta::CPAN
my $super = create_bare_employee( { nick => 'super', password => 'super' } );
my $eid_of_super = $super->eid;
my $status = req( $test, 201, 'root', 'POST', 'priv/history/nick/super', <<"EOH" );
{ "eid" : $eid_of_super, "priv" : "active", "effective" : "1967-06-17 00:00" }
EOH
is( $status->level, "OK" );
is( $status->code, "DOCHAZKA_CUD_OK" );
$status = req( $test, 200, 'root', 'GET', 'priv/nick/super' );
is( $status->level, "OK" );
is( $status->code, "DISPATCH_EMPLOYEE_PRIV" );
ok( $status->{'payload'} );
is( $status->{'payload'}->{'priv'}, 'active' );
note( 'create testing employee \'bubba\' with \'active\' privlevel' );
my $bubba = create_bare_employee( { nick => 'bubba', password => 'bubba' } );
my $eid_of_bubba = $bubba->eid;
$status = req( $test, 201, 'root', 'POST', 'priv/history/nick/bubba', <<"EOH" );
{ "eid" : $eid_of_bubba, "priv" : "active", "effective" : "1967-06-17 00:00" }
EOH
is( $status->level, "OK" );
is( $status->code, "DOCHAZKA_CUD_OK" );
$status = req( $test, 200, 'root', 'GET', 'priv/nick/bubba' );
is( $status->level, "OK" );
is( $status->code, "DISPATCH_EMPLOYEE_PRIV" );
ok( $status->{'payload'} );
is( $status->{'payload'}->{'priv'}, 'active' );
note( 'let super be active\'s supervisor' );
$status = req( $test, 200, 'root', 'PUT', 'employee/nick/active', <<"EOH" );
{ "supervisor" : $eid_of_super }
EOH
is( $status->level, "OK" );
is( $status->code, "DOCHAZKA_CUD_OK" );
sub test_interval_new {
my ( $test ) = @_;
# get AID of WORK
my $aid_of_work = get_aid_by_code( $test, 'WORK' );
note( 'in test_interval_new() function' );
$status = req( $test, 201, 'root', 'POST', 'interval/new', <<"EOH" );
{ "eid" : $eid_active, "aid" : $aid_of_work, "intvl" : "[2014-10-01 08:00, 2014-10-01 12:00)" }
EOH
if( $status->level ne 'OK' ) {
diag( Dumper $status );
BAIL_OUT(0);
}
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
ok( $status->{'payload'} );
is( $status->{'payload'}->{'aid'}, $aid_of_work );
ok( $status->{'payload'}->{'iid'} );
return $status->{'payload'}->{'iid'};
}
sub create_testing_lock {
my ( $test ) = @_;
note( 'in create_testing_lock() function' );
$status = req( $test, 201, 'root', 'POST', 'lock/new', <<"EOH" );
{ "eid" : $eid_active, "intvl" : "[2013-06-01 00:00, 2013-06-30 24:00)" }
EOH
if( $status->level ne 'OK' ) {
diag( Dumper $status );
BAIL_OUT(0);
}
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
ok( $status->{'payload'} );
ok( $status->{'payload'}->{'lid'} );
return $status->{'payload'}->{'lid'};
}
my $test_iid = test_interval_new( $test );
my $test_lid = create_testing_lock( $test );
my @failing_tsranges = (
'[]',
'{asf}',
'[2014-01-01: 2015-01-01)',
'wamble wumble womble',
);
note( '=============================' );
note( '"interval/eid/:eid/:tsrange" resource' );
note( '"lock/eid/:eid/:tsrange" resource' );
note( '=============================' );
foreach my $il ( qw( interval lock ) ) {
my $base = "$il/eid";
docu_check($test, "$base/:eid/:tsrange");
note( 'GET' );
note( 'root has no intervals but these users can\'t find that out' );
foreach my $user ( qw( demo inactive active ) ) {
req( $test, 403, $user, 'GET', "$base/1/[,)" );
}
note( 'active has one interval in 2014 and one lock in 2013' );
$status = req( $test, 200, 'root', 'GET',
"$base/$eid_active/[2013-01-01 00:00, 2014-12-31 24:00)" );
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_RECORDS_FOUND' );
is( $status->{'count'}, 1 );
foreach my $tsr ( @failing_tsranges ) {
note( 'tsranges that fail validations clause' );
foreach my $user ( qw( demo inactive active root ) ) {
req( $test, 400, $user, 'GET', "$base/1/$tsr" );
}
}
note( 'PUT, POST' );
foreach my $method ( qw( PUT POST ) ) {
note( 'Testing method: $method' );
foreach my $user ( 'demo', 'root', 'WAMBLE owdkmdf 5**' ) {
req( $test, 405, $user, $method, "$base/2/[,)" );
}
}
#note( 'DELETE' );
#foreach my $user ( 'demo', 'root', 'WAMBLE owdkmdf 5**' ) {
# req( $test, 403, $user, 'DELETE', "$base/2/[,)" );
#}
( run in 2.324 seconds using v1.01-cache-2.11-cpan-2398b32b56e )