App-Dochazka-REST
view release on metacpan or search on metacpan
t/model/interval_lock.t view on Meta::CPAN
is( $status->code, 'DISPATCH_RECORDS_FOUND' );
is( $status->{count}, 1 );
my $found_interval = $status->payload->[0];
is( ref( $found_interval ), 'App::Dochazka::REST::Model::Interval' );
ok( $found_interval->partial, "Found interval is a partial interval" );
ok( tsrange_equal( $dbix_conn, $search_interval, $found_interval->intvl ),
'the partial interval found is the same as the one we searched for' );
note( 'partial interval #2 - overlaps start' );
$search_interval = "[ $today 07:00, $today 11:00 )";
$status = fetch_intervals_by_eid_and_tsrange(
$dbix_conn,
$emp->eid,
$search_interval,
);
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_RECORDS_FOUND' );
is( $status->{count}, 1 );
$found_interval = $status->payload->[0];
is( ref( $found_interval ), 'App::Dochazka::REST::Model::Interval' );
ok( $found_interval->partial, "Found interval is a partial interval" );
ok( tsrange_equal( $dbix_conn, "[ $today 08:00, $today 11:00 )", $found_interval->intvl ),
'the partial interval found is the same as the one we searched for' );
note( 'partial interval #3 - overlaps end' );
$search_interval = "[ $today 11:00, $today 13:00 )";
$status = fetch_intervals_by_eid_and_tsrange(
$dbix_conn,
$emp->eid,
$search_interval,
);
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_RECORDS_FOUND' );
is( $status->{count}, 1 );
$found_interval = $status->payload->[0];
is( ref( $found_interval ), 'App::Dochazka::REST::Model::Interval' );
ok( $found_interval->partial, "Found interval is a partial interval" );
ok( tsrange_equal( $dbix_conn, "[ $today 11:00, $today 12:00 )", $found_interval->intvl ),
'the partial interval found is the same as the one we searched for' );
note( 'test accessors' );
ok( $int->iid > 0 );
is( $int->eid, $emp->eid );
is( $int->aid, $work->aid );
ok( tsrange_equal( $dbix_conn, $int->intvl, $intvl ) );
is( $int->long_desc, 'Pencil pushing' );
is( $int->remark, 'TEST INTERVAL' );
note( 'spawn another interval object (Dozing off)' );
my $dozing_off = App::Dochazka::REST::Model::Interval->spawn(
eid => $emp->eid,
aid => $work->aid,
intvl => "[ $today 05:00, $today 06:00 )",
long_desc => "Dozing off",
);
isa_ok( $dozing_off, 'App::Dochazka::REST::Model::Interval' );
$status = $dozing_off->insert( $faux_context);
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
note( 'retrieve intervals and verify they are in temporal order' );
$status = fetch_intervals_by_eid_and_tsrange(
$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' );
( run in 1.956 second using v1.01-cache-2.11-cpan-e1769b4cff6 )