Bug 22511: Update tests
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 15 Mar 2019 14:18:12 +0000 (14:18 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 25 Apr 2019 11:02:14 +0000 (11:02 +0000)
Updated tests to check for 'status' change and fixed 'accounttype' and
moved from t/db_dependent/Accounts.t to the more appropriate
t/db_dependent/Koha/Account/Lines.t

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

t/db_dependent/Accounts.t
t/db_dependent/Koha/Account/Lines.t

index 791af78..e1ba90d 100644 (file)
@@ -958,72 +958,6 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
 };
 
-subtest "Koha::Account::Line::void tests" => sub {
-
-    plan tests => 15;
-
-    # Create a borrower
-    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
-    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
-
-    my $borrower = Koha::Patron->new( {
-        cardnumber => 'dariahall',
-        surname => 'Hall',
-        firstname => 'Daria',
-    } );
-    $borrower->categorycode( $categorycode );
-    $borrower->branchcode( $branchcode );
-    $borrower->store;
-
-    my $account = Koha::Account->new({ patron_id => $borrower->id });
-
-    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline'  })->store();
-    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline'  })->store();
-
-    is( $account->balance(), 30, "Account balance is 30" );
-    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
-    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
-
-    my $id = $account->pay(
-        {
-            lines  => [$line1, $line2],
-            amount => 30,
-        }
-    );
-
-    my $account_payment = Koha::Account::Lines->find( $id );
-
-    is( $account->balance(), 0, "Account balance is 0" );
-
-    $line1->_result->discard_changes();
-    $line2->_result->discard_changes();
-    is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' );
-    is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' );
-
-    my $ret = $account_payment->void();
-
-    is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' );
-    is( $account->balance(), 30, "Account balance is again 30" );
-
-    $account_payment->_result->discard_changes();
-    $line1->_result->discard_changes();
-    $line2->_result->discard_changes();
-
-    is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' );
-    is( $account_payment->amount+0, 0, 'Voided payment amount is 0' );
-    is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' );
-
-    is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' );
-    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
-
-    # Accountlines that are not credits should be un-voidable
-    my $line1_pre = $line1->unblessed();
-    $ret = $line1->void();
-    $line1->_result->discard_changes();
-    my $line1_post = $line1->unblessed();
-    is( $ret, undef, 'Attempted void on non-credit returns undef' );
-    is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' )
-};
 
 subtest "Koha::Account::Offset credit & debit tests" => sub {
 
index 610a342..f0087a9 100755 (executable)
@@ -489,4 +489,72 @@ subtest 'checkout() tests' => sub {
     $schema->storage->txn_rollback;
 };
 
+subtest "void() tests" => sub {
+
+    plan tests => 15;
+
+    # Create a borrower
+    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
+    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
+
+    my $borrower = Koha::Patron->new( {
+        cardnumber => 'dariahall',
+        surname => 'Hall',
+        firstname => 'Daria',
+    } );
+    $borrower->categorycode( $categorycode );
+    $borrower->branchcode( $branchcode );
+    $borrower->store;
+
+    my $account = Koha::Account->new({ patron_id => $borrower->id });
+
+    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store();
+    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store();
+
+    is( $account->balance(), 30, "Account balance is 30" );
+    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
+    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
+
+    my $id = $account->pay(
+        {
+            lines  => [$line1, $line2],
+            amount => 30,
+        }
+    );
+
+    my $account_payment = Koha::Account::Lines->find( $id );
+
+    is( $account->balance(), 0, "Account balance is 0" );
+
+    $line1->_result->discard_changes();
+    $line2->_result->discard_changes();
+    is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' );
+    is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' );
+
+    my $ret = $account_payment->void();
+
+    is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' );
+    is( $account->balance(), 30, "Account balance is again 30" );
+
+    $account_payment->_result->discard_changes();
+    $line1->_result->discard_changes();
+    $line2->_result->discard_changes();
+
+    is( $account_payment->accounttype, 'Pay', 'Voided payment accounttype is still Pay' );
+    is( $account_payment->status, 'VOID', 'Voided payment status is VOID' );
+    is( $account_payment->amount+0, 0, 'Voided payment amount is 0' );
+    is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' );
+
+    is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' );
+    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
+
+    # Accountlines that are not credits should be un-voidable
+    my $line1_pre = $line1->unblessed();
+    $ret = $line1->void();
+    $line1->_result->discard_changes();
+    my $line1_post = $line1->unblessed();
+    is( $ret, undef, 'Attempted void on non-credit returns undef' );
+    is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' )
+};
+
 1;