Bug 13990: (QA follow-up) Add unit test coverage
authorMark Tompsett <mtompset@hotmail.com>
Sun, 28 Jan 2018 06:18:54 +0000 (01:18 -0500)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 30 Jan 2018 17:21:10 +0000 (14:21 -0300)
prove t/db_dependent/ILSDI_Services.t

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/ILSDI_Services.t

index 7677db0..a433551 100644 (file)
@@ -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;
+};