View | Details | Raw Unified | Return to bug 35398
Collapse All | Expand All

(-)a/t/db_dependent/Koha/EDI.t (+123 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2024 Martin Renvoize <martin.renvoize@ptfs-europe.com>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use FindBin qw( $Bin );
22
23
use Test::More tests => 1;
24
use Test::Warn;
25
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
29
use Koha::EDI qw(process_quote);
30
use Koha::Edifact::Transport;
31
32
my $schema  = Koha::Database->new->schema;
33
my $builder = t::lib::TestBuilder->new;
34
35
subtest 'process_quote' => sub {
36
    plan tests => 7;
37
38
    $schema->storage->txn_begin;
39
40
    # Add our test quote file to the database for testing against
41
    my $account = $builder->build(
42
        {
43
            source => 'VendorEdiAccount',
44
            value  => {
45
                description => 'test vendor', transport => 'FILE',
46
            }
47
        }
48
    );
49
    my $dirname  = ( $Bin =~ /^(.*\/t\/)/ ? $1 . 'edi_testfiles/' : q{} );
50
    my $filename = 'QUOTES_SMALL.CEQ';
51
    ok( -e $dirname . $filename, 'File QUOTES_SMALL.CEQ found' );
52
53
    my $trans = Koha::Edifact::Transport->new( $account->{id} );
54
    $trans->working_directory($dirname);
55
56
    my $mhash = $trans->message_hash();
57
    $mhash->{message_type} = 'QUOTE';
58
    $trans->ingest( $mhash, $filename );
59
60
    my $quote = $schema->resultset('EdifactMessage')->find( { filename => $filename } );
61
62
    # Test quote expects REF to be a valid and active fund code
63
    my $active_period = $builder->build(
64
        {
65
            source => 'Aqbudgetperiod',
66
            value  => { budget_period_active => 1 }
67
        }
68
    );
69
    my $fund = $builder->build(
70
        {
71
            source => 'Aqbudget',
72
            value  => {
73
                budget_code      => 'REF',
74
                budget_period_id => $active_period->{budget_period_id}
75
            }
76
        }
77
    );
78
79
    # The quote expects a ROT1 stock rotation roata to exist
80
    my $rota = $builder->build_object(
81
        {
82
            class => 'Koha::StockRotationRotas',
83
            value => { title => 'ROT1' }
84
        }
85
    );
86
    $builder->build({
87
        source => 'Stockrotationstage',
88
        value  => { rota_id => $rota->rota_id },
89
    });
90
91
    # Process the test quote file
92
    process_quote($quote);
93
94
    # Test for expected warnings for the passed quote file
95
    #
96
    # Test for quote status change
97
    $quote->get_from_storage;
98
    is( $quote->status, 'received', 'Quote status was set to received' );
99
100
    # Tests for generated basket for passed quote file
101
    my $baskets = Koha::Acquisition::Baskets->search( { booksellerid => $account->{vendor_id} } );
102
    is( $baskets->count, 1, "1 basket created for a single quote file" );
103
    my $basket = $baskets->next;
104
105
    my $orders = $basket->orders;
106
    is( $orders->count, 1, "1 order line attached to basket when only 1 order is in the edi message" );
107
    my $order = $orders->next;
108
109
    my $biblio = $order->biblio;
110
111
    my $items = $order->items;
112
    is( $items->count, 1, "1 item added when AcqCreateItem eq ordering and 1 item is in the EDI quote" );
113
    my $item = $items->next;
114
115
    # Test that item is added to rota appropriately
116
    my $on_rota = Koha::StockRotationItems->search({ itemnumber_id => $item->itemnumber });
117
    is($on_rota->count, 1, "Item added to stockrotation rota");
118
119
    my $rota_item = $on_rota->next;
120
    is($rota_item->stage->rota->id, $rota->id, "Item is on correct rota");
121
122
    $schema->storage->txn_rollback;
123
};
(-)a/t/edi_testfiles/QUOTES_SMALL.CEQ (-1 / +1 lines)
Line 0 Link Here
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'

Return to bug 35398