Lines 22-27
use Modern::Perl;
Link Here
|
22 |
use Test::More tests => 14; |
22 |
use Test::More tests => 14; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
|
|
25 |
use Time::Fake; |
25 |
|
26 |
|
26 |
use DateTime; |
27 |
use DateTime; |
27 |
|
28 |
|
Lines 466-471
subtest 'adjust() tests' => sub {
Link Here
|
466 |
plan tests => 29; |
467 |
plan tests => 29; |
467 |
|
468 |
|
468 |
$schema->storage->txn_begin; |
469 |
$schema->storage->txn_begin; |
|
|
470 |
my $faketime = DateTime->now->subtract( hours => 4 ); |
471 |
Time::Fake->offset($faketime->epoch); |
469 |
|
472 |
|
470 |
# count logs before any actions |
473 |
# count logs before any actions |
471 |
my $action_logs = $schema->resultset('ActionLog')->search()->count; |
474 |
my $action_logs = $schema->resultset('ActionLog')->search()->count; |
Lines 510-522
subtest 'adjust() tests' => sub {
Link Here
|
510 |
|
513 |
|
511 |
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); |
514 |
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); |
512 |
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); |
515 |
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); |
513 |
isnt( $debit_2->date, undef, 'Date has been set' ); |
516 |
is( $debit_2->date, $faketime->strftime('%F %T'), "Instance time was used to set date"); |
514 |
|
517 |
|
515 |
my $offsets = Koha::Account::Offsets->search( { debit_id => $debit_2->id } ); |
518 |
my $offsets = Koha::Account::Offsets->search( { debit_id => $debit_2->id } ); |
516 |
is( $offsets->count, 1, 'An offset is generated for the increment' ); |
519 |
is( $offsets->count, 1, 'An offset is generated for the increment' ); |
517 |
my $THIS_offset = $offsets->next; |
520 |
my $THIS_offset = $offsets->next; |
518 |
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); |
521 |
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); |
519 |
is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' ); |
522 |
is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' ); |
|
|
523 |
is( $THIS_offset->created_on, $faketime->strftime('%F %T'), "Instance time was used to set created_on date"); |
520 |
|
524 |
|
521 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
525 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
522 |
|
526 |
|
Lines 777-782
subtest "payout() tests" => sub {
Link Here
|
777 |
plan tests => 18; |
781 |
plan tests => 18; |
778 |
|
782 |
|
779 |
$schema->storage->txn_begin; |
783 |
$schema->storage->txn_begin; |
|
|
784 |
my $faketime = DateTime->now->subtract( hours => 4 ); |
785 |
Time::Fake->offset($faketime->epoch); |
780 |
|
786 |
|
781 |
# Create a borrower |
787 |
# Create a borrower |
782 |
my $categorycode = |
788 |
my $categorycode = |
Lines 906-920
subtest "payout() tests" => sub {
Link Here
|
906 |
is( $credit1->amountoutstanding + 0, |
912 |
is( $credit1->amountoutstanding + 0, |
907 |
-10, 'Credit has an new amount outstanding of -10' ); |
913 |
-10, 'Credit has an new amount outstanding of -10' ); |
908 |
is( $credit1->status(), 'PAID', "Credit has a new status of PAID" ); |
914 |
is( $credit1->status(), 'PAID', "Credit has a new status of PAID" ); |
|
|
915 |
is( $payout->date, $faketime->strftime('%F %T'), "Instance time was used to set payout date"); |
909 |
|
916 |
|
|
|
917 |
Time::Fake->reset; |
910 |
$schema->storage->txn_rollback; |
918 |
$schema->storage->txn_rollback; |
911 |
}; |
919 |
}; |
912 |
|
920 |
|
913 |
subtest "reduce() tests" => sub { |
921 |
subtest "reduce() tests" => sub { |
914 |
|
922 |
|
915 |
plan tests => 29; |
923 |
plan tests => 31; |
916 |
|
924 |
|
917 |
$schema->storage->txn_begin; |
925 |
$schema->storage->txn_begin; |
|
|
926 |
my $faketime = DateTime->now->subtract( hours => 4 ); |
927 |
Time::Fake->offset($faketime->epoch); |
918 |
|
928 |
|
919 |
# Create a borrower |
929 |
# Create a borrower |
920 |
my $categorycode = |
930 |
my $categorycode = |
Lines 1033-1038
subtest "reduce() tests" => sub {
Link Here
|
1033 |
is( $debit1->status(), 'DISCOUNTED', "Debit status updated to DISCOUNTED"); |
1043 |
is( $debit1->status(), 'DISCOUNTED', "Debit status updated to DISCOUNTED"); |
1034 |
is( $account->balance() * 1, -5, "Account balance is -5" ); |
1044 |
is( $account->balance() * 1, -5, "Account balance is -5" ); |
1035 |
is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); |
1045 |
is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); |
|
|
1046 |
is( $reduction->date(), $faketime->strftime('%F %T'), "Instance time was used to set reduction date"); |
1036 |
|
1047 |
|
1037 |
my $offsets = Koha::Account::Offsets->search( |
1048 |
my $offsets = Koha::Account::Offsets->search( |
1038 |
{ credit_id => $reduction->id, debit_id => $debit1->id } ); |
1049 |
{ credit_id => $reduction->id, debit_id => $debit1->id } ); |
Lines 1041-1046
subtest "reduce() tests" => sub {
Link Here
|
1041 |
is( $THE_offset->amount * 1, |
1052 |
is( $THE_offset->amount * 1, |
1042 |
-5, 'Correct amount was applied against debit' ); |
1053 |
-5, 'Correct amount was applied against debit' ); |
1043 |
is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" ); |
1054 |
is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" ); |
|
|
1055 |
is( $THE_offset->created_on, $faketime->strftime('%F %T'), "Instance time was used to set created_on date"); |
1044 |
|
1056 |
|
1045 |
# Zero offset created when zero outstanding |
1057 |
# Zero offset created when zero outstanding |
1046 |
# (Refund another 5 on paid debt of 20) |
1058 |
# (Refund another 5 on paid debt of 20) |
Lines 1087-1099
subtest "reduce() tests" => sub {
Link Here
|
1087 |
'Koha::Exceptions::Account::IsNotDebit', |
1099 |
'Koha::Exceptions::Account::IsNotDebit', |
1088 |
'->reduce() cannot be used on a payout debit'; |
1100 |
'->reduce() cannot be used on a payout debit'; |
1089 |
|
1101 |
|
|
|
1102 |
Time::Fake->reset; |
1090 |
$schema->storage->txn_rollback; |
1103 |
$schema->storage->txn_rollback; |
1091 |
}; |
1104 |
}; |
1092 |
|
1105 |
|
1093 |
subtest "cancel() tests" => sub { |
1106 |
subtest "cancel() tests" => sub { |
1094 |
plan tests => 16; |
1107 |
plan tests => 18; |
1095 |
|
1108 |
|
1096 |
$schema->storage->txn_begin; |
1109 |
$schema->storage->txn_begin; |
|
|
1110 |
my $faketime = DateTime->now->subtract( hours => 4 ); |
1111 |
Time::Fake->offset($faketime->epoch); |
1097 |
|
1112 |
|
1098 |
my $library = $builder->build_object( { class => 'Koha::Libraries' }); |
1113 |
my $library = $builder->build_object( { class => 'Koha::Libraries' }); |
1099 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } }); |
1114 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } }); |
Lines 1175-1180
subtest "cancel() tests" => sub {
Link Here
|
1175 |
0, "Debit amountoutstanding reduced to 0" ); |
1190 |
0, "Debit amountoutstanding reduced to 0" ); |
1176 |
is( $debit1->status(), 'CANCELLED', "Debit status updated to CANCELLED" ); |
1191 |
is( $debit1->status(), 'CANCELLED', "Debit status updated to CANCELLED" ); |
1177 |
is( $account->balance() * 1, 15, "Account balance is 15" ); |
1192 |
is( $account->balance() * 1, 15, "Account balance is 15" ); |
|
|
1193 |
is( $cancellation->date, $faketime->strftime('%F %T'), "Instance time was used to set cancellation date"); |
1178 |
|
1194 |
|
1179 |
my $offsets = Koha::Account::Offsets->search( |
1195 |
my $offsets = Koha::Account::Offsets->search( |
1180 |
{ credit_id => $cancellation->id, debit_id => $debit1->id } ); |
1196 |
{ credit_id => $cancellation->id, debit_id => $debit1->id } ); |
Lines 1184-1190
subtest "cancel() tests" => sub {
Link Here
|
1184 |
-10, 'Correct amount was applied against debit' ); |
1200 |
-10, 'Correct amount was applied against debit' ); |
1185 |
is( $THE_offset->type, 'CANCELLATION', |
1201 |
is( $THE_offset->type, 'CANCELLATION', |
1186 |
"Offset type set to 'CANCELLATION'" ); |
1202 |
"Offset type set to 'CANCELLATION'" ); |
|
|
1203 |
is( $THE_offset->created_on, $faketime->strftime('%F %T'), "Instance time was used to set created_on date"); |
1187 |
|
1204 |
|
|
|
1205 |
Time::Fake->reset; |
1188 |
$schema->storage->txn_rollback; |
1206 |
$schema->storage->txn_rollback; |
1189 |
}; |
1207 |
}; |
1190 |
|
1208 |
|
1191 |
- |
|
|