App-Dochazka-REST
view release on metacpan or search on metacpan
$log->info( "=== $note" );
$intervals = $status->payload->{"success"}->{"intervals"};
is(scalar @$intervals, 6 );
like( $intervals->[0]->intvl, qr/^\["1998-06-08 10:05:00...","1998-06-08 12:00:00..."\)$/ );
like( $intervals->[1]->intvl, qr/^\["1998-06-08 12:30:00...","1998-06-08 16:30:00..."\)$/ );
like( $intervals->[2]->intvl, qr/^\["1998-06-09 08:00:00...","1998-06-09 12:00:00..."\)$/ );
like( $intervals->[3]->intvl, qr/^\["1998-06-09 12:30:00...","1998-06-09 14:00:00..."\)$/ );
like( $intervals->[4]->intvl, qr/^\["1998-06-09 14:15:00...","1998-06-09 16:30:00..."\)$/ );
like( $intervals->[5]->intvl, qr/^\["1998-06-10 08:00:00...","1998-06-10 10:00:00..."\)$/ );
note( $note = "Insert an interval that overlaps the end of the fillup tsrange" );
$log->info( "=== $note" );
my $conflict3 = App::Dochazka::REST::Model::Interval->spawn(
eid => $active->eid,
aid => $activity->aid,
intvl => "[ 1998-6-10 9:55, 1998-6-10 10:05 )",
);
$status = $conflict3->insert( $faux_context );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
note( $note = "Commit \$fo4 (dry_run, clobber), take six" );
$log->info( "=== $note" );
$fo4->clobber(1);
$status = $fo4->commit;
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_SCHEDULED_INTERVALS_IDENTIFIED' );
note( $note = "Commit \$fo4 (dry_run, clobber), take six, returned the same intervals as always" );
$log->info( "=== $note" );
$intervals = $status->payload->{"success"}->{"intervals"};
is(scalar @$intervals, 5 );
like( $intervals->[0]->intvl, qr/^\["1998-06-08 10:00:00...","1998-06-08 12:00:00..."\)$/ );
like( $intervals->[1]->intvl, qr/^\["1998-06-08 12:30:00...","1998-06-08 16:30:00..."\)$/ );
like( $intervals->[2]->intvl, qr/^\["1998-06-09 08:00:00...","1998-06-09 12:00:00..."\)$/ );
like( $intervals->[3]->intvl, qr/^\["1998-06-09 12:30:00...","1998-06-09 16:30:00..."\)$/ );
like( $intervals->[4]->intvl, qr/^\["1998-06-10 08:00:00...","1998-06-10 10:00:00..."\)$/ );
note( $note = "Commit \$fo4 (dry_run, no clobber)" );
$log->info( "=== $note" );
$fo4->clobber(0);
$status = $fo4->commit;
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_SCHEDULED_INTERVALS_IDENTIFIED' );
note( $note = "Commit \$fo4 (dry_run, no clobber) returned the expected intervals - i.e., the last interval ends at 09:55 instead of 10:00" );
$log->info( "=== $note" );
$intervals = $status->payload->{"success"}->{"intervals"};
is(scalar @$intervals, 6 );
foreach my $i ( 0..5 ) {
isa_ok( $intervals->[$i], 'App::Dochazka::REST::Model::Interval' );
is( $intervals->[$i]->iid, undef );
}
like( $intervals->[0]->intvl, qr/^\["1998-06-08 10:05:00...","1998-06-08 12:00:00..."\)$/ );
like( $intervals->[1]->intvl, qr/^\["1998-06-08 12:30:00...","1998-06-08 16:30:00..."\)$/ );
like( $intervals->[2]->intvl, qr/^\["1998-06-09 08:00:00...","1998-06-09 12:00:00..."\)$/ );
like( $intervals->[3]->intvl, qr/^\["1998-06-09 12:30:00...","1998-06-09 14:00:00..."\)$/ );
like( $intervals->[4]->intvl, qr/^\["1998-06-09 14:15:00...","1998-06-09 16:30:00..."\)$/ );
like( $intervals->[5]->intvl, qr/^\["1998-06-10 08:00:00...","1998-06-10 09:55:00..."\)$/ );
note( $note = "GET interval/nick/active/[ \"1998-06-08 00:00\", \"1998-06-10 24:00\" )" );
my @ARGS = (
$faux_context->{'dbix_conn'},
$active->eid,
"[ \"1998-06-08 00:00\", \"1998-06-10 24:00\" )",
);
$status = fetch_intervals_by_eid_and_tsrange( @ARGS );
$intervals = $status->payload;
is(scalar @$intervals, 3 );
isa_ok( $intervals->[0], 'App::Dochazka::REST::Model::Interval' );
ok( $intervals->[0]->iid > 0 );
like( $intervals->[0]->intvl, qr/^\["1998-06-08 09:55:00...","1998-06-08 10:05:00..."\)$/ );
isa_ok( $intervals->[1], 'App::Dochazka::REST::Model::Interval' );
ok( $intervals->[1]->iid > 0 );
like( $intervals->[1]->intvl, qr/^\["1998-06-09 14:00:00...","1998-06-09 14:15:00..."\)$/ );
isa_ok( $intervals->[2], 'App::Dochazka::REST::Model::Interval' );
ok( $intervals->[2]->iid > 0 );
like( $intervals->[2]->intvl, qr/^\["1998-06-10 09:55:00...","1998-06-10 10:05:00..."\)$/ );
note( $note = "Commit \$fo4 - really insert the records" );
$log->info( "=== $note" );
$fo4->dry_run(0);
$fo4->clobber(0);
$status = $fo4->commit;
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_SCHEDULED_INTERVALS_CREATED' );
note( $note = "Commit \$fo4 returned the expected intervals and they have iid populated" );
$log->info( "=== $note" );
$intervals = $status->payload->{"success"}->{"intervals"};
is(scalar @$intervals, 6 );
foreach my $i ( 0..5 ) {
isa_ok( $intervals->[$i], 'App::Dochazka::REST::Model::Interval' );
ok( $intervals->[$i]->iid > 0 );
}
like( $intervals->[0]->intvl, qr/^\["1998-06-08 10:05:00...","1998-06-08 12:00:00..."\)$/ );
like( $intervals->[1]->intvl, qr/^\["1998-06-08 12:30:00...","1998-06-08 16:30:00..."\)$/ );
like( $intervals->[2]->intvl, qr/^\["1998-06-09 08:00:00...","1998-06-09 12:00:00..."\)$/ );
like( $intervals->[3]->intvl, qr/^\["1998-06-09 12:30:00...","1998-06-09 14:00:00..."\)$/ );
like( $intervals->[4]->intvl, qr/^\["1998-06-09 14:15:00...","1998-06-09 16:30:00..."\)$/ );
like( $intervals->[5]->intvl, qr/^\["1998-06-10 08:00:00...","1998-06-10 09:55:00..."\)$/ );
note( $note = "GET interval/nick/active/[ \"1998-06-08 00:00\", \"1998-06-10 24:00\" )" );
my @ARGS = (
$faux_context->{'dbix_conn'},
$eids_to_delete[0],
"[ \"1998-06-08 00:00\", \"1998-06-10 24:00\" )",
);
$status = fetch_intervals_by_eid_and_tsrange( @ARGS );
$intervals = $status->payload;
is(scalar @$intervals, 9 );
foreach my $i ( 0..8 ) {
isa_ok( $intervals->[$i], 'App::Dochazka::REST::Model::Interval' );
ok( $intervals->[$i]->iid > 0 );
}
like( $intervals->[0]->intvl, qr/^\["1998-06-08 09:55:00...","1998-06-08 10:05:00..."\)$/ );
like( $intervals->[1]->intvl, qr/^\["1998-06-08 10:05:00...","1998-06-08 12:00:00..."\)$/ );
like( $intervals->[2]->intvl, qr/^\["1998-06-08 12:30:00...","1998-06-08 16:30:00..."\)$/ );
like( $intervals->[3]->intvl, qr/^\["1998-06-09 08:00:00...","1998-06-09 12:00:00..."\)$/ );
like( $intervals->[4]->intvl, qr/^\["1998-06-09 12:30:00...","1998-06-09 14:00:00..."\)$/ );
like( $intervals->[5]->intvl, qr/^\["1998-06-09 14:00:00...","1998-06-09 14:15:00..."\)$/ );
like( $intervals->[6]->intvl, qr/^\["1998-06-09 14:15:00...","1998-06-09 16:30:00..."\)$/ );
like( $intervals->[7]->intvl, qr/^\["1998-06-10 08:00:00...","1998-06-10 09:55:00..."\)$/ );
like( $intervals->[8]->intvl, qr/^\["1998-06-10 09:55:00...","1998-06-10 10:05:00..."\)$/ );
note( $note = 'create a second testing schedule, exactly like the first except MON 08:00-12:00 is dropped' );
$log->info( "=== $note" );
my $schedule2 = test_schedule_model( [
'[ 1998-05-04 12:30, 1998-05-04 16:30 )',
'[ 1998-05-05 08:00, 1998-05-05 12:00 )',
'[ 1998-05-05 12:30, 1998-05-05 16:30 )',
'[ 1998-05-06 08:00, 1998-05-06 12:00 )',
'[ 1998-05-06 12:30, 1998-05-06 16:30 )',
'[ 1998-05-07 08:00, 1998-05-07 12:00 )',
'[ 1998-05-07 12:30, 1998-05-07 16:30 )',
'[ 1998-05-08 08:00, 1998-05-08 12:00 )',
'[ 1998-05-08 12:30, 1998-05-08 16:30 )',
] );
push my @sids_to_delete, $schedule2->sid;
note( $note = "Put the second schedule in active\'s schedhistory, so we can test Fillup over a tsrange that has a schedule change in the middle of it" );
$log->info( "=== $note" );
my $second_active_eid = $active->eid;
is( $first_active_eid, $second_active_eid );
my $schedhistory2 = App::Dochazka::REST::Model::Schedhistory->spawn(
eid => $active->eid,
sid => $schedule2->sid,
effective => "1998-06-15 00:00",
remark => 'TESTING',
);
isa_ok( $schedhistory2, 'App::Dochazka::REST::Model::Schedhistory', "schedhistory object is an object" );
$status = $schedhistory2->insert( $faux_context );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
push my @shids_to_delete, $schedhistory2->shid;
is( noof( $dbix_conn, "schedhistory" ), 2 );
note( $note = "Get the prevailing schedule at \"1998-06-14 08:00:00\" and \"1998-06-15 08:00:00\" in order to assert there is a schedule change during the Fillup interval" );
$log->info( "=== $note" );
ok( $schedule1->sid > 0 );
ok( $schedule2->sid > 0 );
ok( $schedule1->sid != $schedule2->sid );
is( schedule_by_eid( $dbix_conn, $active->eid, "1998-06-14 08:00:00" ), $schedule1->sid );
#diag( "\$schedule1->sid == " . $schedule1->sid );
is( schedule_by_eid( $dbix_conn, $active->eid, "1998-06-15 08:00:00" ), $schedule2->sid );
#diag( "\$schedule2->sid == " . $schedule2->sid );
ok( ! $active->schedule_change_during_range( $dbix_conn, '[ 1900-06-14 00:00:00, 1900-06-16 24:00:00 )' ) );
( run in 1.157 second using v1.01-cache-2.11-cpan-2398b32b56e )