App-Dochazka-REST
view release on metacpan or search on metacpan
t/dispatch/interval_lock.t view on Meta::CPAN
req( $test, 405, 'demo', 'POST', "$base/1" );
req( $test, 405, 'active', 'POST', "$base/1" );
req( $test, 405, 'root', 'POST', "$base/1" );
note( 'DELETE' );
note( 'first make sure there is something to delete' );
$status = undef;
$status = req( $test, 200, 'root', 'GET', "$base/$test_id" );
is( $status->level, 'OK' );
ok( $status->{"payload"} );
is( $status->payload->{$idmap{$il}}, $test_id );
## - test with demo fail 403
#req( $test, 403, 'demo', 'DELETE', "$base/$test_id" );
##
## - test with active fail 403
#req( $test, 403, 'active', 'DELETE', "$base/$test_id" );
#
# - test with root success
#diag( "DELETE $base/$test_id" );
note( 'delete something testy' );
$status = req( $test, 200, 'root', 'DELETE', "$base/$test_id" );
is( $status->level, 'OK', "DELETE $base/:iid 3" );
is( $status->code, 'DOCHAZKA_CUD_OK', "DELETE $base/:iid 4" );
note( 'really gone' );
req( $test, 404, 'active', 'GET', "$base/$test_id" );
note( 'test with root fail invalid IID' );
req( $test, 400, 'root', 'DELETE', "$base/asd" );
}
note( 're-create the testing intervals' );
$test_iid = test_interval_new( $test );
$test_lid = create_testing_lock( $test );
note( '=============================' );
note( 'The "interval/new" resource ( see below for tests common to both "interval/new" and "lock/new" )' );
note( '=============================' );
my $base = 'interval/new';
docu_check($test, $base);
note( 'GET, PUT' );
foreach my $method ( 'GET', 'PUT' ) {
note( "Testing method: $method" );
foreach my $user ( 'demo', 'active', 'root', 'WOMBAT5', 'WAMBLE owdkmdf 5**' ) {
req( $test, 405, $user, $method, $base );
}
}
note( 'POST' );
note( '- instigate a "403 Forbidden"' );
foreach my $user ( qw( demo inactive ) ) {
req( $test, 403, $user, 'POST', $base, <<"EOH" );
{ "aid" : $aid_of_work, "intvl" : "[1957-01-02 08:00, 1957-01-03 08:00)" }
EOH
}
note( '- let active and root create themselves an interval and promptly delete it' );
foreach my $user ( qw( active root ) ) {
$status = req( $test, 201, $user, 'POST', $base, <<"EOH" );
{ "aid" : $aid_of_work, "intvl" : "[1957-01-02 08:00, 1957-01-03 08:00)" }
EOH
if ( $status->not_ok ) {
diag( "MARK foo3 $user" );
diag( Dumper $status );
BAIL_OUT(0);
}
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
ok( $status->{'payload'} );
ok( $status->{'payload'}->{'iid'} );
my $iid = $status->payload->{'iid'};
$status = req( $test, 200, $user, 'DELETE', "/interval/iid/$iid" );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
}
note( '- as long as all required properties are present, JSON with bogus properties' );
note( ' will be accepted for insert operation (bogus properties will be silently ignored)' );
foreach my $rb (
"{ \"aid\" : $aid_of_work, \"intvl\" : \"[1957-01-02 08:00, 1957-01-02 08:05)\", \"whinger\" : \"me\" }",
"{ \"aid\" : $aid_of_work, \"intvl\" : \"[1957-01-03 08:00, 1957-01-03 08:05)\", \"horse\" : \"E-Or\" }",
"{ \"aid\" : $aid_of_work, \"intvl\" : \"[1957-01-04 08:00, 1957-01-04 08:05)\", \"nine dogs\" : [ 1, 9 ] }",
) {
$status = req( $test, 201, 'root', 'POST', $base, $rb );
if ( $status->not_ok ) {
diag( "MARK foo4: $rb");
diag( Dumper $status );
BAIL_OUT(0);
}
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
ok( $status->{'payload'} );
ok( $status->{'payload'}->{'iid'} );
my $iid = $status->payload->{'iid'};
$status = req( $test, 200, 'root', 'DELETE', "/interval/iid/$iid" );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
}
note( '- required property missing' );
req( $test, 400, 'root', 'POST', $base, <<"EOH" );
{ "intvl" : "[1957-01-02 08:00, 1957-01-02 08:00)", "whinger" : "me" }
EOH
note( '- nonsensical JSON' );
req( $test, 400, 'root', 'POST', $base, 0 );
req( $test, 400, 'root', 'POST', $base, '[ 1, 2, [1, 2], { "wombat":"five" } ]' );
note( 'DELETE' );
req( $test, 405, 'demo', 'DELETE', $base );
req( $test, 405, 'root', 'DELETE', $base );
req( $test, 405, 'WOMBAT5', 'DELETE', $base );
note( '=============================' );
( run in 0.916 second using v1.01-cache-2.11-cpan-6aa56a78535 )