Bug 19841: Unit tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 20 Dec 2017 19:19:07 +0000 (16:19 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 26 Dec 2017 15:52:34 +0000 (12:52 -0300)
This patch introduces unit tests for the new behaviour of AddMember
(raising an exception if the passed categorycode is not valid.

 To test:
 - Apply this patch
 - Run:
   $ kshell
  k$ prove t/db_dependent/Members.t
=> FAIL: It should fail because the feature is still not implemented.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Members.t

index a933827..cfb314f 100755 (executable)
 
 use Modern::Perl;
 
-use Test::More tests => 63;
+use Test::More tests => 64;
 use Test::MockModule;
+use Test::Exception;
+
 use Data::Dumper qw/Dumper/;
 use C4::Context;
 use Koha::Database;
@@ -501,3 +503,25 @@ subtest 'Trivial test for AddMember_Auto' => sub {
 };
 
 $schema->storage->txn_rollback;
+
+subtest 'AddMember (invalid categorycode) tests' => sub {
+    plan tests => 1;
+
+    $schema->storage->txn_begin;
+
+    my $category    = $builder->build_object({ class => 'Koha::Patron::Categories' });
+    my $category_id = $category->id;
+    # Remove category to make sure the id is not on the DB
+    $category->delete;
+
+    my $patron_data = {
+        categorycode => $category_id
+    };
+
+    throws_ok
+        { AddMember( %{ $patron_data } ); }
+        'Koha::Exceptions::BadParameter',
+        'AddMember raises an exception on invalid categorycode';
+
+    $schema->storage->txn_rollback;
+};