From 1d8320594941f124da5afc3fb562ef1bd131f06e Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Sun, 20 Dec 2015 13:36:56 -0800 Subject: [PATCH] fufillRequest: more tests. --- Supporters/t/Supporters.t | 41 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Supporters/t/Supporters.t b/Supporters/t/Supporters.t index 2792c17..076271b 100644 --- a/Supporters/t/Supporters.t +++ b/Supporters/t/Supporters.t @@ -5,7 +5,7 @@ use strict; use warnings; -use Test::More tests => 129; +use Test::More tests => 138; use Test::Exception; use Scalar::Util qw(looks_like_number reftype); @@ -296,13 +296,50 @@ ok( (defined $tShirt0RequestId and looks_like_number($tShirt0RequestId) and $tSh my $fufillRequestId; + +dies_ok { $fufillRequestId = $sp->fufillRequest( { requestType => "t-shirt-small-only", who => 'joe', + how => "in-person delivery" }); } + "fufillRequest: dies if supporterId not specified"; + +dies_ok { $fufillRequestId = $sp->fufillRequest( { supporterId => $drapperId, who => 'joe', + how => "in-person delivery" }); } + "fufillRequest: dies if requestType not specified"; + +dies_ok { $fufillRequestId = $sp->fufillRequest( { supporterId => $drapperId, + requestType => "t-shirt-small-only", + how => "in-person delivery" }); } + "fufillRequest: who not specified"; + lives_ok { $fufillRequestId = $sp->fufillRequest( { supporterId => $drapperId, requestType => "t-shirt-small-only", who => 'joe', how => "in-person delivery" }); } "fufillRequest: succeeds for existing request"; ok( (defined $fufillRequestId and looks_like_number($fufillRequestId) and $fufillRequestId > 0), - "fufillRequestId: id returned on successful fufillRequest() is a number"); + "fufillRequest: id returned on successful fufillRequest() is a number"); + +lives_ok { $val = $sp->dbh()->selectall_hashref("SELECT id, date, who, how, request_id FROM fulfillment", 'id'); } + "fufillRequest: sql command in database for entry succeeds."; +is_deeply($val, { $fufillRequestId => { id => $fufillRequestId, date => $today, + how => 'in-person delivery', who => 'joe', + request_id => $tshirtSmallRequestId } }, + "fufillRequest: databse etnry from successful return is correct"); + +ok((defined $val and (keys(%$val) == 0)), + "_getOrCreateRequestConfiguration: no request_configuration record added for failed attempts"); + +my $badFR; +lives_ok { $badFR = $sp->fufillRequest( { supporterId => $drapperId, who => 'john', + requestType => "does-not-exist", + how => "in-person delivery" }); } + "fufillRequest: attempt to fulfill a request never made does not die..."; + +ok( (not defined $badFR), + "fufillRequest: ... but, rather, returns undef."); + +is($sp->getRequestType("does-not-exist"), undef, + "fufillRequest: requestType not created when fufillRequest fails."); + =item getRequest