App-Dochazka-REST
view release on metacpan or search on metacpan
map {
my $value = $status->payload->{$_};
ok( $value, "$_ property has value $value" );
} @props;
note( 'Ensure that LDAP user does not exist in Dochazka database' );
$status = App::Dochazka::REST::Model::Employee->load_by_nick( $dbix_conn, $ex );
$emp->delete( $faux_context ) if $status->ok;
note( 'Assert that LDAP user does not exist in Dochazka database' );
$status = App::Dochazka::REST::Model::Employee->load_by_nick( $dbix_conn, $ex );
is( $status->level, 'NOTICE' );
is( $status->code, 'DISPATCH_NO_RECORDS_FOUND', "nick doesn't exist" );
is( $status->{'count'}, 0, "nick doesn't exist" );
ok( ! exists $status->{'payload'} );
ok( ! defined( $status->payload ) );
note( "PUT employee/nick/$ex/ldap" );
$status = req( $test, 200, 'root', 'PUT', "employee/nick/$ex/ldap" );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
note( "Assert that $ex employee exists in Dochazka database" );
$status = App::Dochazka::REST::Model::Employee->load_by_nick( $dbix_conn, $ex );
is( $status->code, 'DISPATCH_RECORDS_FOUND', "Nick $ex exists" );
$emp = $status->payload;
is( $emp->nick, $ex, "Nick is the right string" );
note( "Assert that mapped properties have values" );
foreach my $prop ( @props ) {
ok( $emp->{$prop}, "$prop property has value " . $emp->{$prop} );
}
note( "Assert that employee $ex is a passerby" );
is( $emp->nick, $ex );
is( $emp->priv( $dbix_conn ), 'passerby' );
my $eid = $emp->eid;
ok( $eid > 0 );
note( "Make $ex an active employee" );
$status = req( $test, 201, 'root', 'POST', "priv/history/eid/$eid",
"{ \"effective\":\"1892-01-01\", \"priv\":\"active\" }" );
ok( $status->ok, "New privhistory record created for $ex" );
is( $status->code, 'DOCHAZKA_CUD_OK', "Status code is as expected" );
note( "Employee $ex is an active" );
is( $emp->priv( $dbix_conn ), 'active' );
note( "Depopulate fullname field" );
my $saved_fullname = $emp->fullname;
$emp->fullname( undef );
is( $emp->fullname, undef );
$status = $emp->update( $faux_context );
ok( $status->ok );
note( "Assert that fullname field is empty" );
$status = req( $test, 200, 'root', 'GET', "employee/nick/$ex" );
is( $status->level, 'OK' );
is( $status->payload->{fullname}, undef );
note( "Set password of employee $ex to \"$ex\"" );
$status = req( $test, 200, 'root', 'PUT', "employee/nick/$ex",
"{\"password\":\"$ex\"}" );
is( $status->level, 'OK' );
note( "PUT employee/nick/$ex/ldap" );
$status = req( $test, 200, $ex, 'PUT', "employee/nick/$ex/ldap" );
is( $status->level, 'OK' );
note( "Assert that fullname field is populated as expected" );
$status = req( $test, 200, 'root', 'GET', "employee/nick/$ex" );
is( $status->level, 'OK' );
is( $status->payload->{fullname}, $saved_fullname );
note( "Cleanup" );
$status = delete_all_attendance_data();
BAIL_OUT(0) unless $status->ok;
}
done_testing;
( run in 1.087 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )