App-Dochazka-REST

 view release on metacpan or  search on metacpan

t/model/interval_lock.t  view on Meta::CPAN

    $status = $lock->delete( $faux_context );
    ok( $status->ok );
    ok( ! lid_exists( $dbix_conn, $lock->lid ) );
}
is( noof( $dbix_conn, 'locks' ), 0 );

note( 'second attempt to delete all intervals in the tsrange' );
$status = delete_intervals_by_eid_and_tsrange( 
    $dbix_conn, 
    $emp->eid, 
    "[$today 00:00, $tomorrow 24:00)",
);
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
is( $status->{'count'}, 1 );
is( $status->{'DBI_return_value'}, 1 );

note( 'create 80 intervals' );
my $d = $today;
my ( $by, $bm, $bd ) = $d =~ m/(\d+)-(\d+)-(\d+)/;
my ( $ey, $em, $ed ) = Add_Delta_Days( $by, $bm, $bd, 40 );
my $end_date = sprintf( "%04d-%02d-%02d", $ey, $em, $ed );
my $count = 0;
while ( $d ne $end_date ) {
    foreach my $intvl ( "[ $d 08:00, $d 12:00 )", "[ $d 12:30, $d 16:30 )" ) {
        $count += 1;
        $int->iid( undef );
        $int->intvl( $intvl );
        $status = $int->insert( $faux_context );
        is( $status->level, 'OK' );
        is( $status->code, 'DOCHAZKA_CUD_OK' );
        ok( $int->iid > 0 );
    }
    $d = get_tomorrow( $d );
}
is( $count, 80 );

note( 'and promptly delete them all' );
$status = delete_intervals_by_eid_and_tsrange( 
    $dbix_conn, 
    $emp->eid, 
    "[$today 00:00, $d 24:00)",
);
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
is( $status->{'count'}, 80 );
is( $status->{'DBI_return_value'}, 80 );

note( 'create 260 intervals' );
$d = $today;
( $by, $bm, $bd ) = $d =~ m/(\d+)-(\d+)-(\d+)/;
( $ey, $em, $ed ) = Add_Delta_Days( $by, $bm, $bd, 65 );
$end_date = sprintf( "%04d-%02d-%02d", $ey, $em, $ed );
$count = 0;
while ( $d ne $end_date ) {
    foreach my $intvl ( "[ $d 08:00, $d 10:00 )", "[ $d 10:00, $d 12:00 )", "[ $d 12:30, $d 14:30 )", "[ $d 14:30, $d 16:30 )" ) {
        $count += 1;
        $int->iid( undef );
        $int->intvl( $intvl );
        $status = $int->insert( $faux_context );
        if( $status->not_ok ) {
            diag( "Count: $count" );
            diag( Dumper $status );
            BAIL_OUT(0);
        }
        is( $status->level, 'OK' );
        is( $status->code, 'DOCHAZKA_CUD_OK' );
        ok( $int->iid > 0 );
    }
    $d = get_tomorrow( $d );
}
is( $count, 260 );

note( 'and try to delete them all, but fail because limit is 250 intervals deleted at one time' );
$status = delete_intervals_by_eid_and_tsrange( 
    $dbix_conn, 
    $emp->eid, 
    "[$today 00:00, $d 24:00)",
);
is( $status->level, 'ERR' );
is( $status->code, 'DOCHAZKA_INTERVAL_DELETE_LIMIT_EXCEEDED' );

note( 'delete them in two batches' );
my ( $my, $mm, $md ) = $d =~ m/(\d+)-(\d+)-(\d+)/;
( $my, $mm, $md ) = Add_Delta_Days( $my, $mm, $md, -30 );
my $mid_d = sprintf( "%04d-%02d-%02d", $my, $mm, $md );

note( 'first batch' );
$status = delete_intervals_by_eid_and_tsrange( 
    $dbix_conn, 
    $emp->eid, 
    "[$today 00:00, $mid_d 24:00)",
);
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
is( $status->{'count'}, 144 );
is( $status->{'DBI_return_value'}, 144 );

note( 'second batch' );
$status = delete_intervals_by_eid_and_tsrange( 
    $dbix_conn, 
    $emp->eid, 
    "[$mid_d 00:00, $d 24:00)",
);
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
is( $status->{'count'}, 116 );
is( $status->{'DBI_return_value'}, 116 );

note( 'delete the privhistory record' );
$status = $mrsched_ph->delete( $faux_context );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );

note( 'delete the schedhistory record' );
$status = $shr->delete( $faux_context );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );

note( 'delete the schedule' );
$status = App::Dochazka::REST::Model::Schedule->load_by_sid( $dbix_conn, $test_sid );



( run in 0.619 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )