Bugzilla – Attachment 162542 Details for
Bug 35398
EDI: Fix support for LRP (Library Rotation Plan) for Koha with Stock Rotation enabled
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35398: Unit test
Bug-35398-Unit-test.patch (text/plain), 5.84 KB, created by
Martin Renvoize
on 2024-02-28 16:45:09 UTC
(
hide
)
Description:
Bug 35398: Unit test
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2024-02-28 16:45:09 UTC
Size:
5.84 KB
patch
obsolete
>From ff2f8bf335ec9f215e48ef39587deb73234303c4 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 28 Feb 2024 16:40:39 +0000 >Subject: [PATCH] Bug 35398: Unit test > >This patch adds the begginings of unit tests for Koha::EDI. Right now >we only test that a simple QUOTE message creates a basket, adds the item >to said basket and assigns that single item to a corresponding stock >rotation rota as defined by the LRP segment in the QUOTE message. > >It lays the foundations for much more rigorous tests to be written to >cover the whole of EDI.pm however. >--- > t/db_dependent/Koha/EDI.t | 123 +++++++++++++++++++++++++++++++ > t/edi_testfiles/QUOTES_SMALL.CEQ | 1 + > 2 files changed, 124 insertions(+) > create mode 100644 t/db_dependent/Koha/EDI.t > create mode 100644 t/edi_testfiles/QUOTES_SMALL.CEQ > >diff --git a/t/db_dependent/Koha/EDI.t b/t/db_dependent/Koha/EDI.t >new file mode 100644 >index 00000000000..a91e307cc72 >--- /dev/null >+++ b/t/db_dependent/Koha/EDI.t >@@ -0,0 +1,123 @@ >+#!/usr/bin/perl >+ >+# Copyright 2024 Martin Renvoize <martin.renvoize@ptfs-europe.com> >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use FindBin qw( $Bin ); >+ >+use Test::More tests => 1; >+use Test::Warn; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use Koha::EDI qw(process_quote); >+use Koha::Edifact::Transport; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'process_quote' => sub { >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ # Add our test quote file to the database for testing against >+ my $account = $builder->build( >+ { >+ source => 'VendorEdiAccount', >+ value => { >+ description => 'test vendor', transport => 'FILE', >+ } >+ } >+ ); >+ my $dirname = ( $Bin =~ /^(.*\/t\/)/ ? $1 . 'edi_testfiles/' : q{} ); >+ my $filename = 'QUOTES_SMALL.CEQ'; >+ ok( -e $dirname . $filename, 'File QUOTES_SMALL.CEQ found' ); >+ >+ my $trans = Koha::Edifact::Transport->new( $account->{id} ); >+ $trans->working_directory($dirname); >+ >+ my $mhash = $trans->message_hash(); >+ $mhash->{message_type} = 'QUOTE'; >+ $trans->ingest( $mhash, $filename ); >+ >+ my $quote = $schema->resultset('EdifactMessage')->find( { filename => $filename } ); >+ >+ # Test quote expects REF to be a valid and active fund code >+ my $active_period = $builder->build( >+ { >+ source => 'Aqbudgetperiod', >+ value => { budget_period_active => 1 } >+ } >+ ); >+ my $fund = $builder->build( >+ { >+ source => 'Aqbudget', >+ value => { >+ budget_code => 'REF', >+ budget_period_id => $active_period->{budget_period_id} >+ } >+ } >+ ); >+ >+ # The quote expects a ROT1 stock rotation roata to exist >+ my $rota = $builder->build_object( >+ { >+ class => 'Koha::StockRotationRotas', >+ value => { title => 'ROT1' } >+ } >+ ); >+ $builder->build({ >+ source => 'Stockrotationstage', >+ value => { rota_id => $rota->rota_id }, >+ }); >+ >+ # Process the test quote file >+ process_quote($quote); >+ >+ # Test for expected warnings for the passed quote file >+ # >+ # Test for quote status change >+ $quote->get_from_storage; >+ is( $quote->status, 'received', 'Quote status was set to received' ); >+ >+ # Tests for generated basket for passed quote file >+ my $baskets = Koha::Acquisition::Baskets->search( { booksellerid => $account->{vendor_id} } ); >+ is( $baskets->count, 1, "1 basket created for a single quote file" ); >+ my $basket = $baskets->next; >+ >+ my $orders = $basket->orders; >+ is( $orders->count, 1, "1 order line attached to basket when only 1 order is in the edi message" ); >+ my $order = $orders->next; >+ >+ my $biblio = $order->biblio; >+ >+ my $items = $order->items; >+ is( $items->count, 1, "1 item added when AcqCreateItem eq ordering and 1 item is in the EDI quote" ); >+ my $item = $items->next; >+ >+ # Test that item is added to rota appropriately >+ my $on_rota = Koha::StockRotationItems->search({ itemnumber_id => $item->itemnumber }); >+ is($on_rota->count, 1, "Item added to stockrotation rota"); >+ >+ my $rota_item = $on_rota->next; >+ is($rota_item->stage->rota->id, $rota->id, "Item is on correct rota"); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/edi_testfiles/QUOTES_SMALL.CEQ b/t/edi_testfiles/QUOTES_SMALL.CEQ >new file mode 100644 >index 00000000000..26126a27a40 >--- /dev/null >+++ b/t/edi_testfiles/QUOTES_SMALL.CEQ >@@ -0,0 +1 @@ >+UNA:+.? 'UNB+UNOC:3+5013546027173+5013546098818+240123:0945+1044416+ASKEDI:+QUOTES++++'UNH+1044416001+QUOTES:D:96A:UN:EAN002'BGM+31C::28+WO0800131+9'DTM+137:20240123:102'RFF+ON:orders 23/1'CUX+2:GBP:12'NAD+BY+5013546098818::9'NAD+SU+5013546027173::9'LIN+1++9781529923766:EN'PIA+5+152992376X:IB'IMD+L+010+:::Thompson'IMD+L+011+:::Louise'IMD+L+050+:::Lucky'IMD+L+060+:::learning to live again'IMD+L+120+:::Ebury Spotlight'IMD+L+170+:::2024'IMD+L+180+:::304'IMD+L+220+:::Hbk'IMD+L+230+:::791.45'IMD+L+250+:::AN'QTY+1:1'GIR+001+BOOK:LST+ANF:LSQ+CPL:LLO+REF:LFN+791.45:LCL'GIR+001+22.00:LCV'GIR+001+ROT1:LRP'PRI+AAE:22.00'RFF+QLI:WO0800131000001'UNS+S'CNT+2:1'UNT+27+1044416001'UNZ+1+1044416' >-- >2.44.0
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 35398
:
159240
|
160350
|
160352
|
160406
|
160407
|
162541
| 162542 |
162543
|
162544