Bugzilla – Attachment 82777 Details for
Bug 21727
Add Koha::Account::Line->adjust
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21727: Add tests for Koha::Account::Line->adjust
Bug-21727-Add-tests-for-KohaAccountLine-adjust.patch (text/plain), 4.29 KB, created by
Martin Renvoize (ashimema)
on 2018-11-30 11:54:19 UTC
(
hide
)
Description:
Bug 21727: Add tests for Koha::Account::Line->adjust
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2018-11-30 11:54:19 UTC
Size:
4.29 KB
patch
obsolete
>From 371a6289fa35f115c9466a92000ba7a296e77e45 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 30 Nov 2018 11:52:12 +0000 >Subject: [PATCH] Bug 21727: Add tests for Koha::Account::Line->adjust > >--- > t/db_dependent/Koha/Account/Lines.t | 86 ++++++++++++++++++++++++++++- > 1 file changed, 85 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t >index eb8dfdd1c0..f5ea8f2b4e 100755 >--- a/t/db_dependent/Koha/Account/Lines.t >+++ b/t/db_dependent/Koha/Account/Lines.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 5; > use Test::Exception; > > use Koha::Account; >@@ -27,6 +27,7 @@ use Koha::Account::Lines; > use Koha::Account::Offsets; > use Koha::Items; > >+use t::lib::Mocks; > use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; >@@ -268,3 +269,86 @@ subtest 'apply() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'adjust() tests' => sub { >+ >+ plan tests => 16; >+ >+ $schema->storage->txn_begin; >+ >+ # count logs before any actions >+ my $action_logs = $schema->resultset('ActionLog')->search()->count; >+ >+ # Disable logs >+ t::lib::Mocks::mock_preference( 'FinesLog', 0 ); >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $account = $patron->account; >+ >+ my $debit_1 = Koha::Account::Line->new( >+ { borrowernumber => $patron->id, >+ accounttype => "F", >+ amount => 10, >+ amountoutstanding => 10 >+ } >+ )->store; >+ >+ my $debit_2 = Koha::Account::Line->new( >+ { borrowernumber => $patron->id, >+ accounttype => "FU", >+ amount => 100, >+ amountoutstanding => 100 >+ } >+ )->store; >+ >+ my $credit = $account->add_credit( { amount => 40, user_id => $patron->id } ); >+ >+ throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) } >+ qr/Update type not recognised/, 'Exception thrown for unrecognised type'; >+ >+ throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_increment' } ) } >+ qr/Update type not allowed on this accounttype/, >+ 'Exception thrown for type conflict'; >+ >+ # Increment an unpaid fine >+ $debit_2->adjust( { amount => 150, type => 'fine_increment' } ); >+ >+ is( $debit_2->discard_changes->amount * 1, 150, 'Fine amount was updated in full' ); >+ is( $debit_2->discard_changes->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); >+ >+ my $offsets = Koha::Account::Offsets->search( { debit_id => $debit_2->id } ); >+ is( $offsets->count, 1, 'An offset is generated for the increment' ); >+ my $THIS_offset = $offsets->next; >+ is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); >+ is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' ); >+ >+ is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); >+ >+ # Update fine to partially paid >+ my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); >+ $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } ); >+ >+ is( $debit_2->discard_changes->amount * 1, 150, 'Fine amount unaffected by partial payment' ); >+ is( $debit_2->discard_changes->amountoutstanding * 1, 110, 'Fine amountoutstanding updated by partial payment' ); >+ >+ # Enable logs >+ t::lib::Mocks::mock_preference( 'FinesLog', 1 ); >+ >+ # Increment the partially paid fine >+ $debit_2->adjust( { amount => 160, type => 'fine_increment' } ); >+ >+ is( $debit_2->discard_changes->amount * 1, 160, 'Fine amount was updated in full' ); >+ is( $debit_2->discard_changes->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' ); >+ >+ $offsets = Koha::Account::Offsets->search( { debit_id => $debit_2->id } ); >+ is( $offsets->count, 3, 'An offset is generated for the increment' ); >+ $THIS_offset = $offsets->last; >+ is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' ); >+ is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' ); >+ >+ is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+1; >-- >2.19.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21727
:
81879
|
82777
|
82778
|
83054
|
83055
|
83056
|
83058
|
83088
|
83089
|
83090
|
83091
|
83095
|
83096
|
83097
|
83098
|
83101
|
83117
|
83118
|
83121
|
83122
|
83818