|
Lines 21-34
use Modern::Perl;
Link Here
|
| 21 |
use FindBin qw( $Bin ); |
21 |
use FindBin qw( $Bin ); |
| 22 |
|
22 |
|
| 23 |
use Test::NoWarnings; |
23 |
use Test::NoWarnings; |
| 24 |
use Test::More tests => 4; |
24 |
use Test::More tests => 5; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
| 26 |
|
26 |
|
| 27 |
use t::lib::Mocks; |
27 |
use t::lib::Mocks; |
| 28 |
use t::lib::Mocks::Logger; |
28 |
use t::lib::Mocks::Logger; |
| 29 |
use t::lib::TestBuilder; |
29 |
use t::lib::TestBuilder; |
| 30 |
|
30 |
|
| 31 |
use Koha::EDI qw(process_quote process_invoice); |
31 |
use Koha::EDI qw(process_quote process_invoice create_edi_order); |
| 32 |
use Koha::Edifact::Transport; |
32 |
use Koha::Edifact::Transport; |
| 33 |
use Koha::Edifact::File::Errors; |
33 |
use Koha::Edifact::File::Errors; |
| 34 |
use Koha::DateUtils qw(dt_from_string); |
34 |
use Koha::DateUtils qw(dt_from_string); |
|
Lines 897-899
subtest 'process_invoice_without_tax_rate' => sub {
Link Here
|
| 897 |
|
897 |
|
| 898 |
$schema->storage->txn_rollback; |
898 |
$schema->storage->txn_rollback; |
| 899 |
}; |
899 |
}; |
| 900 |
- |
900 |
|
|
|
901 |
subtest 'create_edi_order_logging' => sub { |
| 902 |
plan tests => 8; |
| 903 |
|
| 904 |
$schema->storage->txn_begin; |
| 905 |
|
| 906 |
# Test 1: Error when called without basketno |
| 907 |
$logger->clear(); |
| 908 |
my $result = create_edi_order( { ean => '1234567890' } ); |
| 909 |
ok( !defined $result, 'create_edi_order returns undef when called without basketno' ); |
| 910 |
$logger->error_is( |
| 911 |
'create_edi_order called with no basketno or ean', |
| 912 |
'Error logged when create_edi_order called without basketno' |
| 913 |
); |
| 914 |
|
| 915 |
# Test 2: Error when called without ean |
| 916 |
$logger->clear(); |
| 917 |
$result = create_edi_order( { basketno => 123 } ); |
| 918 |
ok( !defined $result, 'create_edi_order returns undef when called without ean' ); |
| 919 |
$logger->error_is( |
| 920 |
'create_edi_order called with no basketno or ean', |
| 921 |
'Error logged when create_edi_order called without ean' |
| 922 |
); |
| 923 |
|
| 924 |
# Test 3: Warning when no orderlines for basket |
| 925 |
$logger->clear(); |
| 926 |
my $empty_basket = $builder->build_object( { class => 'Koha::Acquisition::Baskets' } ); |
| 927 |
my $ean = $builder->build( |
| 928 |
{ |
| 929 |
source => 'EdifactEan', |
| 930 |
value => { |
| 931 |
description => 'test ean', |
| 932 |
branchcode => undef, |
| 933 |
ean => '1234567890' |
| 934 |
} |
| 935 |
} |
| 936 |
); |
| 937 |
|
| 938 |
$result = create_edi_order( |
| 939 |
{ |
| 940 |
basketno => $empty_basket->basketno, |
| 941 |
ean => $ean->{ean} |
| 942 |
} |
| 943 |
); |
| 944 |
ok( !defined $result, 'create_edi_order returns undef when no orderlines for basket' ); |
| 945 |
$logger->warn_is( |
| 946 |
"No orderlines for basket " . $empty_basket->basketno, |
| 947 |
'Warning logged when no orderlines for basket' |
| 948 |
); |
| 949 |
|
| 950 |
# Test 4: Warning when no matching EAN found |
| 951 |
$logger->clear(); |
| 952 |
my $basket_with_orders = $builder->build_object( { class => 'Koha::Acquisition::Baskets' } ); |
| 953 |
my $order = $builder->build_object( |
| 954 |
{ |
| 955 |
class => 'Koha::Acquisition::Orders', |
| 956 |
value => { |
| 957 |
basketno => $basket_with_orders->basketno, |
| 958 |
orderstatus => 'new' |
| 959 |
} |
| 960 |
} |
| 961 |
); |
| 962 |
|
| 963 |
$result = create_edi_order( |
| 964 |
{ |
| 965 |
basketno => $basket_with_orders->basketno, |
| 966 |
ean => 'nonexistent_ean' |
| 967 |
} |
| 968 |
); |
| 969 |
ok( !defined $result, 'create_edi_order returns undef when no matching EAN found' ); |
| 970 |
$logger->warn_is( |
| 971 |
'No matching EAN found for nonexistent_ean', |
| 972 |
'Warning logged when no matching EAN found' |
| 973 |
); |
| 974 |
|
| 975 |
$schema->storage->txn_rollback; |
| 976 |
}; |