holdRequest: revise tests to shake out the API.

First of all, I originally thought about releaseDate all wrong.  We want
to store the date that the hold was released, which is the indicator
that the request is no longer on hold and can be fulfilled.

We also need tests that assure a request is not fulfilled while on
hold.  Those are added here.

I shook out a few other changes to the test ordering that are necessary
for the change to testing holdRequest().
This commit is contained in:
Bradley M. Kuhn 2016-01-19 17:49:20 -08:00
parent 18e08833d5
commit ef21af7afd
2 changed files with 73 additions and 34 deletions

View file

@ -1109,7 +1109,12 @@ A hash reference, the following keys are considered:
=back
Returns the id value of the fulfillment entry.
Returns the id value of the fulfillment entry. Note that value may be a
fulfillment id from a previous fulfillment (i.e., the request may have
already been fulfilled).
undef can be returned. Currently, undef is only returned if the request is
on hold.
=cut

View file

@ -8,7 +8,7 @@
use strict;
use warnings;
use Test::More tests => 313;
use Test::More tests => 331;
use Test::Exception;
use Sub::Override;
use File::Temp qw/tempfile/;
@ -510,50 +510,61 @@ lives_ok { $tShirt0RequestId =
ok( (defined $tShirt0RequestId and looks_like_number($tShirt0RequestId) and $tShirt0RequestId > 0),
"addRequest: another successful call returns an integer id.");
my $olsonTShirtRequest;
lives_ok { $olsonTShirtRequest =
$sp->addRequest({ donorId => $olsonId, requestTypeId => $tShirt0RequestTypeId,
requestConfigurationId => $tShirt0Data->{$tShirt0RequestTypeId}{'LadiesXL'} }); }
"addRequest: different donor succeeds with a requestTypeId and requestConfigurationId with no a note....";
ok( (defined $olsonTShirtRequest and looks_like_number($olsonTShirtRequest) and $olsonTShirtRequest > 0
and $olsonTShirtRequest != $tShirt0RequestTypeId and $olsonTShirtRequest != $tshirtSmallRequestId),
"addRequest: ... and successful call returns an integer id that's different from others.");
=item holdRequest
=cut
my $holdRequestId;
my $drapperTShirt0HoldId;
my $newHoldId;
dies_ok { $holdRequestId = $sp->holdRequest(requestType => "t-shirt-0", who => 'joe',
dies_ok { $drapperTShirt0HoldId = $sp->holdRequest(requestType => "t-shirt-0", who => 'joe',
why => "will see him soon and give t-shirt in person" ); }
"holdRequest: dies if donorId not specified";
dies_ok { $holdRequestId = $sp->holdRequest(donorId => $drapperId + 1000,
dies_ok { $drapperTShirt0HoldId = $sp->holdRequest(donorId => $drapperId + 1000,
requestType => "t-shirt-0", who => 'joe',
why => "will see him soon and give t-shirt in person"); }
"holdRequest: dies if donorId not found in database";
dies_ok { $holdRequestId = $sp->holdRequest(donorId => $drapperId, who => 'joe',
dies_ok { $drapperTShirt0HoldId = $sp->holdRequest(donorId => $drapperId, who => 'joe',
why => "in-person delivery" ); }
"holdRequest: dies if requestType not specified";
dies_ok { $holdRequestId = $sp->holdRequest( { donorId => $drapperId,
dies_ok { $drapperTShirt0HoldId = $sp->holdRequest( { donorId => $drapperId,
requestType => "t-shirt-0",
why => "in-person delivery" }); }
"holdRequest: dies if who not specified";
lives_ok { $holdRequestId = $sp->holdRequest( { donorId => $drapperId,
lives_ok { $drapperTShirt0HoldId = $sp->holdRequest( { donorId => $drapperId,
requestType => "t-shirt-0", who => 'joe',
why => "in-person delivery" }); }
"holdRequest: succeeds for existing request...";
ok( (defined $holdRequestId and looks_like_number($holdRequestId) and $holdRequestId > 0),
ok( (defined $drapperTShirt0HoldId and looks_like_number($drapperTShirt0HoldId) and $drapperTShirt0HoldId > 0),
"holdRequest: ... and id returned on successful holdRequest() is a number");
lives_ok { $val = $sp->dbh()->selectall_hashref("SELECT id, date, who, how, request_id FROM request_hold", 'id'); }
"holdRequest: sql command in database for entry succeeds.";
is_deeply($val, { $holdRequestId => { id => $holdRequestId, date => $today,
why => 'in-person delivery', who => 'joe',
request_id => $tshirtSmallRequestId } },
is_deeply($val, { $drapperTShirt0HoldId => { id => $drapperTShirt0HoldId, date => $today,
why => 'in-person delivery planned', who => 'joe',
request_id => $tShirt0RequestId } },
"holdRequest: databse entry from successful return is correct");
my $badHold;
lives_ok { $badHold = $sp->holdRequest( { donorId => $drapperId, who => 'john',
requestType => "does-not-exist",
how => "in-person delivery" }); }
why => "in-person delivery" }); }
"holdRequest: attempt to hold a request never made does not die...";
ok( (not defined $badHold),
@ -562,32 +573,22 @@ ok( (not defined $badHold),
is($sp->getRequestType("does-not-exist"), undef,
"holdRequest: requestType not created when holdRequest fails.");
my $lookedUpHoldId;
my $reHoldId;
lives_ok { $lookedUpHoldId = $sp->holdRequest( { donorId => $drapperId,
dies_ok { $reHoldId = $sp->holdRequest( { donorId => $drapperId,
requestType => "t-shirt-0", who => 'peggy',
how => "left in his office." }); }
"holdRequest: attempt to hold an already-hold request does not die ...";
is($lookedUpHoldId, $holdRequestId,
"holdRequest: ... but, rather, returns the same value from the previous holdRequest() call.");
why => "will leave in his office." }); }
"holdRequest: attempt to hold an already-hold request dies ...";
my $holdRequest;
lives_ok { $newHoldId = $sp->holdRequest( { donorId => $drapperId, releaseDate => '3000-01-01',
lives_ok { $newHoldId = $sp->holdRequest( { donorId => $olsonId,
requestTypeId => $tShirt0RequestTypeId, who => 'john',
how => "mailed" }); }
why => "will delivery at conference" }); }
"holdRequest: succeeds for existing request, using requestTypeId";
ok( (defined $newHoldId and looks_like_number($newHoldId) and $newHoldId > 0 and ($newHoldId != $holdRequestId)),
ok( (defined $newHoldId and looks_like_number($newHoldId) and $newHoldId > 0 and ($newHoldId != $drapperTShirt0HoldId)),
"holdRequest: id returned on successful holdRequest() is a number and is not the one returned by previous");
=item releaseRequestHold
=cut
# FIXME: releaseRequestHold
=item fulfillRequest
@ -666,10 +667,9 @@ my $newFRID;
lives_ok { $newFRID = $sp->fulfillRequest( { donorId => $drapperId,
requestTypeId => $tShirt0RequestTypeId, who => 'john',
how => "mailed" }); }
"fulfillRequest: succeeds for existing request, using requestTypeId";
"fulfillRequest: returns properly for an existing request, using requestTypeId for lookup, when the request his held...";
ok( (defined $newFRID and looks_like_number($newFRID) and $newFRID > 0 and ($newFRID != $fulfillRequestId)),
"fulfillRequest: id returned on successful fulfillRequest() is a number and is not the one returned by previous");
is($newFRID, undef, "fulfillRequest: .... but undef is returned when attempting to fulfill a held request.");
=item getRequest
@ -709,7 +709,10 @@ lives_ok { $tt = $sp->getRequest({donorId => $drapperId, requestTypeId => $tShir
is($tt->{requestType}, 't-shirt-0', "getRequest: requestType is correct.");
is($tt->{requestDate}, $today, "getRequest: request date is today.");
is($tt->{requestConfiguration}, 'MenL', "getRequest: configuration is correct.");
is($tt->{heldUntil}, '3000-01-01', "getRequest: heldUntil is correct.");
is($tt->{holdReleaseDate}, undef, "getRequest: releaseDate is correct.");
is($tt->{holdDate}, $today, "getRequest: holdDate is correct.");
is($tt->{holder}, 'joe', "getRequest: holder is correct.");
is($tt->{heldBecause}, 'in-person delivery planned', "getRequest: heldBecause is correct.");
is($tt->{notes}, undef, "getRequest: notes are undef when null in database.");
lives_ok { $tt = $sp->getRequest({donorId => $drapperId, requestTypeId => $tShirt0RequestTypeId,
@ -727,6 +730,37 @@ is($tt->{requestConfiguration}, undef, "getRequest: configuration is undefined w
is($tt->{notes}, undef, "getRequest: notes are undef when null in database.");
=item releaseRequestHold
=cut
my $releasedHoldId;
lives_ok { $releasedHoldId = $sp->releaseRequestHold(donorId => $drapperId, requestType => 't-shirt-0'); }
"releaseRequestHold: release of a knonw held request succeeds...";
is($releasedHoldId, $drapperTShirt0HoldId, "releaseRequestHold: ... & returns same hold id as holdRequest() call did");
lives_ok { $newFRID = $sp->fulfillRequest( { donorId => $drapperId,
requestTypeId => $tShirt0RequestTypeId, who => 'john',
how => "mailed" }); }
"fulfillRequest: succeeds once the request is no longer on hold...";
is( (defined $newFRID and looks_like_number($newFRID) and $newFRID > 0 and ($newFRID != $fulfillRequestId)),
"....id returned on successful fulfillRequest() is a number and is not the one returned by previous");
lives_ok { $tt = $sp->getRequest({donorId => $drapperId, requestTypeId => $tShirt0RequestTypeId } ); }
"getRequest: succeeds with valid parameters, using requestTypeId.";
is($tt->{requestType}, 't-shirt-0', "getRequest: requestType is correct.");
is($tt->{requestDate}, $today, "getRequest: request date is today.");
is($tt->{requestConfiguration}, 'MenL', "getRequest: configuration is correct.");
is($tt->{holdReleaseDate}, $today, "getRequest: holdReleaseDate is correct.");
is($tt->{holdDate}, $today, "getRequest: holdDate is correct.");
is($tt->{holder}, 'joe', "getRequest: holder is correct.");
is($tt->{heldBecause}, 'in-person delivery planned', "getRequest: heldBecause is correct.");
is($tt->{fulfillDate}, $today, "getRequest: fulfilled request is today.");
is($tt->{notes}, undef, "getRequest: notes are undef when null in database.");
=item getRequestConfigurations
=cut