From e8bded7aa3e6787555260fcf4d9dffa41e4cfad4 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 18 Jul 2025 14:43:15 +0100 Subject: [PATCH] Bug 40387: Add tests for create_edi_order logger calls Tests for the logger calls introduced in the create_edi_order in the last commit. Signed-off-by: David Nind Signed-off-by: Jonathan Druart --- t/db_dependent/Koha/EDI.t | 81 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/EDI.t b/t/db_dependent/Koha/EDI.t index 810c60bc062..46a876cfb71 100755 --- a/t/db_dependent/Koha/EDI.t +++ b/t/db_dependent/Koha/EDI.t @@ -21,14 +21,14 @@ use Modern::Perl; use FindBin qw( $Bin ); use Test::NoWarnings; -use Test::More tests => 4; +use Test::More tests => 5; use Test::MockModule; use t::lib::Mocks; use t::lib::Mocks::Logger; use t::lib::TestBuilder; -use Koha::EDI qw(process_quote process_invoice); +use Koha::EDI qw(process_quote process_invoice create_edi_order); use Koha::Edifact::Transport; use Koha::Edifact::File::Errors; use Koha::DateUtils qw(dt_from_string); @@ -897,3 +897,80 @@ subtest 'process_invoice_without_tax_rate' => sub { $schema->storage->txn_rollback; }; + +subtest 'create_edi_order_logging' => sub { + plan tests => 8; + + $schema->storage->txn_begin; + + # Test 1: Error when called without basketno + $logger->clear(); + my $result = create_edi_order( { ean => '1234567890' } ); + ok( !defined $result, 'create_edi_order returns undef when called without basketno' ); + $logger->error_is( + 'create_edi_order called with no basketno or ean', + 'Error logged when create_edi_order called without basketno' + ); + + # Test 2: Error when called without ean + $logger->clear(); + $result = create_edi_order( { basketno => 123 } ); + ok( !defined $result, 'create_edi_order returns undef when called without ean' ); + $logger->error_is( + 'create_edi_order called with no basketno or ean', + 'Error logged when create_edi_order called without ean' + ); + + # Test 3: Warning when no orderlines for basket + $logger->clear(); + my $empty_basket = $builder->build_object( { class => 'Koha::Acquisition::Baskets' } ); + my $ean = $builder->build( + { + source => 'EdifactEan', + value => { + description => 'test ean', + branchcode => undef, + ean => '1234567890' + } + } + ); + + $result = create_edi_order( + { + basketno => $empty_basket->basketno, + ean => $ean->{ean} + } + ); + ok( !defined $result, 'create_edi_order returns undef when no orderlines for basket' ); + $logger->warn_is( + "No orderlines for basket " . $empty_basket->basketno, + 'Warning logged when no orderlines for basket' + ); + + # Test 4: Warning when no matching EAN found + $logger->clear(); + my $basket_with_orders = $builder->build_object( { class => 'Koha::Acquisition::Baskets' } ); + my $order = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + basketno => $basket_with_orders->basketno, + orderstatus => 'new' + } + } + ); + + $result = create_edi_order( + { + basketno => $basket_with_orders->basketno, + ean => 'nonexistent_ean' + } + ); + ok( !defined $result, 'create_edi_order returns undef when no matching EAN found' ); + $logger->warn_is( + 'No matching EAN found for nonexistent_ean', + 'Warning logged when no matching EAN found' + ); + + $schema->storage->txn_rollback; +}; -- 2.34.1