From 2531f820320970c4efacfe92fbdca058d0223d31 Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Thu, 31 Aug 2023 19:11:04 +0000 Subject: [PATCH] Bug 21272: Unit test https://bugs.koha-community.org/show_bug.cgi?id=12532 --- t/db_dependent/ImportBatch.t | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t index c9ef54391a..9e57c9c81e 100755 --- a/t/db_dependent/ImportBatch.t +++ b/t/db_dependent/ImportBatch.t @@ -216,7 +216,7 @@ my $import_batch = C4::ImportBatch::GetImportBatch( $id_import_batch3 ); is( $import_batch, undef, "Batch 3 has been deleted"); subtest "_batchCommitItems" => sub { - plan tests => 3; + plan tests => 6; my $exist_item = $builder->build_sample_item; my $import_item = $builder->build_object({ class => 'Koha::Import::Record::Items', value => { @@ -246,6 +246,34 @@ subtest "_batchCommitItems" => sub { $import_item->discard_changes(); is( $import_item->status, 'error', "Import item marked as error when duplicate barcode and action always_add"); is( $import_item->import_error, 'duplicate item barcode', 'Error correctly set when import item has duplicate barcode and action always_add' ); + + $import_item = $builder->build_object({ class => 'Koha::Import::Record::Items', value => { + marcxml => q{ + + + + 00000 a + + WBRC + WBRC + GEN + BCDETEST + BK + + + + }, + }}); + + ( $num_items_added, $num_items_replaced, $num_items_errored ) = + C4::ImportBatch::_batchCommitItems( $import_item->import_record_id, 32, 'always_add',64 ); + is( $num_items_errored, 1, "Item with wrong branchcode fails when action always_add" ); + $import_item->discard_changes(); + is( $import_item->status, 'error', "Import item marked as error when wrong branchcode detected and action always_add"); + is( $import_item->import_error, 'Branch code WBRC missing', 'Error correctly set when import item has a wrong branchcode detected and action always_add' ); }; subtest "RecordsFromMarcPlugin" => sub { -- 2.34.1