App-Dochazka-REST
view release on metacpan or search on metacpan
- t/dispatch/employee.t: add test cases for POST employee/{current,self} by
inactive and active employees; adapt tests to current state
0.281 2014-11-14 16:42 CET
- finish implementation (including test cases) of POST dispatch
target for 'employee/{current,self}' resource
0.282 2014-11-14 21:36 CET
- dbinit_Config.pm: add trigger clause to make 'sid' field immutable
- Docs/Workflow.pm: add verbiage
- t/model/schedule.t: add test case verifying that 'update' method does not
change the database even if the 'sid' field is changed
0.283 2014-11-18 07:45 CET
- REST_Message_en.conf: add finer-grained notice messages for 'cud'
- Model/Shared.pm: in cud, check return value of '$sth->execute' and
return finer-grained notices to distinguish various edge cases
- t/: adapt to current state
0.284 2014-11-18 11:01 CET
- unit tests: move existing '002-root' and '003-current-priv' units to
codes
0.415 2015-03-30 17:29 CEST
- require App::Dochazka 0.186 for 'scode' property in schedule class
- make test suite tolerate 'scode' property
- t/sql/schedule_Config.pm: add scode property to all SQL statements where it
makes sense
- implement 'schedule/scode/:scode' property with basic test cases
0.416 2015-04-01 09:39 CEST
- t/dispatch/schedule.t: trying to verify with tests that the new schedule
insert logic really does what we want
0.417 2015-04-02 22:06 CEST
- use TDD to get what we want: POST schedule/new ignores scode value when given
schedule exactly matches an existing schedule with a different (non-NULL)
scode
0.418 2015-04-03 09:08 CEST
- SQL: split 'disabled_to_zero' function/triggers into separate variants for
insert and update; confidently add 'NOT NULL' constraint to 'disabled' fields
lib/App/Dochazka/REST/Docs/Resources.pm view on Meta::CPAN
=head2 C<< schedule/new >>
=over
Allowed methods: POST
Given a set of intervals, all of which must fall within a single contiguous
168-hour (7-day) period, this resource performs all actions necessary to either
create a new schedule from those intervals or verify that an equivalent
schedule already exists.
Sample JSON:
{ "schedule" : [
"[2014-09-22 08:00, 2014-09-22 12:00)",
"[2014-09-22 12:30, 2014-09-22 16:30)",
"[2014-09-23 08:00, 2014-09-23 12:00)",
"[2014-09-23 12:30, 2014-09-23 16:30)",
"[2014-09-24 08:00, 2014-09-24 12:00)",
lib/App/Dochazka/REST/Model/Shared.pm view on Meta::CPAN
=item * Database error
Level C<ERR>, code C<DOCHAZKA_DBI_ERR>, text: error message, payload: none
=back
=cut
sub load {
# get and verify arguments
my %ARGS = validate( @_, {
conn => { isa => 'DBIx::Connector' },
class => { type => SCALAR },
sql => { type => SCALAR },
keys => { type => ARRAYREF },
} );
# consult the database; N.B. - select may only return a single record
my ( $hr, $status );
try {
lib/App/Dochazka/REST/Model/Shared.pm view on Meta::CPAN
The return value will be a status object, the payload of which will be an
arrayref containing a set of objects. The objects are constructed by calling
$ARGS{'class'}->spawn
For convenience, a 'count' property will be included in the status object.
=cut
sub load_multiple {
# get and verify arguments
my %ARGS = validate( @_, {
conn => { isa => 'DBIx::Connector' },
class => { type => SCALAR },
sql => { type => SCALAR },
keys => { type => ARRAYREF },
} );
$log->debug( "Entering " . __PACKAGE__ . "::load_multiple" );
my $status;
my $results = [];
lib/App/Dochazka/REST/ResourceDefs.pm view on Meta::CPAN
POST => 'handler_schedule_new',
},
acl_profile => 'admin',
cli => 'schedule new $JSON',
description => 'Insert schedules',
documentation => <<'EOH',
=pod
Given a set of intervals, all of which must fall within a single contiguous
168-hour (7-day) period, this resource performs all actions necessary to either
create a new schedule from those intervals or verify that an equivalent
schedule already exists.
Sample JSON:
{ "schedule" : [
"[2014-09-22 08:00, 2014-09-22 12:00)",
"[2014-09-22 12:30, 2014-09-22 16:30)",
"[2014-09-23 08:00, 2014-09-23 12:00)",
"[2014-09-23 12:30, 2014-09-23 16:30)",
"[2014-09-24 08:00, 2014-09-24 12:00)",
t/dispatch/schedule.t view on Meta::CPAN
req( $test, 403, 'demo', 'PUT', "$base/$sid" );
$status = req( $test, 200, 'root', 'PUT', "$base/$sid", '{ "remark" : "foobar" }' );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
ok( exists( $status->{'payload'} ) );
ok( defined( $status->payload ) );
ok( exists( $status->{'payload'}->{'remark'} ) );
ok( defined( $status->{'payload'}->{'remark'} ) );
is( $status->{'payload'}->{'remark'}, "foobar" );
note( 'verify with GET' );
$status = req( $test, 200, 'root', 'GET', "$base/$sid" );
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_SCHEDULE_FOUND' );
is( $status->payload->{'remark'}, 'foobar' );
note( 'disable the schedule in the wrong way' );
dbi_err( $test, 500, 'root', 'PUT', "$base/$sid", '{ "pebble" : [1,2,3], "disabled":"hoogar" }',
qr/invalid input syntax for type boolean/ );
note( 'disable the schedule in the right way' );
t/dispatch/schedule.t view on Meta::CPAN
req( $test, 403, 'demo', 'PUT', "$base/$sid" );
$status = req( $test, 200, 'root', 'PUT', "$base/$sid", '{ "scode" : "bazblare" }' );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
ok( exists( $status->{'payload'} ) );
ok( defined( $status->payload ) );
ok( exists( $status->{'payload'}->{'scode'} ) );
ok( defined( $status->{'payload'}->{'scode'} ) );
is( $status->{'payload'}->{'scode'}, "bazblare" );
note( 'verify with GET' );
$status = req( $test, 200, 'root', 'GET', "$base/$sid" );
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_SCHEDULE_FOUND' );
is( $status->payload->{'scode'}, 'bazblare' );
note( 'DELETE' );
note( 'delete the testing schedule' );
$status = req( $test, 200, 'root', 'DELETE', "$base/$sid" );
is( $status->level, 'OK' );
t/dispatch/schedule.t view on Meta::CPAN
req( $test, 403, 'demo', 'PUT', "$base/$scode" );
$status = req( $test, 200, 'root', 'PUT', "$base/$scode", '{ "remark" : "foobar" }' );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
ok( exists( $status->{'payload'} ) );
ok( defined( $status->payload ) );
ok( exists( $status->{'payload'}->{'remark'} ) );
ok( defined( $status->{'payload'}->{'remark'} ) );
is( $status->{'payload'}->{'remark'}, "foobar" );
note( 'verify with GET' );
$status = req( $test, 200, 'root', 'GET', "$base/$scode" );
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_SCHEDULE_FOUND' );
is( $status->payload->{'remark'}, 'foobar' );
note( 'disable the schedule in the wrong way' );
dbi_err( $test, 500, 'root', 'PUT', "$base/$scode", '{ "pebble" : [1,2,3], "disabled":"hoogar" }',
qr/invalid input syntax for type boolean/ );
note( 'disable the schedule in the right way' );
t/dispatch/schedule.t view on Meta::CPAN
req( $test, 403, 'demo', 'PUT', "$base/$scode" );
$status = req( $test, 200, 'root', 'PUT', "$base/$scode", '{ "scode" : "bazblare" }' );
is( $status->level, 'OK' );
is( $status->code, 'DOCHAZKA_CUD_OK' );
ok( exists( $status->{'payload'} ) );
ok( defined( $status->payload ) );
ok( exists( $status->{'payload'}->{'scode'} ) );
ok( defined( $status->{'payload'}->{'scode'} ) );
is( $status->{'payload'}->{'scode'}, "bazblare" );
note( 'verify with GET' );
$status = req( $test, 200, 'root', 'GET', "$base/bazblare" );
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_SCHEDULE_FOUND' );
is( $status->payload->{'scode'}, 'bazblare' );
note( 'DELETE' );
note( 'delete the testing schedule' );
$status = req( $test, 200, 'root', 'DELETE', "$base/bazblare" );
is( $status->level, 'OK' );
t/model/interval_lock.t view on Meta::CPAN
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 );
( run in 1.486 second using v1.01-cache-2.11-cpan-e1769b4cff6 )