App-Dochazka-REST
view release on metacpan or search on metacpan
t/model/interval_lock.t view on Meta::CPAN
$dbix_conn,
$emp->eid,
"[ $today 05:00, $today 10:00 )",
);
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_RECORDS_FOUND' );
is( $status->{count}, 2 );
is( $status->payload->[0]->partial, 0 );
is( $status->payload->[0]->iid, $dozing_off->iid );
is( $status->payload->[1]->partial, 1 );
is( $status->payload->[1]->iid, $int->iid );
note( 'test DOCHAZKA_PARTIAL_INTERVAL_ILLEGAL_OPERATION' );
note( '(no database operations allowed on partial intervals' );
my $partial_int = $status->payload->[1];
$status = $partial_int->insert( $faux_context );
is( $status->level, 'ERR' );
is( $status->code, 'DOCHAZKA_PARTIAL_INTERVAL_ILLEGAL_OPERATION' );
$status = $partial_int->update( $faux_context );
is( $status->level, 'ERR' );
is( $status->code, 'DOCHAZKA_PARTIAL_INTERVAL_ILLEGAL_OPERATION' );
$status = $partial_int->delete( $faux_context );
is( $status->level, 'ERR' );
is( $status->code, 'DOCHAZKA_PARTIAL_INTERVAL_ILLEGAL_OPERATION' );
note( 'delete the "Dozing off" interval' );
$status = $dozing_off->delete( $faux_context );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
note( 'load_by_iid' );
$status = App::Dochazka::REST::Model::Interval->load_by_iid( $dbix_conn, $saved_iid );
diag( $status->text ) unless $status->ok;
ok( $status->ok );
is( $status->code, 'DISPATCH_RECORDS_FOUND' );
my $newint = $status->payload;
is( $newint->long_desc, "Pencil pushing" );
my $t_iid = $newint->iid;
note( 'insert a lock covering the entire day' );
note( 'spawn a lock object' );
my $lock = App::Dochazka::REST::Model::Lock->spawn(
eid => $emp->eid,
intvl => "[$today 00:00, $today 24:00)",
remark => 'TESTING',
);
isa_ok( $lock, 'App::Dochazka::REST::Model::Lock' );
#diag( Dumper( $lock ) );
note( 'insert the lock object' );
is( noof( $dbix_conn, 'locks' ), 0 );
$status = $lock->insert( $faux_context );
is( noof( $dbix_conn, 'locks' ), 1 );
push @locks_to_delete, $lock;
note( 'attept to delete the testing interval' );
$status = $int->delete( $faux_context );
is( $status->level, 'ERR' );
is( $status->code, 'DOCHAZKA_DBI_ERR' );
like( $status->text, qr/interval is locked/ );
note( 'now test history_policy triggers:' );
note( '1. the interval runs from 08:00 - 12:00 today' );
note( '2. so attempt to insert a privhistory record effective 10:00 today' );
note( ' -- i.e., a clear policy violation' );
my $vio_ph = App::Dochazka::REST::Model::Privhistory->spawn(
eid => $emp->eid,
priv => 'passerby',
effective => "$today 10:00"
);
$status = $vio_ph->insert( $faux_context );
is( $status->level, 'ERR' );
is( $status->code, 'DOCHAZKA_DBI_ERR' );
like( $status->text, qr/effective timestamp conflicts with existing attendance interval/ );
note( 'do the same with schedhistory' );
my $vio_sh = App::Dochazka::REST::Model::Schedhistory->spawn(
eid => $emp->eid,
sid => $test_sid,
effective => "$today 10:00"
);
$status = $vio_ph->insert( $faux_context );
is( $status->level, 'ERR' );
is( $status->code, 'DOCHAZKA_DBI_ERR' );
like( $status->text, qr/effective timestamp conflicts with existing attendance interval/ );
note( 'test count_locks_in_tsrange()' );
note( 'the lock interval is [$today 00:00, $today 24:00)' );
note( 'so the answer should be resoundingly 1' );
$status = count_locks_in_tsrange( $dbix_conn, $emp->eid, "[$today 00:00, $today 24:00)" );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_NUMBER_OF_LOCKS' );
is( ref( $status->payload ), '' );
is( $status->payload, 1 );
note( 'yesterday should contain 0 locks' );
$status = count_locks_in_tsrange( $dbix_conn, $emp->eid, "[$yesterday 00:00, $yesterday 24:00)" );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_NUMBER_OF_LOCKS' );
is( ref( $status->payload ), '' );
is( $status->payload, 0 );
note( 'same for tomorrow' );
$status = count_locks_in_tsrange( $dbix_conn, $emp->eid, "[$tomorrow 00:00, $tomorrow 24:00)" );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_NUMBER_OF_LOCKS' );
is( ref( $status->payload ), '' );
is( $status->payload, 0 );
note( 'try a tsrange just for the heck of it' );
$status = count_locks_in_tsrange( $dbix_conn, $emp->eid, "[$today 23:00, $tomorrow 1:00)" );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_NUMBER_OF_LOCKS' );
is( ref( $status->payload ), '' );
is( $status->payload, 1 );
note( 'add another lock' );
note( 'spawn a lock object for tomorrow' );
$lock = App::Dochazka::REST::Model::Lock->spawn(
( run in 0.407 second using v1.01-cache-2.11-cpan-524268b4103 )