Bug 23321: (follow-up) Add test for Koha::Account change
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 13 Sep 2019 16:04:00 +0000 (17:04 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 23 Sep 2019 10:39:22 +0000 (11:39 +0100)
Sponsored-by: PTFS Europe
Sponsored-by: Cheshire Libraries Shared Services
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
t/db_dependent/Koha/Account.t

index f8ee8a8..a757f52 100755 (executable)
@@ -158,7 +158,7 @@ subtest 'outstanding_credits() tests' => sub {
 
 subtest 'add_credit() tests' => sub {
 
-    plan tests => 16;
+    plan tests => 17;
 
     $schema->storage->txn_begin;
 
@@ -231,7 +231,8 @@ subtest 'add_credit() tests' => sub {
     is( $offset_2->debit_id, undef, 'No debit_id is set for credits' );
 
     my $line_3 = $account->add_credit(
-        {   amount      => 20,
+        {
+            amount      => 20,
             description => 'Manual credit applied',
             library_id  => $patron->branchcode,
             user_id     => $patron->id,
@@ -243,6 +244,26 @@ subtest 'add_credit() tests' => sub {
     is( $schema->resultset('ActionLog')->count(), $action_logs + 2, 'Log was added' );
     is( $schema->resultset('Statistic')->count(), $statistics + 2, 'No action added to statistics, because of credit type' );
 
+    # Enable cash registers
+    t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 );
+    throws_ok {
+        $account->add_credit(
+            {
+                amount       => 20,
+                description  => 'Cash payment without cash register',
+                library_id   => $patron->branchcode,
+                user_id      => $patron->id,
+                payment_type => 'CASH',
+                interface    => 'intranet'
+            }
+        );
+    }
+    'Koha::Exceptions::Account::RegisterRequired',
+      'Exception thrown for UseCashRegisters:1 + payment_type:CASH + cash_register:undef';
+
+    # Disable cash registers
+    t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 );
+
     $schema->storage->txn_rollback;
 };
 
@@ -560,7 +581,7 @@ subtest 'reconcile_balance' => sub {
 
 subtest 'pay() tests' => sub {
 
-    plan tests => 2;
+    plan tests => 3;
 
     $schema->storage->txn_begin;
 
@@ -581,6 +602,23 @@ subtest 'pay() tests' => sub {
 
     is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' );
 
+    # Enable cash registers
+    t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 );
+    throws_ok {
+        $account->pay(
+            {
+                amount       => 20,
+                payment_type => 'CASH',
+                interface    => 'intranet'
+            }
+        );
+    }
+    'Koha::Exceptions::Account::RegisterRequired',
+      'Exception thrown for UseCashRegisters:1 + payment_type:CASH + cash_register:undef';
+
+    # Disable cash registers
+    t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 );
+
     $schema->storage->txn_rollback;
 };