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

(-)a/t/Edifact.t (-2 / +60 lines)
Lines 4-10 use warnings; Link Here
4
use FindBin qw( $Bin );
4
use FindBin qw( $Bin );
5
5
6
use Test::NoWarnings;
6
use Test::NoWarnings;
7
use Test::More tests => 42;
7
use Test::More tests => 64;
8
use JSON qw( decode_json );
8
use Koha::EDI;
9
use Koha::EDI;
9
10
10
BEGIN { use_ok('Koha::Edifact') }
11
BEGIN { use_ok('Koha::Edifact') }
Lines 139-141 is( $dp, 9.0, 'Discount calculated with discount = 0' ); Link Here
139
140
140
$dp = Koha::EDI::_discounted_price( 0.0, 9, 8.0 );
141
$dp = Koha::EDI::_discounted_price( 0.0, 9, 8.0 );
141
is( $dp, 8.0, 'Discount overridden by incoming calculated value' );
142
is( $dp, 8.0, 'Discount overridden by incoming calculated value' );
142
- 
143
144
# Test JSON output functionality
145
my $json_output = $quote->to_json();
146
ok( $json_output, 'JSON output generated' );
147
148
my $parsed_json = decode_json($json_output);
149
ok( $parsed_json, 'JSON output is valid JSON' );
150
151
# Test structure
152
ok( exists $parsed_json->{header},   'JSON has header field' );
153
ok( exists $parsed_json->{messages}, 'JSON has messages field' );
154
ok( exists $parsed_json->{trailer},  'JSON has trailer field' );
155
156
# Test header content (should be UNB segment)
157
like( $parsed_json->{header}, qr/^UNB\+/, 'Header starts with UNB' );
158
159
# Test messages array
160
is( ref $parsed_json->{messages},         'ARRAY', 'Messages is an array' );
161
is( scalar @{ $parsed_json->{messages} }, 1,       'Correct number of messages' );
162
163
# Test first message structure
164
my $first_msg = $parsed_json->{messages}->[0];
165
ok( exists $first_msg->{header},   'Message has header' );
166
ok( exists $first_msg->{segments}, 'Message has segments' );
167
ok( exists $first_msg->{trailer},  'Message has trailer' );
168
169
# Test message header/trailer format
170
like( $first_msg->{header},  qr/^UNH\+/, 'Message header starts with UNH' );
171
like( $first_msg->{trailer}, qr/^UNT\+/, 'Message trailer starts with UNT' );
172
173
# Test segments array
174
is( ref $first_msg->{segments}, 'ARRAY', 'Segments is an array' );
175
ok( scalar @{ $first_msg->{segments} } > 0, 'Message has segments' );
176
177
# Find a LIN segment to test line_id functionality
178
my $lin_segment;
179
my $lin_related_segment;
180
for my $seg ( @{ $first_msg->{segments} } ) {
181
    if ( $seg->{tag} eq 'LIN' ) {
182
        $lin_segment = $seg;
183
    } elsif ( $lin_segment && $seg->{tag} =~ /^(QTY|PRI|PIA)$/ && $seg->{line_id} ) {
184
        $lin_related_segment = $seg;
185
        last;
186
    }
187
}
188
189
ok( $lin_segment, 'Found LIN segment in JSON' );
190
if ($lin_segment) {
191
    ok( exists $lin_segment->{line_id},  'LIN segment has line_id' );
192
    ok( exists $lin_segment->{raw},      'LIN segment has raw data' );
193
    ok( exists $lin_segment->{elements}, 'LIN segment has elements array' );
194
    like( $lin_segment->{raw}, qr/^LIN\+/, 'LIN raw data starts correctly' );
195
}
196
197
ok( $lin_related_segment, 'Found line-related segment with line_id' );
198
if ( $lin_related_segment && $lin_segment ) {
199
    is( $lin_related_segment->{line_id}, $lin_segment->{line_id}, 'Line-related segment has matching line_id' );
200
}

Return to bug 40383