From 592e1b0187375faef5f95bed8a8e683a57dd64e5 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Sun, 28 Jan 2018 01:18:54 -0500 Subject: [PATCH] Bug 13990: QA Followup - Add unit test coverage prove t/db_dependent/ILSDI_Services.t Signed-off-by: Mark Tompsett Signed-off-by: Nick Clemens --- t/db_dependent/ILSDI_Services.t | 57 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 7677db0..a433551 100644 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -19,7 +19,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use Test::More tests => 3; +use Test::More tests => 4; use Test::MockModule; use t::lib::Mocks; use t::lib::TestBuilder; @@ -198,3 +198,58 @@ subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes $schema->storage->txn_rollback; }; + +subtest 'LookupPatron test' => sub { + + plan tests => 9; + + $schema->storage->txn_begin; + + $schema->resultset( 'Issue' )->delete_all; + $schema->resultset( 'Borrower' )->delete_all; + $schema->resultset( 'BorrowerAttribute' )->delete_all; + $schema->resultset( 'BorrowerAttributeType' )->delete_all; + $schema->resultset( 'Category' )->delete_all; + $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this + $schema->resultset( 'Branch' )->delete_all; + + my $borrower = $builder->build({ + source => 'Borrower', + }); + + my $query = CGI->new(); + my $bad_result = C4::ILSDI::Services::LookupPatron($query); + is( $bad_result->{message}, 'PatronNotFound', 'No parameters' ); + + $query->delete_all(); + $query->param( 'id', $borrower->{firstname} ); + my $optional_result = C4::ILSDI::Services::LookupPatron($query); + is( + $optional_result->{id}, + $borrower->{borrowernumber}, + 'Valid Firstname only' + ); + + $query->delete_all(); + $query->param( 'id', 'ThereIsNoWayThatThisCouldPossiblyBeValid' ); + my $bad_optional_result = C4::ILSDI::Services::LookupPatron($query); + is( $bad_optional_result->{message}, 'PatronNotFound', 'Invalid ID' ); + + foreach my $id_type ( + 'cardnumber', + 'userid', + 'email', + 'borrowernumber', + 'surname', + 'firstname' + ) { + $query->delete_all(); + $query->param( 'id_type', $id_type ); + $query->param( 'id', $borrower->{$id_type} ); + my $result = C4::ILSDI::Services::LookupPatron($query); + is( $result->{'id'}, $borrower->{borrowernumber}, "Checking $id_type" ); + } + + # Cleanup + $schema->storage->txn_rollback; +}; -- 2.1.4