Implementation of getRequestConfigurations
A basic implementation of getRequestConfigurations and tests to go with it. Also added here is the test to verify that no items are added when duplicates are included.
This commit is contained in:
parent
4331093cee
commit
69945c2704
2 changed files with 23 additions and 2 deletions
|
@ -283,6 +283,16 @@ sub getRequestConfigurations($$) {
|
|||
return undef if not defined $type;
|
||||
my $typeId = $self->getRequestType($type);
|
||||
return undef if not defined $typeId;
|
||||
|
||||
my %descriptions;
|
||||
my $dbData =
|
||||
$self->dbh()->selectall_hashref("SELECT description, id FROM request_configuration " .
|
||||
"WHERE request_type_id = " . $self->dbh->quote($typeId, 'SQL_INTEGER'),
|
||||
'description');
|
||||
foreach my $description (keys %$dbData) {
|
||||
$descriptions{$description} = $dbData->{$description}{id};
|
||||
}
|
||||
return { $typeId => \%descriptions };
|
||||
}
|
||||
######################################################################
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More tests => 49;
|
||||
use Test::More tests => 52;
|
||||
use Test::Exception;
|
||||
|
||||
use Scalar::Util qw(looks_like_number);
|
||||
|
@ -167,7 +167,6 @@ is $tShirt0RequestTypeId, $testSameRequestType,
|
|||
|
||||
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");
|
||||
|
@ -176,6 +175,13 @@ my @sizeList = qw/LadiesS LadiesM LadiesL LadiesXL MenS MenM MenL MenXL Men2XL/;
|
|||
|
||||
my $tShirt0Data;
|
||||
|
||||
dies_ok { $sp->addRequestConfigurations('t-shirt-0', [ @sizeList, 'Men2XL']) }
|
||||
"addRequestConfigurations: dies with duplicate items on configuration list.";
|
||||
|
||||
is_deeply({ $tShirt0RequestTypeId => {} },
|
||||
$sp->getRequestConfigurations('t-shirt-0'),
|
||||
"addRequestConfigurations/getRequestConfigurations: add fails with duplicate in configuration list");
|
||||
|
||||
lives_ok { $tShirt0Data = $sp->addRequestConfigurations('t-shirt-0', \@sizeList) }
|
||||
"addRequestConfigurations: existing requestType with configuration runs.";
|
||||
|
||||
|
@ -190,6 +196,7 @@ foreach my $size (@sizeList) {
|
|||
sprintf "addRequestConfigurations: item %d added correctly", $cnt++);
|
||||
}
|
||||
|
||||
|
||||
=back
|
||||
|
||||
=item getRequestConfigurations
|
||||
|
@ -200,6 +207,10 @@ is undef, $sp->getRequestConfigurations(undef), "getRequestConfigurations: undef
|
|||
|
||||
is undef, $sp->getRequestConfigurations('Hae2Ohlu'), "getRequestConfigurations: non-existent type returns undef";
|
||||
|
||||
is_deeply $tShirt0Data,
|
||||
$sp->getRequestConfigurations('t-shirt-0'),
|
||||
"getRequestConfigurations: lookup of previously added items is same";
|
||||
|
||||
|
||||
=back
|
||||
|
||||
|
|
Loading…
Reference in a new issue