Begin implementation of addRequestConfigurations

Includes some modifications to reuse data from previous tests.
This commit is contained in:
Bradley M. Kuhn 2015-12-13 13:04:27 -08:00
parent 8fd03e8e6f
commit 735db56d47
2 changed files with 61 additions and 5 deletions

View file

@ -286,6 +286,49 @@ sub getRequestConfigurations($$) {
} }
###################################################################### ######################################################################
=begin addRequestConfigurations
Arguments:
=over
=item type
A string describing the request type. This will be created if it does not
already exist, so be careful.
=item descriptionListRef
A list reference to the list of configuration descriptions to associate
with this requestId.
=back
Returns a hash in the form of:
$requestTypeId => { description => $requestConfigurationId }
=cut
sub addRequestConfigurations($$$) {
my($self, $requestType, $descriptionListRef) = @_;
die "addRequestConfigurations: undefined request type." unless defined $requestType;
$self->dbh->begin_work();
my $requestId = $self->addRequestType($requestType);
die "addRequestConfigurations: unable to create request configurations"
unless defined $requestType;
my %descriptions;
$self->dbh->commit();
return { $requestId => \%descriptions };
}
######################################################################
=head1 Non-Public Methods =head1 Non-Public Methods
These methods are part of the internal implementation are not recommended for These methods are part of the internal implementation are not recommended for

View file

@ -5,7 +5,7 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 36; use Test::More tests => 38;
use Test::Exception; use Test::Exception;
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
@ -143,14 +143,14 @@ ok($same == $paypalPayerAddressType, "addAddressType: lookup returns same as the
dies_ok { $sp->addRequestType(undef); } dies_ok { $sp->addRequestType(undef); }
"addRequestType: undef argument dies."; "addRequestType: undef argument dies.";
my $requestTypeId; my $tShirt0RequestTypeId;
ok( (not defined $sp->getRequestType('t-shirt-0')), "getRequestType: returns undef when not found"); ok( (not defined $sp->getRequestType('t-shirt-0')), "getRequestType: returns undef when not found");
lives_ok { $requestTypeId = $sp->addRequestType('t-shirt-0'); } lives_ok { $tShirt0RequestTypeId = $sp->addRequestType('t-shirt-0'); }
"addRequestType: succeeds on add"; "addRequestType: succeeds on add";
ok( (defined $requestTypeId and looks_like_number($requestTypeId) and $requestTypeId > 0), ok( (defined $tShirt0RequestTypeId and looks_like_number($tShirt0RequestTypeId) and $tShirt0RequestTypeId > 0),
"addRequestType: id is a number"); "addRequestType: id is a number");
my $testSameRequestType; my $testSameRequestType;
@ -158,9 +158,22 @@ my $testSameRequestType;
lives_ok { $testSameRequestType = $sp->addRequestType('t-shirt-0'); } lives_ok { $testSameRequestType = $sp->addRequestType('t-shirt-0'); }
"addRequestType: succeeds on add when type already exists"; "addRequestType: succeeds on add when type already exists";
is $requestTypeId, $testSameRequestType, is $tShirt0RequestTypeId, $testSameRequestType,
"addRequestType: lookup first of existing request type before adding."; "addRequestType: lookup first of existing request type before adding.";
=item addRequestConfigurations
=cut
dies_ok { $sp->addRequestConfigurations(undef, undef); } "addRequestConfigurations: undef type dies";
is_deeply({ $tShirt0RequestTypeId => {} },
$sp->addRequestConfigurations('t-shirt-0'),
"addRequestConfigurations: existing requestType with no configuration yields same");
=back
=item getRequestConfigurations =item getRequestConfigurations
=cut =cut